From 9c6d2da9330cbcca1f0bc59d675cb133118703ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Wed, 13 Apr 2011 20:05:02 +0200 Subject: [PATCH] Refactor Create polymorphic method in AllocationInterval. This allows adding new argument options easier. FEA: ItEr74S04BugFixing --- .../planner/entities/ResourceAllocation.java | 90 +++++++++---------- 1 file changed, 40 insertions(+), 50 deletions(-) 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 e31a589a8..23ad73936 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 @@ -753,22 +753,20 @@ public abstract class ResourceAllocation extends } } - private class AllocateHoursOnInterval implements - IAllocateHoursOnInterval { + @Override + public IAllocateHoursOnInterval onIntervalWithinTask( + final LocalDate start, final LocalDate end) { + checkStartBeforeOrEqualEnd(start, end); + return new OnSubIntervalAllocator( + new AllocationIntervalInsideTask(start, end)); + } - private final LocalDate start; - private final LocalDate end; - - AllocateHoursOnInterval(LocalDate start, LocalDate end) { - checkStartBeforeOrEqualEnd(start, end); - this.start = start; - this.end = end; - } - - - public void allocateHours(int hours) { - allocateSubintervalWithinTaskBounds(start, end, hours(hours)); - } + @Override + public IAllocateHoursOnInterval onInterval( + final LocalDate startInclusive, final LocalDate endExclusive) { + checkStartBeforeOrEqualEnd(startInclusive, endExclusive); + return new OnSubIntervalAllocator(new AllocationInterval( + startInclusive, endExclusive)); } private void checkStartBeforeOrEqualEnd(LocalDate start, LocalDate end) { @@ -776,24 +774,26 @@ public abstract class ResourceAllocation extends "the end must be equal or posterior than start"); } - @Override - public IAllocateHoursOnInterval onIntervalWithinTask(LocalDate start, - LocalDate end) { - return new AllocateHoursOnInterval(start, end); - } + private class OnSubIntervalAllocator implements + IAllocateHoursOnInterval { - @Override - public IAllocateHoursOnInterval onInterval( - final LocalDate startInclusive, final LocalDate endExclusive) { - checkStartBeforeOrEqualEnd(startInclusive, endExclusive); - return new IAllocateHoursOnInterval() { + private final AllocationInterval allocationInterval; - @Override - public void allocateHours(int hours) { - allocateInterval(startInclusive, endExclusive, hours); - } + private OnSubIntervalAllocator( + AllocationInterval allocationInterval) { + this.allocationInterval = allocationInterval; + } - }; + @Override + public void allocateHours(int hours) { + allocateDuration(hours(hours)); + } + + private void allocateDuration(EffortDuration duration) { + List assignmentsCreated = createAssignments( + allocationInterval, duration); + allocationInterval.resetAssignments(assignmentsCreated); + } } @Override @@ -831,26 +831,6 @@ public abstract class ResourceAllocation extends updateResourcesPerDay(); } - private void allocateSubintervalWithinTaskBounds( - LocalDate startInclusive, LocalDate endExclusive, - EffortDuration durationToAssign) { - AllocationIntervalInsideTask interval = new AllocationIntervalInsideTask( - startInclusive, endExclusive); - List assignmentsCreated = createAssignments(interval, - durationToAssign); - resetAssigmentsForInterval(interval, assignmentsCreated); - } - - private void allocateInterval(LocalDate startInclusive, - LocalDate endExclusive, int hours) { - AllocationInterval interval = new AllocationInterval( - startInclusive, endExclusive); - List assignmentsCreated = createAssignments(interval, - hours(hours)); - resetAssigmentsFittingAllocationDatesToResultingAssignments( - interval, assignmentsCreated); - } - protected abstract AvailabilityTimeLine getResourcesAvailability(); private List createAssignments(AllocationInterval interval, @@ -990,6 +970,11 @@ public abstract class ResourceAllocation extends this.end = IntraDayDate.max(this.start, end); } + public void resetAssignments(List assignmentsCreated) { + resetAssigmentsFittingAllocationDatesToResultingAssignments(this, + assignmentsCreated); + } + public AllocationInterval(LocalDate startInclusive, LocalDate endExclusive) { this(IntraDayDate.startOfDay(startInclusive), IntraDayDate @@ -1025,6 +1010,11 @@ public abstract class ResourceAllocation extends .getFirstDayNotConsolidated()), IntraDayDate.min( endExclusive, task.getIntraDayEndDate())); } + + @Override + public void resetAssignments(List assignmentsCreated) { + resetAssigmentsForInterval(this, assignmentsCreated); + } } protected void resetAssigmentsForInterval(