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);
}
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);
}
@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;
*/
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";
/**
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
*/
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$
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) {
}
return toAppendTo.append(FORMAT.format(value)).append(' ').append(B);
}
- return toAppendTo;
+ return toAppendTo.append(obj);
}
@Override
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
*/
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) {
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