private static CapacityResult thereIsCapacityOn(ICalendar calendar,
EffortDuration effortToAllocate,
ResourcesPerDay resourcesPerDay, List<Interval> validPeriods) {
EffortDuration sum = zero();
for (Interval each : validPeriods) {
FixedPoint start = (FixedPoint) each.getStart();
FixedPoint end = (FixedPoint) each.getEnd();
EffortDuration pending = effortToAllocate.minus(sum);
sum = sum.plus(sumDurationUntil(calendar, pending,
resourcesPerDay, start.getDate(), end.getDate()));
if (sum.compareTo(effortToAllocate) >= 0) {
return new CapacityAvailable();
}
}
return new ValidPeriodsDontHaveCapacity(validPeriods, sum,