final LimitingResourceQueue queue,
final DateAndHour startAt,
final DateAndHour endsAfter) {
// Check if allocation is possible
InsertionRequirements requirements = queuesState.getRequirementsFor(
element, startAt);
AllocationSpec allocation = insertAtGap(requirements, queue);
if (!allocation.isValid()) {
return Collections.emptyList();
}
// Do allocation
applyAllocation(allocation, new IDayAssignmentBehaviour() {
@Override
public void allocateDayAssigments(IntraDayDate start,
IntraDayDate end) {
List<DayAssignment> assignments = LimitingResourceAllocator
.generateDayAssignments(
element.getResourceAllocation(),
queue.getResource(), startAt, endsAfter);
element.getResourceAllocation().allocateLimitingDayAssignments(
assignments, start, end);
}
});
assert allocation.isValid();
// Move other tasks to respect dependency constraints
List<LimitingResourceQueueElement> result = new ArrayList<LimitingResourceQueueElement>();
result.add(requirements.getElement());
List<LimitingResourceQueueElement> moved = shift(
queuesState.getPotentiallyAffectedByInsertion(element),
requirements.getElement(), allocation);
result.addAll(rescheduleAffectedElementsToSatisfyDependencies(allocation, moved));
return result;
}