Commit | Line | Data |
---|---|---|
4208b510 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir | |
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.internal.provisional.analysis.lami.core.aspect; | |
11 | ||
12 | import java.util.Comparator; | |
13 | ||
14 | import org.eclipse.jdt.annotation.Nullable; | |
15 | import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiTableEntry; | |
16 | ||
17 | /** | |
18 | * Aspect for LAMI table entries, which normally correspond to one "row" | |
19 | * of JSON output. | |
20 | * | |
21 | * It is not the same as a "Event aspect" used for trace events, but it is | |
22 | * heavily inspired from it. | |
23 | * | |
24 | * @author Alexandre Montplaisir | |
25 | * @see org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect | |
26 | */ | |
27 | public abstract class LamiTableEntryAspect { | |
28 | ||
29 | private final String fName; | |
30 | private final @Nullable String fUnits; | |
31 | ||
32 | /** | |
33 | * Constructor | |
34 | * | |
35 | * @param name | |
36 | * Aspect name, will be used as column name in the UI | |
37 | * @param units | |
38 | * The units of the value in this column | |
39 | */ | |
40 | protected LamiTableEntryAspect(String name, @Nullable String units) { | |
41 | fUnits = units; | |
42 | fName = name; | |
43 | } | |
44 | ||
45 | /** | |
46 | * Get the label of this aspect. | |
47 | * | |
48 | * The label is composed of the name followed by the units in parentheses. | |
49 | * | |
50 | * @return The label | |
51 | */ | |
52 | public String getLabel() { | |
53 | if (getUnits() == null) { | |
54 | return getName(); | |
55 | } | |
56 | return (getName() + " (" + getUnits() + ')'); //$NON-NLS-1$ | |
57 | } | |
58 | ||
59 | /** | |
60 | * Get the name of this aspect | |
61 | * | |
62 | * @return The name | |
63 | */ | |
64 | public String getName() { | |
65 | return fName; | |
66 | } | |
67 | ||
68 | /** | |
69 | * Get the units of this aspect. | |
70 | * | |
71 | * @return The units | |
72 | */ | |
73 | public @Nullable String getUnits() { | |
74 | return fUnits; | |
75 | } | |
76 | ||
77 | /** | |
78 | * Indicate if this aspect is numerical or not. This is used, among other | |
79 | * things, to align the text in the table cells. | |
80 | * | |
81 | * @return If this aspect is numerical or not | |
82 | */ | |
83 | public abstract boolean isContinuous(); | |
84 | ||
85 | ||
86 | /** | |
87 | * Indicate if this aspect represent timestamp or not. This can be used in chart | |
88 | * for axis labeling etc. | |
89 | * @return If this aspect represent a timestamp or not | |
90 | */ | |
91 | public abstract boolean isTimeStamp(); | |
92 | ||
93 | /** | |
94 | * Indicate if this aspect represent a time duration or not. This can be used in | |
95 | * chart for axis labeling etc. | |
96 | * @return If this aspect represent a time duration or not | |
97 | */ | |
98 | public boolean isTimeDuration() { | |
99 | return false; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Resolve this aspect for the given entry. | |
104 | * | |
105 | * @param entry | |
106 | * The table row | |
107 | * @return The string to display for the given cell | |
108 | */ | |
109 | public abstract @Nullable String resolveString(LamiTableEntry entry); | |
110 | ||
111 | /** | |
112 | * Resolve this aspect double representation for the given entry | |
113 | * | |
114 | * Returned value does not matter if isNumerical() is false. | |
115 | * | |
116 | * @param entry | |
117 | * The table row | |
118 | * @return The double value for the given cell | |
119 | */ | |
5b973e7c | 120 | public abstract @Nullable Number resolveNumber(LamiTableEntry entry); |
4208b510 AM |
121 | |
122 | /** | |
123 | * Get the comparator that should be used to compare this entry (or table | |
124 | * row) with the other rows in the table. This will be passed on to the | |
125 | * table's content provider. | |
126 | * | |
127 | * @return The entry comparator | |
128 | */ | |
129 | public abstract Comparator<LamiTableEntry> getComparator(); | |
130 | ||
131 | /** | |
132 | * Check if an aspect have the same properties. | |
133 | * | |
134 | * FIXME:Might want to compare the units if necessary. | |
135 | * | |
136 | * @param aspect | |
137 | * The aspect to compare to | |
138 | * @return If all aspect's properties are equal | |
139 | */ | |
140 | public boolean arePropertiesEqual(LamiTableEntryAspect aspect) { | |
141 | boolean timestamp = (this.isTimeStamp() == aspect.isTimeStamp()); | |
142 | boolean numerical = (this.isContinuous() == aspect.isContinuous()); | |
143 | return (timestamp && numerical); | |
144 | } | |
145 | } |