Pull up method and do it more generic

FEA: ItEr70S08CriteriaLoadRefinementItEr69S10
This commit is contained in:
Óscar González Fernández 2011-02-07 20:01:44 +01:00
parent c74b23252b
commit 57c10052c1
2 changed files with 15 additions and 21 deletions

View file

@ -85,27 +85,6 @@ public class GenericResourceAllocation extends
return result;
}
public static Map<Resource, List<GenericResourceAllocation>> byResource(
Collection<GenericResourceAllocation> allocations) {
Map<Resource, List<GenericResourceAllocation>> result = new HashMap<Resource, List<GenericResourceAllocation>>();
for (GenericResourceAllocation resourceAllocation : allocations) {
for (Resource resource : resourceAllocation
.getAssociatedResources()) {
initializeIfNeeded_(result, resource);
result.get(resource).add(resourceAllocation);
}
}
return result;
}
private static void initializeIfNeeded_(
Map<Resource, List<GenericResourceAllocation>> result,
Resource resource) {
if (!result.containsKey(resource)) {
result.put(resource, new ArrayList<GenericResourceAllocation>());
}
}
@OnCopy(Strategy.SHARE_COLLECTION_ELEMENTS)
private Set<Criterion> criterions = new HashSet<Criterion>();

View file

@ -103,6 +103,21 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
return result;
}
public static <R extends ResourceAllocation<?>> Map<Resource, List<R>> byResource(
Collection<? extends R> allocations) {
Map<Resource, List<R>> result = new HashMap<Resource, List<R>>();
for (R resourceAllocation : allocations) {
for (Resource resource : resourceAllocation
.getAssociatedResources()) {
if (!result.containsKey(resource)) {
result.put(resource, new ArrayList<R>());
}
result.get(resource).add(resourceAllocation);
}
}
return result;
}
public static <R extends ResourceAllocation<?>> List<R> sortedByStartDate(
Collection<R> allocations) {
List<R> result = new ArrayList<R>(allocations);