-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from deadlocker8/v1_1_0
merge v1_1_0 into master
- Loading branch information
Showing
18 changed files
with
747 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
174 changes: 174 additions & 0 deletions
174
src/de/deadlocker8/budgetmaster/logic/FilterSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/de/deadlocker8/budgetmaster/logic/PaymentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.