/
TimeEvent.java
231 lines (203 loc) · 6.64 KB
/
TimeEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*******************************************************************************
* Copyright (c) 2012, 2021 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Tasse - Initial API and implementation
* Geneviève Bastien - Added the fValue parameter to avoid subclassing
*******************************************************************************/
package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.model.CoreFilterProperty;
import org.eclipse.tracecompass.tmf.core.model.ITimeElement;
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState;
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState;
import com.google.common.collect.Multimap;
/**
* Generic TimeEvent implementation
*
* @version 1.0
* @author Patrick Tasse
*/
public class TimeEvent implements ITimeEvent {
/** TimeGraphEntry matching this time event */
protected ITimeGraphEntry fEntry;
private final ITimeElement fModel;
/** Beginning timestamp of this time event */
protected long fTime;
/** Duration of this time event */
protected long fDuration;
/**
* Default value when no other value present
*/
private static final int NOVALUE = Integer.MIN_VALUE;
/**
* Standard constructor
*
* @param entry
* The entry matching this event
* @param time
* The timestamp of this event
* @param duration
* The duration of the event
*/
public TimeEvent(ITimeGraphEntry entry, long time, long duration) {
this(entry, time, duration, NOVALUE);
}
/**
* Constructor
*
* @param entry
* The entry to which this time event is assigned
* @param time
* The timestamp of this event
* @param duration
* The duration of this event
* @param value
* The status assigned to the event
*/
public TimeEvent(ITimeGraphEntry entry, long time, long duration, int value) {
this(entry, new TimeGraphState(time, duration, value));
}
/**
* Constructor
*
* @param entry
* The entry to which this time event is assigned
* @param time
* The timestamp of this event
* @param duration
* The duration of this event
* @param value
* The status assigned to the event
* @param activeProperties
* The active properties of the event represented by a bitmask
* value. Each bit represents a property. Available properties
* can be found in {@link CoreFilterProperty}.
* @since 4.0
*/
public TimeEvent(ITimeGraphEntry entry, long time, long duration, int value, int activeProperties) {
this(entry, new TimeGraphState(time, duration, value));
fModel.setActiveProperties(activeProperties);
}
/**
* Constructor
*
* @param stateModel
* {@link ITimeGraphState} that represents this time event
* @param entry
* The entry to which this time event is assigned
* @since 5.2
*/
public TimeEvent(ITimeGraphEntry entry, ITimeElement stateModel) {
fEntry = entry;
fTime = stateModel.getStartTime();
fDuration = stateModel.getDuration();
fModel = stateModel;
}
/**
* Get this event's status
*
* @return The integer matching this status
*/
public int getValue() {
return fModel.getValue();
}
/**
* Return whether an event has a value
*
* @return true if the event has a value
*/
public boolean hasValue() {
return (getValue() != NOVALUE);
}
@Override
public ITimeGraphEntry getEntry() {
return fEntry;
}
@Override
public long getTime() {
return fModel.getStartTime();
}
@Override
public long getDuration() {
return fModel.getDuration();
}
/**
* Get the model associated with this time event
*
* @return Model
* @since 5.2
*/
public ITimeElement getModel() {
return fModel;
}
@Override
public ITimeEvent splitBefore(long splitTime) {
return (splitTime > fTime ?
new TimeEvent(fEntry, fTime, Math.min(fDuration, splitTime - fTime), getValue(), getActiveProperties()) :
null);
}
@Override
public ITimeEvent splitAfter(long splitTime) {
return (splitTime < fTime + fDuration ?
new TimeEvent(fEntry, Math.max(fTime, splitTime), fDuration - Math.max(0, splitTime - fTime),
getValue(), getActiveProperties()) :
null);
}
@Override
public int hashCode() {
return Objects.hash(fEntry, fTime, fDuration, getValue(), getActiveProperties(), fModel.getStyle());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
TimeEvent other = (TimeEvent) obj;
return Objects.equals(fEntry, other.getEntry()) &&
Objects.equals(fTime, other.getTime()) &&
Objects.equals(fDuration, other.getDuration()) &&
Objects.equals(getValue(), other.getValue()) &&
Objects.equals(getActiveProperties(), other.getActiveProperties()) &&
Objects.equals(fModel.getStyle(), other.getModel().getStyle());
}
@Override
public String toString() {
return getClass().getSimpleName() + " start=" + fTime + " end=" + (fTime + fDuration) + " duration=" + fDuration + (hasValue() ? (" value=" + getValue()) : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
/**
* @since 4.0
*/
@Override
public int getActiveProperties() {
return fModel.getActiveProperties();
}
/**
* @since 4.0
*/
@Override
public void setActiveProperties(int activeProperties) {
fModel.setActiveProperties(activeProperties);
}
/**
* @since 4.1
*/
@Override
public @NonNull Multimap<@NonNull String, @NonNull Object> getMetadata() {
return fModel.getMetadata();
}
}