common: Make data size and speed formatters static
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 21 Apr 2016 16:26:17 +0000 (12:26 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 11 May 2016 12:22:32 +0000 (08:22 -0400)
They cannot be constructed anymore, they can be retrieved through a

Also fix the format when the type is not a Number, it should still append the
value to the string.

Change-Id: I42968def6be830589caac3c824d85a5056121f30
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/71172
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/io/diskioactivity/DisksIOActivityViewer.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/kernelmemoryusage/KernelMemoryUsageViewer.java
common/org.eclipse.tracecompass.common.core.tests/src/org/eclipse/tracecompass/common/core/tests/format/DataSizeFormatTest.java
common/org.eclipse.tracecompass.common.core.tests/src/org/eclipse/tracecompass/common/core/tests/format/DataSpeedFormatTest.java
common/org.eclipse.tracecompass.common.core/src/org/eclipse/tracecompass/common/core/format/DataSizeWithUnitFormat.java
common/org.eclipse.tracecompass.common.core/src/org/eclipse/tracecompass/common/core/format/DataSpeedWithUnitFormat.java
lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java

index a2657a5586a526c7497d944d4ab8fccbf2a244e1..0ef01de08d56fad26ec69699bc0b0edbd5990e5d 100644 (file)
@@ -52,7 +52,7 @@ public class DisksIOActivityViewer extends TmfCommonXLineChartViewer {
         super(parent, Messages.DiskIOActivityViewer_Title, Messages.DiskIOActivityViewer_XAxis, Messages.DiskIOActivityViewer_YAxis);
         setResolution(RESOLUTION);
         Chart chart = getSwtChart();
-        chart.getAxisSet().getYAxis(0).getTick().setFormat(new DataSpeedWithUnitFormat());
+        chart.getAxisSet().getYAxis(0).getTick().setFormat(DataSpeedWithUnitFormat.getInstance());
         chart.getLegend().setPosition(SWT.LEFT);
     }
 
index c54184aaa9b8b5b1024218bea516c8f111893173..64bf89a8d9a6b7736f3a0f54c34127e421697f96 100644 (file)
@@ -49,7 +49,7 @@ public class KernelMemoryUsageViewer extends TmfCommonXLineChartViewer {
     public KernelMemoryUsageViewer(Composite parent) {
         super(parent, Messages.MemoryUsageViewer_title, Messages.MemoryUsageViewer_xAxis, Messages.MemoryUsageViewer_yAxis);
         Chart chart = getSwtChart();
-        chart.getAxisSet().getYAxis(0).getTick().setFormat(new DataSizeWithUnitFormat());
+        chart.getAxisSet().getYAxis(0).getTick().setFormat(DataSizeWithUnitFormat.getInstance());
         chart.getLegend().setPosition(SWT.BOTTOM);
     }
 
index 6f667513a2bc5df4994629c5a43305621dca0e51..396acf4b1a97acef1b3d2fc3423034f3b80e964a 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.runners.Parameterized.Parameters;
 @RunWith(Parameterized.class)
 public class DataSizeFormatTest {
 
-    private static final @NonNull Format FORMAT = new DataSizeWithUnitFormat();
+    private static final @NonNull Format FORMAT = DataSizeWithUnitFormat.getInstance();
 
     private final @NonNull Number fNumValue;
     private final @NonNull String fExpected;
index 5db0da2419f60142dfcf05def511f7fcb5c12617..e3b70ef4ce6c711f0bd9243a4ec6bffd60a4f0ab 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.tracecompass.common.core.format.DataSpeedWithUnitFormat;
  */
 public class DataSpeedFormatTest extends DataSizeFormatTest {
 
-    private static final @NonNull Format FORMAT = new DataSpeedWithUnitFormat();
+    private static final @NonNull Format FORMAT = DataSpeedWithUnitFormat.getInstance();
     private static final String PER_SECOND = "/s";
 
     /**
index 68f15fae1e2a61ebea379e33b41e795eee518798..72f8575041aa9e1a8cca171f06a322aa025bbe9d 100644 (file)
@@ -14,6 +14,8 @@ import java.text.FieldPosition;
 import java.text.Format;
 import java.text.ParsePosition;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Provides a formatter for data sizes along with the unit of size (KG, MB, GB
  * ou TB). It receives a size in bytes and it formats a number in the closest
@@ -24,6 +26,8 @@ import java.text.ParsePosition;
  */
 public class DataSizeWithUnitFormat extends Format {
 
+    private static final @NonNull Format INSTANCE = new DataSizeWithUnitFormat();
+
     private static final long serialVersionUID = 3934127385682676804L;
     private static final String B = "B"; //$NON-NLS-1$
     private static final String KB = "KB"; //$NON-NLS-1$
@@ -33,6 +37,22 @@ public class DataSizeWithUnitFormat extends Format {
     private static final long KILO = 1024;
     private static final Format FORMAT = new DecimalFormat("#.###"); //$NON-NLS-1$
 
+    /**
+     * Protected constructor
+     */
+    protected DataSizeWithUnitFormat() {
+        super();
+    }
+
+    /**
+     * Returns the instance of this formatter
+     *
+     * @return The instance of this formatter
+     */
+    public static @NonNull Format getInstance() {
+        return INSTANCE;
+    }
+
     @Override
     public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
         if (obj instanceof Number) {
@@ -56,7 +76,7 @@ public class DataSizeWithUnitFormat extends Format {
             }
             return toAppendTo.append(FORMAT.format(value)).append(' ').append(B);
         }
-        return toAppendTo;
+        return toAppendTo.append(obj);
     }
 
     @Override
index 73c16c492a48d7e99752b56031b4956ced5a9cd8..7211bc91b30d3cd337aee29eba797c076e0ee499 100644 (file)
@@ -10,6 +10,9 @@
 package org.eclipse.tracecompass.common.core.format;
 
 import java.text.FieldPosition;
+import java.text.Format;
+
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * Provides a formatter for data speeds in (XB/s). It receives a size in bytes
@@ -21,12 +24,25 @@ import java.text.FieldPosition;
  */
 public class DataSpeedWithUnitFormat extends DataSizeWithUnitFormat {
 
+    private static final @NonNull Format INSTANCE = new DataSpeedWithUnitFormat();
+    private static final long serialVersionUID = -3603301320242441850L;
+    private static final String PER_SECOND = "/s"; //$NON-NLS-1$
+
     /**
-     *
+     * Protected constructor
      */
-    private static final long serialVersionUID = -3603301320242441850L;
+    protected DataSpeedWithUnitFormat() {
+        super();
+    }
 
-    private static final String PER_SECOND = "/s"; //$NON-NLS-1$
+    /**
+     * Returns the instance of this formatter
+     *
+     * @return The instance of this formatter
+     */
+    public static @NonNull Format getInstance() {
+        return INSTANCE;
+    }
 
     @Override
     public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
index ceb849352e02b24d866e4f1005596dfb9b8896bc..f358010c822429fbedb8273c33a3d0cbee956f75 100644 (file)
@@ -65,7 +65,7 @@ public class MemoryUsageViewer extends TmfCommonXLineChartViewer {
         super(parent, Messages.MemoryUsageViewer_Title, Messages.MemoryUsageViewer_XAxis, Messages.MemoryUsageViewer_YAxis);
         Chart chart = getSwtChart();
         chart.getLegend().setPosition(SWT.LEFT);
-        chart.getAxisSet().getYAxis(0).getTick().setFormat(new DataSizeWithUnitFormat());
+        chart.getAxisSet().getYAxis(0).getTick().setFormat(DataSizeWithUnitFormat.getInstance());
     }
 
     @Override
This page took 0.028695 seconds and 5 git commands to generate.