charts.test: Add a complete set of stub data
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Mon, 30 Jan 2017 20:36:07 +0000 (15:36 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 31 May 2017 18:31:42 +0000 (14:31 -0400)
This stub chart provider can be used to unit test the descriptor types
and consumers

Change-Id: I04ff28f04b3bbdb41891d28b02d3ee523cd57629
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/91934
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/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProvider.java
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProviderFull.java [new file with mode: 0644]

index 354ff76c575f1665359da00293eb0e378f278176..c0019d90db702819f75893958da1cb69bd63f488 100644 (file)
@@ -16,7 +16,7 @@ import java.util.List;
 import java.util.function.Function;
 import java.util.stream.Stream;
 
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
@@ -33,38 +33,40 @@ import org.eclipse.tracecompass.tmf.chart.core.model.IDataChartProvider;
  *
  * @author Geneviève Bastien
  */
+@NonNullByDefault
 public class StubChartProvider implements IDataChartProvider<StubObject> {
 
     /**
      * Name of this chart provider
      */
-    public static final @NonNull String NAME = "Long Chart Provider";
+    public static final String NAME = "Long Chart Provider";
     /**
      * Name of the String descriptor
      */
-    public static final @NonNull String STRING_DESCRIPTOR = "String";
+    public static final String STRING_DESCRIPTOR = "String";
     /**
      * Name of the Integer descriptor
      */
-    public static final @NonNull String INTEGER_DESCRIPTOR = "Integer";
+    public static final String INTEGER_DESCRIPTOR = "Integer";
     /**
      * Name of the Long descriptor
      */
-    public static final @NonNull String LONG_DESCRIPTOR = "Long";
+    public static final String LONG_DESCRIPTOR = "Long";
     /**
      * Name of the Double descriptor
      */
-    public static final @NonNull String DOUBLE_DESCRIPTOR = "Double";
+    public static final String DOUBLE_DESCRIPTOR = "Double";
 
-    private final @NonNull List<@NonNull StubObject> fSource = new ArrayList<>();
+    private final List<StubObject> fSource = new ArrayList<>();
+    private @Nullable List<IDataChartDescriptor<StubObject, ?>> fDescriptors = null;
 
     @Override
-    public @NonNull String getName() {
+    public String getName() {
         return NAME;
     }
 
     @Override
-    public @NonNull Stream<@NonNull StubObject> getSource() {
+    public Stream<StubObject> getSource() {
         return NonNullUtils.checkNotNull(fSource.stream());
     }
 
@@ -75,61 +77,65 @@ public class StubChartProvider implements IDataChartProvider<StubObject> {
      * @param obj
      *            an object to add to the data stream
      */
-    public void addData(@NonNull StubObject obj) {
+    public void addData(StubObject obj) {
         fSource.add(obj);
     }
 
     @Override
-    public @NonNull Collection<@NonNull IDataChartDescriptor<StubObject, ?>> getDataDescriptors() {
-        List<@NonNull IDataChartDescriptor<StubObject, ?>> list = new ArrayList<>();
-        list.add(new DataChartStringDescriptor<>(STRING_DESCRIPTOR, new IStringResolver<StubObject>() {
-
-            @Override
-            public @NonNull Function<StubObject, @Nullable String> getMapper() {
-                return o -> o.getString();
-            }
-        }));
-        list.add(new DataChartNumericalDescriptor<>(INTEGER_DESCRIPTOR, new INumericalResolver<StubObject, @NonNull Integer>() {
-
-            @Override
-            public @NonNull Function<StubObject, @Nullable Integer> getMapper() {
-                return o -> o.getInt();
-            }
-
-            @Override
-            public @NonNull Comparator<@NonNull Integer> getComparator() {
-                return NonNullUtils.checkNotNull(Comparator.naturalOrder());
-            }
-
-            @Override
-            public Integer getMinValue() {
-                return Integer.MIN_VALUE;
-            }
-
-            @Override
-            public Integer getMaxValue() {
-                return Integer.MAX_VALUE;
-            }
-
-            @Override
-            public Integer getZeroValue() {
-                return 0;
-            }
-        }));
-        list.add(new DataChartNumericalDescriptor<>(LONG_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
-
-            @Override
-            public @NonNull Function<StubObject, @Nullable Long> getMapper() {
-                return o -> o.getLong();
-            }
-        }));
-        list.add(new DataChartNumericalDescriptor<>(DOUBLE_DESCRIPTOR, new AbstractDoubleResolver<StubObject>() {
-
-            @Override
-            public @NonNull Function<StubObject, @Nullable Double> getMapper() {
-                return o -> o.getDbl();
-            }
-        }));
+    public Collection<IDataChartDescriptor<StubObject, ?>> getDataDescriptors() {
+        List<IDataChartDescriptor<StubObject, ?>> list = fDescriptors;
+        if (list == null) {
+            list = new ArrayList<>();
+            list.add(new DataChartStringDescriptor<>(STRING_DESCRIPTOR, new IStringResolver<StubObject>() {
+
+                @Override
+                public Function<StubObject, @Nullable String> getMapper() {
+                    return o -> o.getString();
+                }
+            }));
+            list.add(new DataChartNumericalDescriptor<>(INTEGER_DESCRIPTOR, new INumericalResolver<StubObject, Integer>() {
+
+                @Override
+                public Function<StubObject, @Nullable Integer> getMapper() {
+                    return o -> o.getInt();
+                }
+
+                @Override
+                public Comparator<Integer> getComparator() {
+                    return NonNullUtils.checkNotNull(Comparator.naturalOrder());
+                }
+
+                @Override
+                public Integer getMinValue() {
+                    return Integer.MIN_VALUE;
+                }
+
+                @Override
+                public Integer getMaxValue() {
+                    return Integer.MAX_VALUE;
+                }
+
+                @Override
+                public Integer getZeroValue() {
+                    return 0;
+                }
+            }));
+            list.add(new DataChartNumericalDescriptor<>(LONG_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
+
+                @Override
+                public Function<StubObject, @Nullable Long> getMapper() {
+                    return o -> o.getLong();
+                }
+            }));
+            list.add(new DataChartNumericalDescriptor<>(DOUBLE_DESCRIPTOR, new AbstractDoubleResolver<StubObject>() {
+
+                @Override
+                public Function<StubObject, @Nullable Double> getMapper() {
+                    return o -> o.getDbl();
+                }
+            }));
+            fDescriptors = list;
+        }
         return list;
     }
 
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProviderFull.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProviderFull.java
new file mode 100644 (file)
index 0000000..a3139b2
--- /dev/null
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * 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.stubs;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartDurationDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartStringDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartTimestampDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+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.internal.provisional.tmf.chart.core.resolver.IStringResolver;
+
+/**
+ * A chart provider that returns a few descriptors of each types. It allows to
+ * test the interactions of many types of descriptors, similar and different.
+ *
+ * @author Geneviève Bastien
+ */
+@NonNullByDefault
+public class StubChartProviderFull extends StubChartProvider {
+
+    /**
+     * Name of a second String descriptor. It will return the String of the stub
+     * object, prefixed with "alt_"
+     */
+    public static final String SECOND_STRING_DESCRIPTOR = "String2";
+    /**
+     * Name of a duration descriptor. It will return the Integer field of the
+     * stub object
+     */
+    public static final String DURATION_DESCRIPTOR = "Duration";
+    /**
+     * Name of a second duration descriptor. It will return the Integer field of
+     * the stub object, plus 10
+     */
+    public static final String SECOND_DURATION_DESCRIPTOR = "Duration2";
+    /**
+     * Name of a timestamp descriptor. It will return the Long field of the stub
+     * object
+     */
+    public static final String TIMESTAMP_DESCRIPTOR = "Timestamp";
+    /**
+     * Name of a second timestamp descriptor. It will return the Long field of
+     * the stub object, plus 1000
+     */
+    public static final String SECOND_TIMESTAMP_DESCRIPTOR = "Timestamp2";
+    private @Nullable List<IDataChartDescriptor<StubObject, ?>> fDescriptors = null;
+
+    @Override
+    public Collection<IDataChartDescriptor<StubObject, ?>> getDataDescriptors() {
+        List<IDataChartDescriptor<StubObject, ?>> descriptors = fDescriptors;
+        if (descriptors == null) {
+            descriptors = new ArrayList<>(super.getDataDescriptors());
+            descriptors.add(new DataChartStringDescriptor<>(SECOND_STRING_DESCRIPTOR, new IStringResolver<StubObject>() {
+
+                @Override
+                public @NonNull Function<StubObject, @Nullable String> getMapper() {
+                    return o -> "alt_" + o.getString();
+                }
+            }));
+            descriptors.add(new DataChartDurationDescriptor<>(DURATION_DESCRIPTOR, new INumericalResolver<StubObject, @NonNull Integer>() {
+
+                @Override
+                public @NonNull Function<StubObject, @Nullable Integer> getMapper() {
+                    return o -> o.getInt();
+                }
+
+                @Override
+                public @NonNull Comparator<@NonNull Integer> getComparator() {
+                    return NonNullUtils.checkNotNull(Comparator.naturalOrder());
+                }
+
+                @Override
+                public Integer getMinValue() {
+                    return Integer.MIN_VALUE;
+                }
+
+                @Override
+                public Integer getMaxValue() {
+                    return Integer.MAX_VALUE;
+                }
+
+                @Override
+                public Integer getZeroValue() {
+                    return 0;
+                }
+            }));
+            descriptors.add(new DataChartDurationDescriptor<>(SECOND_DURATION_DESCRIPTOR, new INumericalResolver<StubObject, @NonNull Integer>() {
+
+                @Override
+                public @NonNull Function<StubObject, @Nullable Integer> getMapper() {
+                    return o -> o.getInt() + 10;
+                }
+
+                @Override
+                public @NonNull Comparator<@NonNull Integer> getComparator() {
+                    return NonNullUtils.checkNotNull(Comparator.naturalOrder());
+                }
+
+                @Override
+                public Integer getMinValue() {
+                    return Integer.MIN_VALUE;
+                }
+
+                @Override
+                public Integer getMaxValue() {
+                    return Integer.MAX_VALUE;
+                }
+
+                @Override
+                public Integer getZeroValue() {
+                    return 0;
+                }
+            }));
+            descriptors.add(new DataChartTimestampDescriptor<>(TIMESTAMP_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
+
+                @Override
+                public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+                    return o -> o.getLong();
+                }
+            }));
+            descriptors.add(new DataChartTimestampDescriptor<>(SECOND_TIMESTAMP_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
+
+                @Override
+                public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+                    return o -> o.getLong() + 1000;
+                }
+            }));
+            fDescriptors = descriptors;
+        }
+        return descriptors;
+    }
+
+}
This page took 0.028273 seconds and 5 git commands to generate.