diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java index 98e7c57c5..5f5048ec5 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java @@ -20,6 +20,8 @@ package org.navalplanner.business.planner.entities; +import org.joda.time.LocalDate; + /** * This interface represents an object that can be do an allocation based on an * amount of {@link ResourcesPerDay} @@ -27,4 +29,6 @@ package org.navalplanner.business.planner.entities; */ public interface IAllocatable { public void allocate(ResourcesPerDay resourcesPerDay); + + public IAllocateHoursOnInterval onInterval(LocalDate start, LocalDate end); } \ No newline at end of file diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocateHoursOnInterval.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocateHoursOnInterval.java new file mode 100644 index 000000000..34d7c7631 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocateHoursOnInterval.java @@ -0,0 +1,24 @@ +/* + * 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.business.planner.entities; + +public interface IAllocateHoursOnInterval { + void allocateHours(int hours); +} \ No newline at end of file diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java index 6fe600654..c125057f9 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java @@ -296,7 +296,32 @@ public abstract class ResourceAllocation extends return result; } - void allocate(LocalDate startInclusive, LocalDate endExclusive, int hours) { + private class AllocateHoursOnInterval implements + IAllocateHoursOnInterval { + + private final LocalDate start; + private final LocalDate end; + + AllocateHoursOnInterval(LocalDate start, LocalDate end) { + Validate.isTrue(start.compareTo(end) <= 0, + "the end must be equal or posterior than start"); + this.start = start; + this.end = end; + } + + public void allocateHours(int hours) { + allocate(start, end, hours); + } + } + + @Override + public IAllocateHoursOnInterval onInterval(LocalDate start, + LocalDate end) { + return new AllocateHoursOnInterval(start, end); + } + + private void allocate(LocalDate startInclusive, LocalDate endExclusive, + int hours) { Validate.isTrue(hours >= 0); Validate.isTrue(startInclusive.compareTo(endExclusive) <= 0, "the end must be equal or posterior than start"); diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java index 427995880..e2f7f1a47 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java @@ -123,29 +123,9 @@ public class SpecificResourceAllocation extends } } - public interface IAllocateHoursOnInterval { - void allocateHours(int hours); - } - - private class AllocateHoursOnInterval implements IAllocateHoursOnInterval { - - private final LocalDate start; - private final LocalDate end; - - AllocateHoursOnInterval(LocalDate start, LocalDate end) { - this.start = start; - this.end = end; - } - - public void allocateHours(int hours) { - new SpecificAssignmentsAllocation().allocate(start, end, hours); - } - } - + @Override public IAllocateHoursOnInterval onInterval(LocalDate start, LocalDate end) { - Validate.isTrue(start.compareTo(end) <= 0, - "the end must be equal or posterior than start"); - return new AllocateHoursOnInterval(start, end); + return new SpecificAssignmentsAllocation().onInterval(start, end); } @Override