I am busy adding functionality that adds start and end dates to service charges. Service charges currently contain a minimum withdrawal amount, the charge and the start and end dates.
Requirement is that you can have multiple different minimum withdrawal amounts all with their own period (start and end dates). Items with the same minimum withdrawal amount arent allowed to have their periods overlap, though gaps are allowed. Final requirement is that you can set the amount of distinct minimum withdrawal amounts at any given time, i.e. if the amount is set to 5, you can have 5 distinct service charges at any given point in time.
Now my problem is the last part, making sure that there are only ever a certain amount of periods active for any given point in time.
And to make things even more difficult.. I can't use the Calendar class because I am doing this in GWT which only supports the Date class..
Here is what I have so far..
private boolean checkDates() {
int maxSlates = orgs.getMaxSlates();
for (WfScServiceCharge wfsc : serviceCharges) {
Date startDate = wfsc.getScEffectiveStart();
Date endDate = wfsc.getScEffectiveEnd();
int slates = 0;
for (WfScServiceCharge wfsc2 : serviceCharges) {
// dont check slate against itself
if (!wfsc.equals(wfsc2)) {
// check slates with same min withdraw amounts
if (wfsc.getScMinWithdrawAmount() == wfsc2.getScMinWithdrawAmount()) {
// check that periods dont overlap
if ((startDate.after(wfsc2.getScEffectiveStart()) && startDate
.before(wfsc2.getScEffectiveEnd()))
|| (endDate.after(wfsc2.getScEffectiveStart()) && endDate
.before(wfsc2.getScEffectiveEnd()))) {
Window
.alert("Period clashes with an already configured"
+ " period for a service charge with the same minimum withdrawal amount.");
return false;
}
}
// check number of distinct slates for any given period
// THIS IS WHERE I NEED HELP!
if (wfsc2.getScEffectiveStart().compareTo(startDate) >= 0
|| wfsc2.getScEffectiveEnd().compareTo(endDate) <= 0) {
slates++;
}
if (slates > maxSlates) {
Window.alert("Maximum amount of slates reached for time period. "
+ "Please change the period that this slate needs to fall in.");
return false;
}
}
}
}
return true;
}