From 0fc24014d69fa0679aceb258a200c5f163199c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Sun, 24 Jan 2010 23:48:52 +0100 Subject: [PATCH] ItEr44S16CUAsignacionRecursosEspecificosAPlanificacionItEr37S10: Moving copy methods from model to entity. This makes easier to copy new fields --- .../planner/entities/StretchesFunction.java | 18 ++++++++++++++ .../streches/StretchesFunctionModel.java | 24 +++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) 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; } }