ItEr37S08CUCreacionUnidadesPlanificacionItEr36S11: Adding new factory method to create an AllocationResult from a list of AllocationRow

This commit is contained in:
Óscar González Fernández 2009-12-01 23:36:09 +01:00
parent 486cc1ed54
commit e93f59c1bf
2 changed files with 44 additions and 0 deletions

View file

@ -92,6 +92,25 @@ public class AllocationResult {
calculateNew(translation), calculateModified(translation));
}
public static AllocationResult create(Task task,
CalculatedValue calculatedValue, List<AllocationRow> rows) {
List<ResourceAllocation<?>> newAllocations = AllocationRow
.getNewFrom(rows);
List<ModifiedAllocation> modified = AllocationRow.getModifiedFrom(rows);
return new AllocationResult(task, calculatedValue, createAggregate(
newAllocations, modified),
newAllocations, modified);
}
private static AggregateOfResourceAllocations createAggregate(
List<ResourceAllocation<?>> newAllocations,
List<ModifiedAllocation> modified) {
List<ResourceAllocation<?>> all = new ArrayList<ResourceAllocation<?>>();
all.addAll(newAllocations);
all.addAll(ModifiedAllocation.modified(modified));
return new AggregateOfResourceAllocations(all);
}
public static AllocationResult createCurrent(Task task) {
Set<ResourceAllocation<?>> resourceAllocations = task
.getResourceAllocations();

View file

@ -30,6 +30,7 @@ import org.navalplanner.business.planner.entities.CalculatedValue;
import org.navalplanner.business.planner.entities.ResourceAllocation;
import org.navalplanner.business.planner.entities.ResourcesPerDay;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.Task.ModifiedAllocation;
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourcesPerDayModification;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.web.common.Util;
@ -46,6 +47,30 @@ import org.zkoss.zul.SimpleConstraint;
*/
public abstract class AllocationRow {
public static List<ModifiedAllocation> getModifiedFrom(
Collection<? extends AllocationRow> rows) {
List<ModifiedAllocation> result = new ArrayList<ModifiedAllocation>();
for (AllocationRow each : rows) {
Validate.notNull(each.last);
if (each.origin != null) {
result.add(new ModifiedAllocation(each.origin, each.last));
}
}
return result;
}
public static List<ResourceAllocation<?>> getNewFrom(
List<AllocationRow> rows) {
List<ResourceAllocation<?>> result = new ArrayList<ResourceAllocation<?>>();
for (AllocationRow each : rows) {
Validate.notNull(each.last);
if (each.origin == null) {
result.add(each.last);
}
}
return result;
}
public static List<GenericAllocationRow> getGeneric(
Collection<? extends AllocationRow> all) {
List<GenericAllocationRow> result = new ArrayList<GenericAllocationRow>();