diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java index 26e8b8d06..e89e7669f 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java @@ -187,6 +187,24 @@ public class StretchesFunction extends AssignmentFunction { */ private Type desiredType; + public StretchesFunction copy() { + StretchesFunction result = StretchesFunction.create(); + result.resetToStrechesFrom(this); + return result; + } + + public void resetToStrechesFrom(StretchesFunction from) { + this.removeAllStretches(); + for (Stretch each : from.getStretches()) { + Stretch newStretch = new Stretch(); + newStretch.setDate(each.getDate()); + newStretch.setLengthPercentage(each.getLengthPercentage()); + newStretch.setAmountWorkPercentage(each + .getAmountWorkPercentage()); + this.addStretch(newStretch); + } + } + public void setStretches(List stretches) { this.stretches = stretches; } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java index 34eae0696..417958841 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java @@ -91,7 +91,7 @@ public class StretchesFunctionModel implements IStretchesFunctionModel { if (stretchesFunction != null) { assignmentFunctionDAO.reattach(stretchesFunction); this.originalStretchesFunction = stretchesFunction; - this.stretchesFunction = copy(stretchesFunction); + this.stretchesFunction = stretchesFunction.copy(); this.task = task; forceLoadTask(); @@ -106,25 +106,6 @@ public class StretchesFunctionModel implements IStretchesFunctionModel { task.getCalendar(); } - private static StretchesFunction copy(StretchesFunction stretchesFunction) { - StretchesFunction copy = StretchesFunction.create(); - copyStretches(stretchesFunction, copy); - return copy; - } - - private static void copyStretches(StretchesFunction original, - StretchesFunction copy) { - copy.removeAllStretches(); - for (Stretch stretch : original.getStretches()) { - Stretch newStretch = new Stretch(); - newStretch.setDate(stretch.getDate()); - newStretch.setLengthPercentage(stretch.getLengthPercentage()); - newStretch.setAmountWorkPercentage(stretch - .getAmountWorkPercentage()); - copy.addStretch(newStretch); - } - } - @Override public List getStretches() { if (stretchesFunction == null) { @@ -152,7 +133,8 @@ public class StretchesFunctionModel implements IStretchesFunctionModel { } if (originalStretchesFunction != null) { - copyStretches(stretchesFunction, originalStretchesFunction); + originalStretchesFunction + .resetToStrechesFrom(stretchesFunction); stretchesFunction = originalStretchesFunction; } }