ONOS-3320: PropertyPanelTest fails in non-English locale.
- Added formatter() instance method that can be overridden by unit test.
Change-Id: I38ee045edee852c95e27bead46800fb5dad4cf88
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java b/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java
index a165be3..c75eccf 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java
@@ -18,7 +18,7 @@
import com.google.common.collect.Sets;
-import java.text.DecimalFormat;
+import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -28,7 +28,7 @@
*/
public class PropertyPanel {
- private static final DecimalFormat DF0 = new DecimalFormat("#,###");
+ private static final NumberFormat NF = NumberFormat.getInstance();
private String title;
private String typeId;
@@ -49,6 +49,24 @@
}
/**
+ * Returns a number formatter to use for formatting integer and long
+ * property values.
+ * <p>
+ * This default implementation uses a formatter for the default
+ * locale. For example:
+ * <pre>
+ * Locale.ENGLISH : 1000 -> "1,000"
+ * Locale.FRENCH : 1000 -> "1 000"
+ * Locale.GERMAN : 1000 -> "1.000"
+ * </pre>
+ *
+ * @return the number formatter
+ */
+ protected NumberFormat formatter() {
+ return NF;
+ }
+
+ /**
* Adds an ID field to the panel data, to be included in
* the returned JSON data to the client.
*
@@ -80,7 +98,7 @@
* @return self, for chaining
*/
public PropertyPanel addProp(String key, int value) {
- properties.add(new Prop(key, DF0.format(value)));
+ properties.add(new Prop(key, formatter().format(value)));
return this;
}
@@ -92,7 +110,7 @@
* @return self, for chaining
*/
public PropertyPanel addProp(String key, long value) {
- properties.add(new Prop(key, DF0.format(value)));
+ properties.add(new Prop(key, formatter().format(value)));
return this;
}