From 190f8bc6cbc6b686385397d14bb4ab0ef24e852a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 1 Dec 2009 22:49:09 +0100 Subject: [PATCH] ItEr37S08CUCreacionUnidadesPlanificacionItEr36S11: Using factory method instead of constructor to create an AllocationResult --- .../planner/allocation/AllocationResult.java | 26 +++++++++++++------ .../ResourceAllocationsBeingEdited.java | 9 +++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java index 58a447e86..ff9e4d209 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java @@ -36,7 +36,7 @@ import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; 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.planner.entities.allocationalgorithms.AllocationModification; /** * @author Óscar González Fernández @@ -45,9 +45,9 @@ import org.navalplanner.business.planner.entities.allocationalgorithms.Resources public class AllocationResult { private static Map, ResourceAllocation> translation( - Map> fromDetachedToAttached) { + Map> fromDetachedToAttached) { Map, ResourceAllocation> result = new HashMap, ResourceAllocation>(); - for (Entry> entry : fromDetachedToAttached + for (Entry> entry : fromDetachedToAttached .entrySet()) { result .put(entry.getKey().getBeingModified(), entry @@ -81,6 +81,16 @@ public class AllocationResult { return result; } + public static AllocationResult create( + Task task, + CalculatedValue calculatedValue, + AggregateOfResourceAllocations aggregate, + Map> fromDetachedAllocationToAttached) { + Map, ResourceAllocation> translation = translation(fromDetachedAllocationToAttached); + return new AllocationResult(task, calculatedValue, aggregate, + calculateNew(translation), calculateModified(translation)); + } + private final AggregateOfResourceAllocations aggregate; private final Integer daysDuration; @@ -93,11 +103,12 @@ public class AllocationResult { private final List modified; - AllocationResult( + private AllocationResult( Task task, CalculatedValue calculatedValue, AggregateOfResourceAllocations aggregate, - Map> fromDetachedAllocationToAttached) { + List> newAllocations, + List modified) { Validate.notNull(aggregate); Validate.notNull(calculatedValue); Validate.notNull(task); @@ -106,9 +117,8 @@ public class AllocationResult { this.aggregate = aggregate; this.daysDuration = aggregate.isEmpty() ? task.getDaysDuration() : aggregate.getDaysDuration(); - Map, ResourceAllocation> fromDetachedToAttached = translation(fromDetachedAllocationToAttached); - this.newAllocations = calculateNew(fromDetachedToAttached); - this.modified = calculateModified(fromDetachedToAttached); + this.newAllocations = newAllocations; + this.modified = modified; } public AggregateOfResourceAllocations getAggregate() { diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java index 382fc0dfb..feb5d3fc6 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationsBeingEdited.java @@ -50,8 +50,7 @@ public class ResourceAllocationsBeingEdited { AggregateOfResourceAllocations aggregate = new AggregateOfResourceAllocations( AllocationModification.getBeingModified(forModification .keySet())); - return new AllocationResult(task, task.getCalculatedValue(), aggregate, - forModification); + return AllocationResult.create(task, task.getCalculatedValue(), aggregate, forModification); } private static Map> forModification( @@ -205,10 +204,8 @@ public class ResourceAllocationsBeingEdited { throw new RuntimeException("cant handle: " + calculatedValue); } } - AllocationResult result = new AllocationResult(task, calculatedValue, - new AggregateOfResourceAllocations(AllocationModification - .getBeingModified(allocations)), - fromDetachedToAttached); + AllocationResult result = AllocationResult.create(task, calculatedValue, new AggregateOfResourceAllocations(AllocationModification + .getBeingModified(allocations)), fromDetachedToAttached); daysDuration = result.getDaysDuration(); return result; }