charts: Add units to numerical descriptors
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 24 Jan 2017 18:36:30 +0000 (13:36 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Tue, 31 Jan 2017 15:00:01 +0000 (10:00 -0500)
Like durations, any numerical descriptor could have units. Duration can
now inherit more of its parent behavior.

Change-Id: I151936bf5700dd6bb9b60b2d60a51350b5ec8083
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/89467
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/descriptor/DurationDescriptorTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/descriptor/NumericalDescriptorTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core/src/org/eclipse/tracecompass/internal/provisional/tmf/chart/core/descriptor/DataChartDurationDescriptor.java
tmf/org.eclipse.tracecompass.tmf.chart.core/src/org/eclipse/tracecompass/internal/provisional/tmf/chart/core/descriptor/DataChartNumericalDescriptor.java

index a0ee4a98627c8fa3aa687ebaff4225ec1a229957..59ae997d841af777124a6831ea9d45d0dce88c67 100644 (file)
@@ -14,5 +14,7 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.tracecompass.tmf.chart.core
 Export-Package: org.eclipse.tracecompass.internal.tmf.chart.core.tests;x-internal:=true,
  org.eclipse.tracecompass.tmf.chart.core.tests.chart,
+ org.eclipse.tracecompass.tmf.chart.core.tests.consumer,
+ org.eclipse.tracecompass.tmf.chart.core.tests.descriptor,
  org.eclipse.tracecompass.tmf.chart.core.tests.resolver,
  org.eclipse.tracecompass.tmf.chart.core.tests.stubs
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/descriptor/DurationDescriptorTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/descriptor/DurationDescriptorTest.java
new file mode 100644 (file)
index 0000000..551a6a9
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.descriptor;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartDurationDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link DataChartDurationDescriptor} class
+ *
+ * @author Geneviève Bastien
+ */
+public class DurationDescriptorTest {
+
+    private static final @NonNull String DESC_NAME = "test";
+
+    private final @NonNull INumericalResolver<StubObject, @NonNull Long> fResolver = new AbstractLongResolver<StubObject>() {
+
+        @Override
+        public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+            return o -> o.getLong();
+        }
+    };
+
+    /**
+     * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver)} constructor
+     */
+    @Test
+    public void testConstructor() {
+        DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartDurationDescriptor<>(DESC_NAME, fResolver);
+        assertEquals(DESC_NAME, desc.getName());
+        assertEquals("ns", desc.getUnit());
+        assertEquals(DESC_NAME + " (ns)", desc.getLabel());
+    }
+
+    /**
+     * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver, String)} constructor
+     */
+    @Test
+    public void testConstructorWithUnit() {
+        String unit = "bla";
+        DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartDurationDescriptor<>(DESC_NAME, fResolver, unit);
+        assertEquals(DESC_NAME, desc.getName());
+        assertEquals(unit, desc.getUnit());
+        assertEquals(DESC_NAME + " (" + unit + ')', desc.getLabel());
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/descriptor/NumericalDescriptorTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/descriptor/NumericalDescriptorTest.java
new file mode 100644 (file)
index 0000000..df007ad
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.descriptor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link DataChartNumericalDescriptor} class
+ *
+ * @author Geneviève Bastien
+ */
+public class NumericalDescriptorTest {
+
+    private static final @NonNull String DESC_NAME = "test";
+
+    private final @NonNull INumericalResolver<StubObject, @NonNull Long> fResolver = new AbstractLongResolver<StubObject>() {
+
+        @Override
+        public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+            return o -> o.getLong();
+        }
+    };
+
+    /**
+     * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver)} constructor
+     */
+    @Test
+    public void testConstructor() {
+        DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartNumericalDescriptor<>(DESC_NAME, fResolver);
+        assertEquals(DESC_NAME, desc.getName());
+        assertNull(desc.getUnit());
+        assertEquals(DESC_NAME, desc.getLabel());
+    }
+
+    /**
+     * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver, String)} constructor
+     */
+    @Test
+    public void testConstructorWithUnit() {
+        String unit = "bla";
+        DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartNumericalDescriptor<>(DESC_NAME, fResolver, unit);
+        assertEquals(DESC_NAME, desc.getName());
+        assertEquals(unit, desc.getUnit());
+        assertEquals(DESC_NAME + " (" + unit + ')', desc.getLabel());
+    }
+
+}
index b90b04a1a0f43b7e8291553f8dcd59bc33edc18c..d4f83ce85c89231cf9d7575f392cc0b76afb26a3 100644 (file)
@@ -13,7 +13,8 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
 
 /**
- * Generic descriptor that describes a time range duration.
+ * Generic descriptor that describes a time range duration. Its default units
+ * are nanoseconds.
  *
  * @param <T>
  *            The type of the input it understands
@@ -43,7 +44,21 @@ public class DataChartDurationDescriptor<T, R extends Number> extends DataChartN
      *            The resolver used for mapping durations
      */
     public DataChartDurationDescriptor(String name, INumericalResolver<T, R> resolver) {
-        super(name, resolver);
+        super(name, resolver, UNIT);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param name
+     *            The name of the descriptor
+     * @param resolver
+     *            The resolver used for mapping numbers
+     * @param unit
+     *            The unit of this descriptor, eg. s, ms, ns
+     */
+    public DataChartDurationDescriptor(String name, INumericalResolver<T, R> resolver, @Nullable String unit) {
+        super(name, resolver, unit);
     }
 
     // ------------------------------------------------------------------------
@@ -55,9 +70,4 @@ public class DataChartDurationDescriptor<T, R extends Number> extends DataChartN
         visitor.visit(this);
     }
 
-    @Override
-    public @Nullable String getUnit() {
-        return UNIT;
-    }
-
 }
index edf554976a2fed6b5a37a3809b70b94dfad0dd3b..a3f2196bc21fc67aa9a842b20e64552d48586fcf 100644 (file)
@@ -34,6 +34,8 @@ public class DataChartNumericalDescriptor<T, R extends Number> implements IDataC
     private final String fName;
     private final INumericalResolver<T, R> fResolver;
 
+    private final @Nullable String fUnit;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -47,8 +49,23 @@ public class DataChartNumericalDescriptor<T, R extends Number> implements IDataC
      *            The resolver used for mapping numbers
      */
     public DataChartNumericalDescriptor(String name, INumericalResolver<T, R> resolver) {
+        this(name, resolver, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param name
+     *            The name of the descriptor
+     * @param resolver
+     *            The resolver used for mapping numbers
+     * @param unit
+     *            The unit of this descriptor, eg. s, ms, ns
+     */
+    public DataChartNumericalDescriptor(String name, INumericalResolver<T, R> resolver, @Nullable String unit) {
         fName = name;
         fResolver = resolver;
+        fUnit = unit;
     }
 
     // ------------------------------------------------------------------------
@@ -72,7 +89,7 @@ public class DataChartNumericalDescriptor<T, R extends Number> implements IDataC
 
     @Override
     public @Nullable String getUnit() {
-        return null;
+        return fUnit;
     }
 
     @Override
This page took 0.029441 seconds and 5 git commands to generate.