Skip to content

Commit

Permalink
Merge pull request #75 from deadlocker8/v1_1_0
Browse files Browse the repository at this point in the history
merge v1_1_0 into master
  • Loading branch information
deadlocker8 authored Apr 12, 2017
2 parents 65dbe53 + cfc7c18 commit c3df360
Show file tree
Hide file tree
Showing 18 changed files with 747 additions and 45 deletions.
Binary file modified build/BudgetMaster.exe
Binary file not shown.
Binary file modified build/BudgetMasterClient.jar
Binary file not shown.
Binary file modified build/BudgetMasterServer.jar
Binary file not shown.
174 changes: 174 additions & 0 deletions src/de/deadlocker8/budgetmaster/logic/FilterSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package de.deadlocker8.budgetmaster.logic;

import java.util.ArrayList;

public class FilterSettings
{
private boolean isIncomeAllowed;
private boolean isPaymentAllowed;
private boolean isNoRepeatingAllowed;
private boolean isMonthlyRepeatingAllowed;
private boolean isRepeatingEveryXDaysAllowed;
private ArrayList<Integer> allowedCategoryIDs;
private String name;

public FilterSettings(boolean isIncomeAllowed, boolean isPaymentAllowed, boolean isNoRepeatingAllowed, boolean isMonthlyRepeatingAllowed, boolean isRepeatingEveryXDaysAllowed, ArrayList<Integer> allowedCategoryIDs, String name)
{
this.isIncomeAllowed = isIncomeAllowed;
this.isPaymentAllowed = isPaymentAllowed;
this.isNoRepeatingAllowed = isNoRepeatingAllowed;
this.isMonthlyRepeatingAllowed = isMonthlyRepeatingAllowed;
this.isRepeatingEveryXDaysAllowed = isRepeatingEveryXDaysAllowed;
this.allowedCategoryIDs = allowedCategoryIDs;
this.name = name;
}

public FilterSettings()
{
this.isIncomeAllowed = true;
this.isPaymentAllowed = true;
this.isNoRepeatingAllowed = true;
this.isMonthlyRepeatingAllowed = true;
this.isRepeatingEveryXDaysAllowed = true;
this.allowedCategoryIDs = null;
this.name = null;
}

public boolean isIncomeAllowed()
{
return isIncomeAllowed;
}

public void setIncomeAllowed(boolean isIncomeAllowed)
{
this.isIncomeAllowed = isIncomeAllowed;
}

public boolean isPaymentAllowed()
{
return isPaymentAllowed;
}

public void setPaymentAllowed(boolean isPaymentAllowed)
{
this.isPaymentAllowed = isPaymentAllowed;
}

public boolean isNoRepeatingAllowed()
{
return isNoRepeatingAllowed;
}

public void setNoRepeatingAllowed(boolean isNoRepeatingAllowed)
{
this.isNoRepeatingAllowed = isNoRepeatingAllowed;
}

public boolean isMonthlyRepeatingAllowed()
{
return isMonthlyRepeatingAllowed;
}

public void setMonthlyRepeatingAllowed(boolean isMonthlyRepeatingAllowed)
{
this.isMonthlyRepeatingAllowed = isMonthlyRepeatingAllowed;
}

public boolean isRepeatingEveryXDaysAllowed()
{
return isRepeatingEveryXDaysAllowed;
}

public void setRepeatingEveryXDaysAllowed(boolean isRepeatingEveryXDaysAllowed)
{
this.isRepeatingEveryXDaysAllowed = isRepeatingEveryXDaysAllowed;
}

public ArrayList<Integer> getAllowedCategoryIDs()
{
return allowedCategoryIDs;
}

public void setAllowedCategoryIDs(ArrayList<Integer> allowedCategoryIDs)
{
this.allowedCategoryIDs = allowedCategoryIDs;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String toString()
{
return "FilterSettings [isIncomeAllowed=" + isIncomeAllowed + ", isPaymentAllowed=" + isPaymentAllowed + ", isNoRepeatingAllowed=" + isNoRepeatingAllowed + ", isMonthlyRepeatingAllowed=" + isMonthlyRepeatingAllowed + ", isRepeatingEveryXDaysAllowed=" + isRepeatingEveryXDaysAllowed
+ ", allowedCategoryIDs=" + allowedCategoryIDs + ", name=" + name + "]";
}

public boolean equals(Object other)
{
if(other == null) return false;
if(other == this) return true;
if(!(other instanceof FilterSettings)) return false;
FilterSettings otherSettings = (FilterSettings)other;
if(isIncomeAllowed == otherSettings.isIncomeAllowed() &&
isPaymentAllowed == otherSettings.isPaymentAllowed &&
isNoRepeatingAllowed == otherSettings.isNoRepeatingAllowed &&
isMonthlyRepeatingAllowed == otherSettings.isMonthlyRepeatingAllowed &&
isRepeatingEveryXDaysAllowed == otherSettings.isRepeatingEveryXDaysAllowed)
{
if(name == null)
{
if(otherSettings.getName() != null)
{
return false;
}
}
else
{
if(otherSettings.getName() == null)
{
return false;
}
else
{
if(!name.equals(otherSettings.getName())) return false;
}
}


if(allowedCategoryIDs == null)
{
if(otherSettings.getAllowedCategoryIDs() != null)
{
return false;
}
else
{
return true;
}
}
else
{
if(otherSettings.getAllowedCategoryIDs() == null)
{
return false;
}
else
{
if(allowedCategoryIDs.equals(otherSettings.getAllowedCategoryIDs()))
{
return true;
}
}
}
}

return false;
}
}
2 changes: 1 addition & 1 deletion src/de/deadlocker8/budgetmaster/logic/NormalPayment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public NormalPayment(int ID, int amount, String date, int categoryID, String nam
@Override
public String toString()
{
return "Payment [ID=" + super.getID() + ", amount=" + super.getAmount() + ", date=" + super.getDate() + ", categoryID=" + super.getCategoryID() + ", name=" + super.getName() + ", description=" + super.getDescription() + "]";
return "NormalPayment [ID=" + super.getID() + ", amount=" + super.getAmount() + ", date=" + super.getDate() + ", categoryID=" + super.getCategoryID() + ", name=" + super.getName() + ", description=" + super.getDescription() + "]";
}
}
152 changes: 152 additions & 0 deletions src/de/deadlocker8/budgetmaster/logic/PaymentHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package de.deadlocker8.budgetmaster.logic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Collectors;

public class PaymentHandler
{
private ArrayList<Payment> payments;

public PaymentHandler()
{
payments = new ArrayList<>();
}

public ArrayList<Payment> getPayments()
{
return payments;
}

public void setPayments(ArrayList<Payment> payments)
{
this.payments = payments;
}

public void sort()
{
Collections.sort(payments, new Comparator<Payment>() {
@Override
public int compare(Payment payment1, Payment payment2)
{
return payment2.getDate().compareTo(payment1.getDate());
}
});
}

private ArrayList<Payment> filterByRepeating(FilterSettings filterSettings, ArrayList<Payment> paymentsList)
{
if(filterSettings.isNoRepeatingAllowed() && filterSettings.isMonthlyRepeatingAllowed() && filterSettings.isRepeatingEveryXDaysAllowed())
{
return paymentsList;
}

ArrayList<Payment> filteredPayments = new ArrayList<>();
for(Payment currentPayment : paymentsList)
{
//NormalPayment or rest
if(currentPayment instanceof NormalPayment || currentPayment.getID() == -1)
{
if(filterSettings.isNoRepeatingAllowed())
{
filteredPayments.add(currentPayment);
}
}
//RepeatingPayment
else
{
RepeatingPaymentEntry repeatingPayment = (RepeatingPaymentEntry)currentPayment;
if((repeatingPayment.getRepeatInterval() != 0 && filterSettings.isRepeatingEveryXDaysAllowed()) ||
(repeatingPayment.getRepeatMonthDay() != 0 && filterSettings.isMonthlyRepeatingAllowed()))
{
filteredPayments.add(currentPayment);
}
}
}

return filteredPayments;
}

private ArrayList<Payment> filterByCategory(FilterSettings filterSettings, ArrayList<Payment> paymentsList)
{
if(filterSettings.getAllowedCategoryIDs() == null)
{
return paymentsList;
}

if(filterSettings.getAllowedCategoryIDs().size() == 0)
{
return new ArrayList<>();
}

ArrayList<Payment> filteredPayments = new ArrayList<>();
for(Payment currentPayment : paymentsList)
{
if(filterSettings.getAllowedCategoryIDs().contains(currentPayment.getCategoryID()))
{
filteredPayments.add(currentPayment);
}
}

return filteredPayments;
}

private ArrayList<Payment> filterByName(FilterSettings filterSettings, ArrayList<Payment> paymentsList)
{
if(filterSettings.getName() == null)
{
return paymentsList;
}

ArrayList<Payment> filteredPayments = new ArrayList<>();
for(Payment currentPayment : paymentsList)
{
if(currentPayment.getName().toLowerCase().contains(filterSettings.getName().toLowerCase()))
{
filteredPayments.add(currentPayment);
}
}

return filteredPayments;
}

private ArrayList<Payment> filterByType(FilterSettings filterSettings, ArrayList<Payment> paymentsList)
{
if(filterSettings.isIncomeAllowed() && filterSettings.isPaymentAllowed())
{
return paymentsList;
}

if(filterSettings.isIncomeAllowed())
{
return new ArrayList<Payment>(paymentsList.stream().
filter(p -> p.getAmount() > 0).
collect(Collectors.toList()));
}
else if(filterSettings.isPaymentAllowed())
{
return new ArrayList<Payment>(paymentsList.stream().
filter(p -> p.getAmount() < 0).
collect(Collectors.toList()));
}

return new ArrayList<>();
}

public void filter(FilterSettings filterSettings)
{
ArrayList<Payment> filteredPayments = filterByType(filterSettings, payments);
filteredPayments = filterByType(filterSettings, filteredPayments);
filteredPayments = filterByRepeating(filterSettings, filteredPayments);
filteredPayments = filterByCategory(filterSettings, filteredPayments);
filteredPayments = filterByName(filterSettings, filteredPayments);

payments = filteredPayments;
}

public String toString()
{
return "PaymentHandler [payments=" + payments + "]";
}
}
6 changes: 3 additions & 3 deletions src/de/deadlocker8/budgetmaster/main/_de.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
app.name=BudgetMaster
version.code=1
version.name=1.0.0
version.date=08.04.17
version.code=2
version.name=1.1.0
version.date=12.04.17
author=Robert Goldmann

folder=Deadlocker/BudgetMaster
Expand Down
2 changes: 1 addition & 1 deletion src/de/deadlocker8/budgetmaster/ui/CategoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void deleteCategory(int ID)
{
ServerConnection connection = new ServerConnection(controller.getSettings());
connection.deleteCategory(ID);
controller.refresh();
controller.refresh(controller.getFilterSettings());
}
catch(Exception e)
{
Expand Down
Loading

0 comments on commit c3df360

Please sign in to comment.