List<Allocation> allocationList = new ArrayList<Allocation>(jobList.size());
Map<Job, Allocation> jobToAllocationMap = new HashMap<Job, Allocation>(jobList.size());
Map<Project, Allocation> projectToSourceAllocationMap = new HashMap<Project, Allocation>(projectListSize);
Map<Project, Allocation> projectToSinkAllocationMap = new HashMap<Project, Allocation>(projectListSize);
for (Job job : jobList) {
Allocation allocation = new Allocation();
allocation.setId(job.getId());
allocation.setJob(job);
allocation.setPredecessorAllocationList(new ArrayList<Allocation>(job.getSuccessorJobList().size()));
allocation.setSuccessorAllocationList(new ArrayList<Allocation>(job.getSuccessorJobList().size()));
// Uninitialized allocations take no time, but don't break the predecessorsDoneDate cascade to sink.
allocation.setPredecessorsDoneDate(job.getProject().getReleaseDate());
if (job.getJobType() == JobType.SOURCE) {
allocation.setDelay(0);
if (job.getExecutionModeList().size() != 1) {
throw new IllegalArgumentException("The job (" + job
+ ")'s executionModeList (" + job.getExecutionModeList()
+ ") is expected to be a singleton.");
}
allocation.setExecutionMode(job.getExecutionModeList().get(0));
projectToSourceAllocationMap.put(job.getProject(), allocation);
} else if (job.getJobType() == JobType.SINK) {
allocation.setDelay(0);
if (job.getExecutionModeList().size() != 1) {
throw new IllegalArgumentException("The job (" + job
+ ")'s executionModeList (" + job.getExecutionModeList()
+ ") is expected to be a singleton.");
}
allocation.setExecutionMode(job.getExecutionModeList().get(0));
projectToSinkAllocationMap.put(job.getProject(), allocation);
}
allocationList.add(allocation);
jobToAllocationMap.put(job, allocation);
}
for (Allocation allocation : allocationList) {
Job job = allocation.getJob();
allocation.setSourceAllocation(projectToSourceAllocationMap.get(job.getProject()));
allocation.setSinkAllocation(projectToSinkAllocationMap.get(job.getProject()));
for (Job successorJob : job.getSuccessorJobList()) {
Allocation successorAllocation = jobToAllocationMap.get(successorJob);
allocation.getSuccessorAllocationList().add(successorAllocation);
successorAllocation.getPredecessorAllocationList().add(allocation);
}
}
for (Allocation sourceAllocation : projectToSourceAllocationMap.values()) {
for (Allocation allocation : sourceAllocation.getSuccessorAllocationList()) {
allocation.setPredecessorsDoneDate(sourceAllocation.getEndDate());