You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by cd...@apache.org on 2018/02/14 21:20:11 UTC
incubator-edgent-samples git commit: - Replaced the code for rounding
double values to a given number of fractional digits in order to make it work
in other locales than "EN"
Repository: incubator-edgent-samples
Updated Branches:
refs/heads/develop 5f06787fe -> 2fadbbf57
- Replaced the code for rounding double values to a given number of fractional digits in order to make it work in other locales than "EN"
Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent-samples/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent-samples/commit/2fadbbf5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent-samples/tree/2fadbbf5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent-samples/diff/2fadbbf5
Branch: refs/heads/develop
Commit: 2fadbbf574ee9fbf0d839fe18ce23de20d6d5d21
Parents: 5f06787
Author: Christofer Dutz <ch...@c-ware.de>
Authored: Wed Feb 14 22:20:03 2018 +0100
Committer: Christofer Dutz <ch...@c-ware.de>
Committed: Wed Feb 14 22:20:03 2018 +0100
----------------------------------------------------------------------
.../samples/utils/sensor/SimpleSimulatedSensor.java | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-edgent-samples/blob/2fadbbf5/utils/src/main/java/org/apache/edgent/samples/utils/sensor/SimpleSimulatedSensor.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/org/apache/edgent/samples/utils/sensor/SimpleSimulatedSensor.java b/utils/src/main/java/org/apache/edgent/samples/utils/sensor/SimpleSimulatedSensor.java
index 0e306ca..2c3b598 100644
--- a/utils/src/main/java/org/apache/edgent/samples/utils/sensor/SimpleSimulatedSensor.java
+++ b/utils/src/main/java/org/apache/edgent/samples/utils/sensor/SimpleSimulatedSensor.java
@@ -19,9 +19,9 @@ under the License.
package org.apache.edgent.samples.utils.sensor;
-import java.text.DecimalFormat;
import java.util.Random;
+import org.apache.commons.math3.util.Precision;
import org.apache.edgent.analytics.sensors.Range;
import org.apache.edgent.function.Supplier;
@@ -52,7 +52,6 @@ import org.apache.edgent.function.Supplier;
public class SimpleSimulatedSensor implements Supplier<Double> {
private static final long serialVersionUID = 1L;
private int numFracDigits;
- private volatile DecimalFormat df;
private Random r = new Random();
private final Range<Double> range;
private final double deltaFactor;
@@ -126,13 +125,7 @@ public class SimpleSimulatedSensor implements Supplier<Double> {
public void setNumberFractionalDigits(int numFracDigits) {
this.numFracDigits = numFracDigits;
if (numFracDigits <= 0) {
- df = null;
- }
- else {
- String fracPattern = "";
- for (int i = 0; i < numFracDigits; i++)
- fracPattern += "#";
- df = new DecimalFormat("#."+fracPattern);
+ this.numFracDigits = 0;
}
}
@@ -167,9 +160,7 @@ public class SimpleSimulatedSensor implements Supplier<Double> {
? range.upperEndpoint()
: range.lowerEndpoint();
}
- if (df != null)
- nextValue = Double.valueOf(df.format(nextValue));
- currentValue = nextValue;
+ currentValue = Precision.round(nextValue, numFracDigits);
return currentValue;
}
}