a3139b20046bd15e3d503ccf7b43b9b911e56ba0
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.chart.core.tests / stubs / org / eclipse / tracecompass / tmf / chart / core / tests / stubs / StubChartProviderFull.java
1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.tmf.chart.core.tests.stubs;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Comparator;
15 import java.util.List;
16 import java.util.function.Function;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.tracecompass.common.core.NonNullUtils;
22 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartDurationDescriptor;
23 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartStringDescriptor;
24 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartTimestampDescriptor;
25 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
26 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
27 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
28 import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.IStringResolver;
29
30 /**
31 * A chart provider that returns a few descriptors of each types. It allows to
32 * test the interactions of many types of descriptors, similar and different.
33 *
34 * @author Geneviève Bastien
35 */
36 @NonNullByDefault
37 public class StubChartProviderFull extends StubChartProvider {
38
39 /**
40 * Name of a second String descriptor. It will return the String of the stub
41 * object, prefixed with "alt_"
42 */
43 public static final String SECOND_STRING_DESCRIPTOR = "String2";
44 /**
45 * Name of a duration descriptor. It will return the Integer field of the
46 * stub object
47 */
48 public static final String DURATION_DESCRIPTOR = "Duration";
49 /**
50 * Name of a second duration descriptor. It will return the Integer field of
51 * the stub object, plus 10
52 */
53 public static final String SECOND_DURATION_DESCRIPTOR = "Duration2";
54 /**
55 * Name of a timestamp descriptor. It will return the Long field of the stub
56 * object
57 */
58 public static final String TIMESTAMP_DESCRIPTOR = "Timestamp";
59 /**
60 * Name of a second timestamp descriptor. It will return the Long field of
61 * the stub object, plus 1000
62 */
63 public static final String SECOND_TIMESTAMP_DESCRIPTOR = "Timestamp2";
64 private @Nullable List<IDataChartDescriptor<StubObject, ?>> fDescriptors = null;
65
66 @Override
67 public Collection<IDataChartDescriptor<StubObject, ?>> getDataDescriptors() {
68 List<IDataChartDescriptor<StubObject, ?>> descriptors = fDescriptors;
69 if (descriptors == null) {
70 descriptors = new ArrayList<>(super.getDataDescriptors());
71 descriptors.add(new DataChartStringDescriptor<>(SECOND_STRING_DESCRIPTOR, new IStringResolver<StubObject>() {
72
73 @Override
74 public @NonNull Function<StubObject, @Nullable String> getMapper() {
75 return o -> "alt_" + o.getString();
76 }
77 }));
78 descriptors.add(new DataChartDurationDescriptor<>(DURATION_DESCRIPTOR, new INumericalResolver<StubObject, @NonNull Integer>() {
79
80 @Override
81 public @NonNull Function<StubObject, @Nullable Integer> getMapper() {
82 return o -> o.getInt();
83 }
84
85 @Override
86 public @NonNull Comparator<@NonNull Integer> getComparator() {
87 return NonNullUtils.checkNotNull(Comparator.naturalOrder());
88 }
89
90 @Override
91 public Integer getMinValue() {
92 return Integer.MIN_VALUE;
93 }
94
95 @Override
96 public Integer getMaxValue() {
97 return Integer.MAX_VALUE;
98 }
99
100 @Override
101 public Integer getZeroValue() {
102 return 0;
103 }
104 }));
105 descriptors.add(new DataChartDurationDescriptor<>(SECOND_DURATION_DESCRIPTOR, new INumericalResolver<StubObject, @NonNull Integer>() {
106
107 @Override
108 public @NonNull Function<StubObject, @Nullable Integer> getMapper() {
109 return o -> o.getInt() + 10;
110 }
111
112 @Override
113 public @NonNull Comparator<@NonNull Integer> getComparator() {
114 return NonNullUtils.checkNotNull(Comparator.naturalOrder());
115 }
116
117 @Override
118 public Integer getMinValue() {
119 return Integer.MIN_VALUE;
120 }
121
122 @Override
123 public Integer getMaxValue() {
124 return Integer.MAX_VALUE;
125 }
126
127 @Override
128 public Integer getZeroValue() {
129 return 0;
130 }
131 }));
132 descriptors.add(new DataChartTimestampDescriptor<>(TIMESTAMP_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
133
134 @Override
135 public @NonNull Function<StubObject, @Nullable Long> getMapper() {
136 return o -> o.getLong();
137 }
138 }));
139 descriptors.add(new DataChartTimestampDescriptor<>(SECOND_TIMESTAMP_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
140
141 @Override
142 public @NonNull Function<StubObject, @Nullable Long> getMapper() {
143 return o -> o.getLong() + 1000;
144 }
145 }));
146 fDescriptors = descriptors;
147 }
148 return descriptors;
149 }
150
151 }
This page took 0.034254 seconds and 5 git commands to generate.