]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/ValueFormatUtil.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagram / ValueFormatUtil.java
index c3a0a7375661373af8a81304def1f3d18910ce37..8a541eefcd67c643d56c63a5cdc4a52550e81e3e 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.ui.diagram;\r
-\r
-import java.util.Arrays;\r
-\r
-import org.simantics.utils.strings.format.MetricsFormat;\r
-import org.simantics.utils.strings.format.MetricsFormatList;\r
-\r
-public final class ValueFormatUtil {\r
-\r
-    static String valueStr(Object value_) {\r
-        if (value_ == null)\r
-            return "<null>";\r
-        //return valueStr(value_, "0.0###");\r
-        return valueStr(value_, MetricsFormatList.METRICS_GENERIC);\r
-    }\r
-\r
-    public static String valueStr(Object value_, MetricsFormat decimalFormat) {\r
-        if (value_ == null)\r
-            return "<null>";\r
-\r
-        Class<?> clazz = value_.getClass();\r
-        //System.out.println("FOO: " + clazz + ": " + value_);\r
-        if (clazz.isArray()) {\r
-            Class<?> componentType = clazz.getComponentType();\r
-            if (componentType.isPrimitive()) {\r
-                if (double[].class == clazz) {\r
-                    return formatDouble((double[]) value_, decimalFormat);\r
-                } else if (float[].class == clazz) {\r
-                    return formatFloat((float[]) value_, decimalFormat);\r
-                } else if (boolean[].class == clazz) {\r
-                    return formatBoolean((boolean[]) value_);\r
-                } else if (int[].class == clazz) {\r
-                    return formatInteger((int[]) value_);\r
-                } else if (long[].class == clazz) {\r
-                    return formatLong((long[]) value_);\r
-                } else if (byte[].class == clazz) {\r
-                    return formatByte((byte[]) value_);\r
-                } else {\r
-                    return value_.toString();\r
-                }\r
-            } else {\r
-                if (String[].class == clazz) {\r
-                    return formatString((String[]) value_);\r
-                } else {\r
-                    return value_.toString();\r
-                }\r
-            }\r
-        }\r
-\r
-        if (Double.class == clazz)\r
-            return formatDouble( (Double) value_, decimalFormat );\r
-        else if (Float.class == clazz)\r
-            return formatFloat(new float[] { (Float) value_ }, decimalFormat);\r
-\r
-        // String.class == clazz\r
-        // Boolean.class == clazz\r
-        // Integer.class == clazz\r
-        // Long.class == clazz\r
-        // Byte.class == clazz\r
-        return value_.toString();\r
-    }\r
-\r
-    private static String formatDouble(double[] ds, MetricsFormat f) {\r
-        StringBuilder sb = new StringBuilder();\r
-//        DecimalFormat format = new DecimalFormat(f, DecimalFormatSymbols.getInstance(Locale.US));\r
-        boolean first = true;\r
-        for (double d : ds) {\r
-            if (!first)\r
-                sb.append(", ");\r
-            else\r
-                first = false;\r
-            //sb.append(format.format(d));\r
-            sb.append(f.formatValue(d));\r
-        }\r
-        return sb.toString();\r
-    }\r
-\r
-    private static String formatDouble(double d, MetricsFormat f) {\r
-        //DecimalFormat format = new DecimalFormat(f, DecimalFormatSymbols.getInstance(Locale.US));\r
-        //return format.format(d);\r
-        return f.formatValue(d);\r
-    }\r
-\r
-    private static String formatFloat(float[] ds, MetricsFormat f) {\r
-        StringBuilder sb = new StringBuilder();\r
-        //DecimalFormat format = new DecimalFormat(f, DecimalFormatSymbols.getInstance(Locale.US));\r
-        boolean first = true;\r
-        for (float d : ds) {\r
-            if (!first)\r
-                sb.append(", ");\r
-            else\r
-                first = false;\r
-            //sb.append(format.format(d));\r
-            sb.append(f.formatValue(d));\r
-        }\r
-        return sb.toString();\r
-    }\r
-\r
-    private static String formatString(String[] value) {\r
-        if (value.length == 1)\r
-            return value[0];\r
-        else\r
-            return Arrays.toString(value);\r
-    }\r
-\r
-    private static String formatBoolean(boolean[] value) {\r
-        if (value.length == 1)\r
-            return Boolean.toString(value[0]);\r
-        else\r
-            return Arrays.toString(value);\r
-    }\r
-\r
-    private static String formatInteger(int[] value) {\r
-        if (value.length == 1)\r
-            return Integer.toString(value[0]);\r
-        else\r
-            return Arrays.toString(value);\r
-    }\r
-\r
-    private static String formatLong(long[] value) {\r
-        if (value.length == 1)\r
-            return Long.toString(value[0]);\r
-        else\r
-            return Arrays.toString(value);\r
-    }\r
-\r
-    private static String formatByte(byte[] value) {\r
-        if (value.length == 1)\r
-            return Byte.toString(value[0]);\r
-        else\r
-            return Arrays.toString(value);\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.ui.diagram;
+
+import java.util.Arrays;
+
+import org.simantics.utils.strings.format.MetricsFormat;
+import org.simantics.utils.strings.format.MetricsFormatList;
+
+public final class ValueFormatUtil {
+
+    static String valueStr(Object value_) {
+        if (value_ == null)
+            return "<null>";
+        //return valueStr(value_, "0.0###");
+        return valueStr(value_, MetricsFormatList.METRICS_GENERIC);
+    }
+
+    public static String valueStr(Object value_, MetricsFormat decimalFormat) {
+        if (value_ == null)
+            return "<null>";
+
+        Class<?> clazz = value_.getClass();
+        //System.out.println("FOO: " + clazz + ": " + value_);
+        if (clazz.isArray()) {
+            Class<?> componentType = clazz.getComponentType();
+            if (componentType.isPrimitive()) {
+                if (double[].class == clazz) {
+                    return formatDouble((double[]) value_, decimalFormat);
+                } else if (float[].class == clazz) {
+                    return formatFloat((float[]) value_, decimalFormat);
+                } else if (boolean[].class == clazz) {
+                    return formatBoolean((boolean[]) value_);
+                } else if (int[].class == clazz) {
+                    return formatInteger((int[]) value_);
+                } else if (long[].class == clazz) {
+                    return formatLong((long[]) value_);
+                } else if (byte[].class == clazz) {
+                    return formatByte((byte[]) value_);
+                } else {
+                    return value_.toString();
+                }
+            } else {
+                if (String[].class == clazz) {
+                    return formatString((String[]) value_);
+                } else {
+                    return value_.toString();
+                }
+            }
+        }
+
+        if (Double.class == clazz)
+            return formatDouble( (Double) value_, decimalFormat );
+        else if (Float.class == clazz)
+            return formatFloat(new float[] { (Float) value_ }, decimalFormat);
+
+        // String.class == clazz
+        // Boolean.class == clazz
+        // Integer.class == clazz
+        // Long.class == clazz
+        // Byte.class == clazz
+        return value_.toString();
+    }
+
+    private static String formatDouble(double[] ds, MetricsFormat f) {
+        StringBuilder sb = new StringBuilder();
+//        DecimalFormat format = new DecimalFormat(f, DecimalFormatSymbols.getInstance(Locale.US));
+        boolean first = true;
+        for (double d : ds) {
+            if (!first)
+                sb.append(", ");
+            else
+                first = false;
+            //sb.append(format.format(d));
+            sb.append(f.formatValue(d));
+        }
+        return sb.toString();
+    }
+
+    private static String formatDouble(double d, MetricsFormat f) {
+        //DecimalFormat format = new DecimalFormat(f, DecimalFormatSymbols.getInstance(Locale.US));
+        //return format.format(d);
+        return f.formatValue(d);
+    }
+
+    private static String formatFloat(float[] ds, MetricsFormat f) {
+        StringBuilder sb = new StringBuilder();
+        //DecimalFormat format = new DecimalFormat(f, DecimalFormatSymbols.getInstance(Locale.US));
+        boolean first = true;
+        for (float d : ds) {
+            if (!first)
+                sb.append(", ");
+            else
+                first = false;
+            //sb.append(format.format(d));
+            sb.append(f.formatValue(d));
+        }
+        return sb.toString();
+    }
+
+    private static String formatString(String[] value) {
+        if (value.length == 1)
+            return value[0];
+        else
+            return Arrays.toString(value);
+    }
+
+    private static String formatBoolean(boolean[] value) {
+        if (value.length == 1)
+            return Boolean.toString(value[0]);
+        else
+            return Arrays.toString(value);
+    }
+
+    private static String formatInteger(int[] value) {
+        if (value.length == 1)
+            return Integer.toString(value[0]);
+        else
+            return Arrays.toString(value);
+    }
+
+    private static String formatLong(long[] value) {
+        if (value.length == 1)
+            return Long.toString(value[0]);
+        else
+            return Arrays.toString(value);
+    }
+
+    private static String formatByte(byte[] value) {
+        if (value.length == 1)
+            return Byte.toString(value[0]);
+        else
+            return Arrays.toString(value);
+    }
+
+}