Define sub-types of Bandwidth to reduce round-off error
Two sub-types are defined
- LongBandwidth
- DoubleBandwidth
LongBandwidth can reduce round-off error cause by floating point arithmetics.
These classes are not exposed outside the package and only instantiated
through static factory methods.
Change-Id: Ice5d8ff1397c9dd9c8c1fff46af256fff08fa616
diff --git a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
index 713b4b5..e2753b2 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
@@ -371,7 +371,13 @@
// Check for a bandwidth specification
if (!isNullOrEmpty(bandwidthString)) {
- final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
+ Bandwidth bandwidth;
+ try {
+ bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
+ // when the string can't be parsed as long, then try to parse as double
+ } catch (NumberFormatException e) {
+ bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
+ }
constraints.add(new BandwidthConstraint(bandwidth));
}