Mercurial > lada > lada-server
changeset 948:c9b84bca3e3d
Round some values to three digits, breaking ties half to even, before storing.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 23 May 2016 15:49:30 +0200 |
parents | 0a80f4a87c67 |
children | 2c927b3edb97 |
files | src/main/java/de/intevation/lada/model/Messwert.java src/main/java/de/intevation/lada/model/ZusatzWert.java src/main/java/de/intevation/lada/util/data/MathUtil.java |
diffstat | 3 files changed, 38 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/Messwert.java Wed May 18 18:21:33 2016 +0200 +++ b/src/main/java/de/intevation/lada/model/Messwert.java Mon May 23 15:49:30 2016 +0200 @@ -18,6 +18,8 @@ import javax.persistence.Table; import javax.persistence.Transient; +import de.intevation.lada.util.data.MathUtil; + /** * The persistent class for the messwert database table. @@ -126,7 +128,7 @@ } public void setMesswert(Double messwert) { - this.messwert = messwert; + this.messwert = MathUtil.roundDoubleToThree(messwert); } public String getMesswertNwg() { @@ -142,7 +144,7 @@ } public void setNwgZuMesswert(Double nwgZuMesswert) { - this.nwgZuMesswert = nwgZuMesswert; + this.nwgZuMesswert = MathUtil.roundDoubleToThree(nwgZuMesswert); } public boolean isOwner() {
--- a/src/main/java/de/intevation/lada/model/ZusatzWert.java Wed May 18 18:21:33 2016 +0200 +++ b/src/main/java/de/intevation/lada/model/ZusatzWert.java Mon May 23 15:49:30 2016 +0200 @@ -18,6 +18,8 @@ import javax.persistence.Table; import javax.persistence.Transient; +import de.intevation.lada.util.data.MathUtil; + /** * The persistent class for the zusatz_wert database table. @@ -87,7 +89,7 @@ } public void setMesswertPzs(Double messwertPzs) { - this.messwertPzs = messwertPzs; + this.messwertPzs = MathUtil.roundDoubleToThree(messwertPzs); } public Double getNwgZuMesswert() { @@ -95,7 +97,7 @@ } public void setNwgZuMesswert(Double nwgZuMesswert) { - this.nwgZuMesswert = nwgZuMesswert; + this.nwgZuMesswert = MathUtil.roundDoubleToThree(nwgZuMesswert); } public Integer getProbeId() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/data/MathUtil.java Mon May 23 15:49:30 2016 +0200 @@ -0,0 +1,30 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.util.data; + +import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; + +/** + * Utilities for calculations + * + */ +public class MathUtil { + + public static final MathContext ROUNDING_CONTEXT = new MathContext( + 3, RoundingMode.HALF_EVEN); + + public static Double roundDoubleToThree(Double value) { + if (value == null) { + return null; + } + return BigDecimal.valueOf(value).round(ROUNDING_CONTEXT).doubleValue(); + } + +}