1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.chart
.core
.tests
.stubs
;
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
;
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
;
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.
34 * @author Geneviève Bastien
37 public class StubChartProviderFull
extends StubChartProvider
{
40 * Name of a second String descriptor. It will return the String of the stub
41 * object, prefixed with "alt_"
43 public static final String SECOND_STRING_DESCRIPTOR
= "String2";
45 * Name of a duration descriptor. It will return the Integer field of the
48 public static final String DURATION_DESCRIPTOR
= "Duration";
50 * Name of a second duration descriptor. It will return the Integer field of
51 * the stub object, plus 10
53 public static final String SECOND_DURATION_DESCRIPTOR
= "Duration2";
55 * Name of a timestamp descriptor. It will return the Long field of the stub
58 public static final String TIMESTAMP_DESCRIPTOR
= "Timestamp";
60 * Name of a second timestamp descriptor. It will return the Long field of
61 * the stub object, plus 1000
63 public static final String SECOND_TIMESTAMP_DESCRIPTOR
= "Timestamp2";
64 private @Nullable List
<IDataChartDescriptor
<StubObject
, ?
>> fDescriptors
= null;
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
>() {
74 public @NonNull Function
<StubObject
, @Nullable String
> getMapper() {
75 return o
-> "alt_" + o
.getString();
78 descriptors
.add(new DataChartDurationDescriptor
<>(DURATION_DESCRIPTOR
, new INumericalResolver
<StubObject
, @NonNull Integer
>() {
81 public @NonNull Function
<StubObject
, @Nullable Integer
> getMapper() {
82 return o
-> o
.getInt();
86 public @NonNull Comparator
<@NonNull Integer
> getComparator() {
87 return NonNullUtils
.checkNotNull(Comparator
.naturalOrder());
91 public Integer
getMinValue() {
92 return Integer
.MIN_VALUE
;
96 public Integer
getMaxValue() {
97 return Integer
.MAX_VALUE
;
101 public Integer
getZeroValue() {
105 descriptors
.add(new DataChartDurationDescriptor
<>(SECOND_DURATION_DESCRIPTOR
, new INumericalResolver
<StubObject
, @NonNull Integer
>() {
108 public @NonNull Function
<StubObject
, @Nullable Integer
> getMapper() {
109 return o
-> o
.getInt() + 10;
113 public @NonNull Comparator
<@NonNull Integer
> getComparator() {
114 return NonNullUtils
.checkNotNull(Comparator
.naturalOrder());
118 public Integer
getMinValue() {
119 return Integer
.MIN_VALUE
;
123 public Integer
getMaxValue() {
124 return Integer
.MAX_VALUE
;
128 public Integer
getZeroValue() {
132 descriptors
.add(new DataChartTimestampDescriptor
<>(TIMESTAMP_DESCRIPTOR
, new AbstractLongResolver
<StubObject
>() {
135 public @NonNull Function
<StubObject
, @Nullable Long
> getMapper() {
136 return o
-> o
.getLong();
139 descriptors
.add(new DataChartTimestampDescriptor
<>(SECOND_TIMESTAMP_DESCRIPTOR
, new AbstractLongResolver
<StubObject
>() {
142 public @NonNull Function
<StubObject
, @Nullable Long
> getMapper() {
143 return o
-> o
.getLong() + 1000;
146 fDescriptors
= descriptors
;