From dca3ed6c486ee197b9dd45bd1e42e1e43f9d5983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 16 Nov 2010 20:30:11 +0100 Subject: [PATCH] Unify the calculations done for calculating the end keeping the length of the task Now for both tasks with resource allocations and tasks not allocated the end is calculated considering the workable days. FEA: ItEr63OTS03PlanificacionHaciaAtras --- .../business/planner/entities/Task.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java index 953f1f02b..6f68ddc39 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java @@ -465,7 +465,7 @@ public class Task extends TaskElement implements ITaskLeafConstraint { } if (calculatedValue != CalculatedValue.END_DATE || getSatisfiedResourceAllocations().isEmpty()) { - setIntraDayEndDate(calculateNewEndGiven(newStartDate)); + setIntraDayEndDate(calculateEndKeepingLength(newStartDate)); } setIntraDayStartDate(newStartDate); doReassignment(); @@ -475,16 +475,6 @@ public class Task extends TaskElement implements ITaskLeafConstraint { reassign(scenario, new WithTheSameHoursAndResourcesPerDay()); } - private IntraDayDate calculateNewEndGiven( - IntraDayDate newStartDate) { - if (workableDays != null) { - return IntraDayDate - .startOfDay(calculateEndGivenWorkableDays( - newStartDate.getDate(), workableDays)); - } - return calculateEndKeepingLength(newStartDate); - } - @Override public void resizeTo(IntraDayDate endDate) { if (!canBeResized() || getIntraDayEndDate().equals(endDate)) { @@ -525,25 +515,35 @@ public class Task extends TaskElement implements ITaskLeafConstraint { } private IntraDayDate calculateEndKeepingLength(IntraDayDate newStartDate) { - ICalendar calendar = getCalendar() != null ? getCalendar() - : SameWorkHoursEveryDay.getDefaultWorkingDay(); - DurationBetweenDates durationBetweenDates = new DurationBetweenDates( - calendar, getIntraDayStartDate(), getIntraDayEndDate()); + DurationBetweenDates durationBetweenDates = getDurationBetweenDates(); return durationBetweenDates.from(newStartDate); } - private static class DurationBetweenDates { + private DurationBetweenDates getDurationBetweenDates() { + if (workableDays != null) { + return new DurationBetweenDates(workableDays); + } else { + Integer calculatedWorkableDays = getWorkableDaysUntil(getEndAsLocalDate()); + return new DurationBetweenDates(calculatedWorkableDays); + } + } - private final int numberOfDays; + private class DurationBetweenDates { + + private final int numberOfWorkableDays; private final EffortDuration remainderDuration; private final ICalendar calendar; - public DurationBetweenDates(ICalendar calendar, IntraDayDate start, - IntraDayDate end) { - this.calendar = calendar; - this.numberOfDays = start.numberOfDaysUntil(end); + public DurationBetweenDates(int numberOfWorkableDays) { + this.calendar = getCalendar() != null ? getCalendar() + : SameWorkHoursEveryDay.getDefaultWorkingDay(); + this.numberOfWorkableDays = numberOfWorkableDays; + + IntraDayDate start = getIntraDayStartDate(); + IntraDayDate end = getIntraDayEndDate(); + if (start.getEffortDuration().compareTo(end.getEffortDuration()) <= 0) { this.remainderDuration = end.getEffortDuration().minus( start.getEffortDuration()); @@ -559,7 +559,8 @@ public class Task extends TaskElement implements ITaskLeafConstraint { public IntraDayDate from(IntraDayDate newStartDate) { EffortDuration resultDuration = remainderDuration.plus(newStartDate .getEffortDuration()); - LocalDate resultDay = newStartDate.getDate().plusDays(numberOfDays); + LocalDate resultDay = calculateEndGivenWorkableDays( + newStartDate.getDate(), numberOfWorkableDays); EffortDuration capacity = calendar.getCapacityOn(PartialDay .wholeDay(resultDay)); while (resultDuration.compareTo(capacity) > 0) {