From bd5fd662420d50adf4fd28c53294de63e01df805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 6 Oct 2009 23:24:18 +0200 Subject: [PATCH] ItEr29S06CUAsignacionGrupoRecursosAPlanificacionItEr28S06: Moving AllocationResult to top level --- .../planner/allocation/AllocationResult.java | 115 ++++++++++++++++++ .../ResourceAllocationsBeingEdited.java | 82 +------------ 2 files changed, 116 insertions(+), 81 deletions(-) create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java 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 new file mode 100644 index 000000000..958ae2f2f --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java @@ -0,0 +1,115 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.navalplanner.web.planner.allocation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang.Validate; +import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations; +import org.navalplanner.business.planner.entities.CalculatedValue; +import org.navalplanner.business.planner.entities.ResourceAllocation; +import org.navalplanner.business.planner.entities.Task; +import org.navalplanner.business.planner.entities.Task.ModifiedAllocation; +import org.navalplanner.business.planner.entities.allocationalgorithms.ResourceAllocationWithDesiredResourcesPerDay; + +/** + * @author Óscar González Fernández + * + */ +public class AllocationResult { + + private static Map, ResourceAllocation> translation( + Map> fromDetachedToAttached) { + Map, ResourceAllocation> result = new HashMap, ResourceAllocation>(); + for (Entry> entry : fromDetachedToAttached + .entrySet()) { + result + .put(entry.getKey().getResourceAllocation(), entry + .getValue()); + } + return result; + } + + private final AggregateOfResourceAllocations aggregate; + + private final Integer daysDuration; + + private final Map, ResourceAllocation> fromDetachedAllocationToAttached; + + private final CalculatedValue calculatedValue; + + AllocationResult( + CalculatedValue calculatedValue, + AggregateOfResourceAllocations aggregate, + Integer daysDuration, + Map> fromDetachedAllocationToAttached) { + Validate.notNull(daysDuration); + Validate.notNull(aggregate); + Validate.notNull(calculatedValue); + this.calculatedValue = calculatedValue; + this.aggregate = aggregate; + this.daysDuration = daysDuration; + this.fromDetachedAllocationToAttached = translation(fromDetachedAllocationToAttached); + } + + public AggregateOfResourceAllocations getAggregate() { + return aggregate; + } + + public Integer getDaysDuration() { + return daysDuration; + } + + public List> getNew() { + List> result = new ArrayList>(); + for (Entry, ResourceAllocation> entry : fromDetachedAllocationToAttached + .entrySet()) { + if (entry.getValue() == null) { + result.add(entry.getKey()); + } + } + return result; + } + + public List getModified() { + List result = new ArrayList(); + for (Entry, ResourceAllocation> entry : fromDetachedAllocationToAttached + .entrySet()) { + if (entry.getValue() != null) { + result.add(new ModifiedAllocation(entry.getValue(), entry + .getKey())); + } + } + return result; + } + + public CalculatedValue getCalculatedValue() { + return calculatedValue; + } + + public void applyTo(Task task) { + task.mergeAllocation(getCalculatedValue(), getDaysDuration(), getNew(), + getModified()); + } +} 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 65af56731..e041140da 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 @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; -import org.apache.commons.lang.Validate; import org.joda.time.Days; import org.joda.time.LocalDate; import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations; @@ -40,7 +39,6 @@ import org.navalplanner.business.planner.entities.GenericResourceAllocation; 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.ResourceAllocationWithDesiredResourcesPerDay; import org.navalplanner.business.resources.daos.IResourceDAO; import org.navalplanner.business.resources.entities.Resource; @@ -297,82 +295,4 @@ public class ResourceAllocationsBeingEdited { return daysDuration; } -} - -class AllocationResult { - - private static Map, ResourceAllocation> translation( - Map> fromDetachedToAttached) { - Map, ResourceAllocation> result = new HashMap, ResourceAllocation>(); - for (Entry> entry : fromDetachedToAttached - .entrySet()) { - result - .put(entry.getKey().getResourceAllocation(), entry - .getValue()); - } - return result; - } - - private final AggregateOfResourceAllocations aggregate; - - private final Integer daysDuration; - - private final Map, ResourceAllocation> fromDetachedAllocationToAttached; - - private final CalculatedValue calculatedValue; - - AllocationResult( - CalculatedValue calculatedValue, - AggregateOfResourceAllocations aggregate, - Integer daysDuration, - Map> fromDetachedAllocationToAttached) { - Validate.notNull(daysDuration); - Validate.notNull(aggregate); - Validate.notNull(calculatedValue); - this.calculatedValue = calculatedValue; - this.aggregate = aggregate; - this.daysDuration = daysDuration; - this.fromDetachedAllocationToAttached = translation(fromDetachedAllocationToAttached); - } - - public AggregateOfResourceAllocations getAggregate() { - return aggregate; - } - - public Integer getDaysDuration() { - return daysDuration; - } - - public List> getNew() { - List> result = new ArrayList>(); - for (Entry, ResourceAllocation> entry : fromDetachedAllocationToAttached - .entrySet()) { - if (entry.getValue() == null) { - result.add(entry.getKey()); - } - } - return result; - } - - public List getModified() { - List result = new ArrayList(); - for (Entry, ResourceAllocation> entry : fromDetachedAllocationToAttached - .entrySet()) { - if (entry.getValue() != null) { - result.add(new ModifiedAllocation(entry.getValue(), entry - .getKey())); - } - } - return result; - } - - public CalculatedValue getCalculatedValue() { - return calculatedValue; - } - - public void applyTo(Task task) { - task.mergeAllocation(getCalculatedValue(), - getDaysDuration(), - getNew(), getModified()); - } -} +} \ No newline at end of file