return untilAllocating(Direction.FORWARD, effort, receiver);
}
public IntraDayDate untilAllocating(Direction direction,
EffortDuration toAllocate, final INotFulfilledReceiver receiver) {
UntilFillingHoursAllocator allocator = new UntilFillingHoursAllocator(
direction,
task, allocations) {
@Override
protected <T extends DayAssignment> void setNewDataForAllocation(
ResourceAllocation<T> allocation,
IntraDayDate resultDate,
ResourcesPerDay resourcesPerDay, List<T> dayAssignments) {
Task task = AllocationsSpecified.this.task;
allocation.setIntendedResourcesPerDay(resourcesPerDay);
if (isForwardScheduling()) {
allocation.resetAllAllocationAssignmentsTo(
dayAssignments,
task.getIntraDayStartDate(), resultDate);
} else {
allocation.resetAllAllocationAssignmentsTo(
dayAssignments,
resultDate, task.getIntraDayEndDate());
}
allocation.updateResourcesPerDay();
}
@Override
protected CapacityResult thereAreAvailableHoursFrom(
IntraDayDate dateFromWhichToAllocate,
ResourcesPerDayModification resourcesPerDayModification,
EffortDuration effortToAllocate) {
ICalendar calendar = getCalendar(resourcesPerDayModification);
ResourcesPerDay resourcesPerDay = resourcesPerDayModification
.getGoal();
AvailabilityTimeLine availability = resourcesPerDayModification
.getAvailability();
getDirection().limitAvailabilityOn(availability,
dateFromWhichToAllocate);
return ThereAreHoursOnWorkHoursCalculator
.thereIsAvailableCapacityFor(calendar,
availability, resourcesPerDay,
effortToAllocate);
}
private CombinedWorkHours getCalendar(
ResourcesPerDayModification resourcesPerDayModification) {
return CombinedWorkHours.minOf(resourcesPerDayModification
.getBeingModified().getTaskCalendar(),
resourcesPerDayModification.getResourcesCalendar());
}
@Override
protected void markUnsatisfied(
ResourcesPerDayModification allocationAttempt,
CapacityResult capacityResult) {
allocationAttempt.getBeingModified().markAsUnsatisfied();
receiver.cantFulfill(allocationAttempt, capacityResult);
}
};
IntraDayDate result = allocator.untilAllocating(toAllocate);
if (result == null) {
// allocation could not be done
return direction == Direction.FORWARD ? task
.getIntraDayEndDate() : task.getIntraDayStartDate();
}