[Bug #732] NullPointerException in allocation of limiting resource

FEA: ItEr64S03BugFixing
This commit is contained in:
Diego Pino Garcia 2010-12-09 14:14:21 +01:00
parent 837a12437c
commit 41517ca7e0
2 changed files with 21 additions and 2 deletions

View file

@ -49,6 +49,12 @@ public class DateAndHour implements Comparable<DateAndHour> {
this.hour = hour;
}
public DateAndHour(DateAndHour dateAndHour) {
Validate.notNull(dateAndHour.getDate());
this.date = dateAndHour.getDate();
this.hour = dateAndHour.getHour();
}
public LocalDate getDate() {
return date;
}
@ -147,4 +153,8 @@ public class DateAndHour implements Comparable<DateAndHour> {
};
}
public void plusYears(int years) {
date = date.plusYears(years);
}
}

View file

@ -150,13 +150,22 @@ public class Gap implements Comparable<Gap> {
public List<Integer> getHoursInGapUntilAllocatingAndGoingToTheEnd(
BaseCalendar calendar,
DateAndHour realStart, DateAndHour allocationEnd, int total) {
Validate.isTrue(getEndTime() == null || allocationEnd.compareTo(getEndTime()) <= 0);
Validate.isTrue(endTime == null || allocationEnd.compareTo(endTime) <= 0);
Validate.isTrue(startTime == null
|| realStart.compareTo(startTime) >= 0);
Validate.isTrue(total >= 0);
List<Integer> result = new ArrayList<Integer>();
// If endTime is null (last tasks) assume the end is in 10 years from now
DateAndHour endDate = getEndTime();
if (endDate == null) {
endDate = new DateAndHour(realStart);
endDate.plusYears(10);
}
Iterator<PartialDay> daysUntilEnd = realStart.toIntraDayDate()
.daysUntil(getEndTime().toIntraDayDate()).iterator();
.daysUntil(endDate.toIntraDayDate()).iterator();
while (daysUntilEnd.hasNext()) {
PartialDay each = daysUntilEnd.next();
int hoursAtDay = calendar.getCapacityOn(each).roundToHours();