This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 95222172d0b008cd3e7176b874e34b583c4cc43d Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Mar 16 17:33:27 2016 +0100 Permettre d'arrondir à partir d'une unité --- .../java/fr/ifremer/tutti/type/WeightUnit.java | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java index f56b5cb..9649279 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java @@ -22,6 +22,7 @@ package fr.ifremer.tutti.type; * #L% */ +import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Objects; @@ -49,6 +50,20 @@ public enum WeightUnit { public Float toEntity(Float weight) { return weight == null ? null : weight / 1000.0f; } + + @Override + public Float round(Float weight) { + Float result; + if (weight == null) { + result = null; + } else { + BigDecimal sumB = new BigDecimal(String.valueOf(weight)) + .setScale(2, BigDecimal.ROUND_HALF_UP) + .abs(); + result = sumB.floatValue(); + } + return result; + } }, KG(n("application.common.unit.kg"), n("application.common.unit.short.kg"), 4, "\\d{0,6}(\\.\\d{0,4})?") { @Override @@ -60,6 +75,21 @@ public enum WeightUnit { public Float toEntity(Float weight) { return weight; } + + @Override + public Float round(Float weight) { + Float result; + if (weight == null) { + result = null; + } else { + + BigDecimal sumB = new BigDecimal(String.valueOf(weight)) + .setScale(3, BigDecimal.ROUND_HALF_UP) + .abs(); + result = sumB.floatValue(); + } + return result; + } }; private final String i18nShortKey; @@ -130,9 +160,11 @@ public enum WeightUnit { */ public abstract Float toEntity(Float weight); + public abstract Float round(Float weight); + public Float convertWeight(Float weight, WeightUnit weightUnit) { Objects.requireNonNull(weightUnit); - return fromEntity(weightUnit.toEntity(weight)); + return round(fromEntity(weightUnit.toEntity(weight))); } public String decorateLabel(String label) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.