tmf: Make TmfEventField's equals() also check the sub-fields
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeGraphEntry.java
CommitLineData
4999a196 1/*******************************************************************************
1cf25311 2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
4999a196
GB
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 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Geneviève Bastien - Move code to provide base classes for time graph view
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
15
16import java.util.ArrayList;
17import java.util.Iterator;
18import java.util.List;
1cf25311 19import java.util.concurrent.CopyOnWriteArrayList;
4999a196 20
4999a196
GB
21/**
22 * An entry for use in the time graph views
23 *
24 * @since 2.1
25 */
26public class TimeGraphEntry implements ITimeGraphEntry {
27
4999a196
GB
28 /** Entry's parent */
29 private TimeGraphEntry fParent = null;
30
31 /** List of child entries */
1cf25311 32 private final List<TimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
4999a196
GB
33
34 /** Name of this entry (text to show) */
35 private String fName;
36 private long fStartTime = -1;
37 private long fEndTime = -1;
507b1336
AM
38 private List<ITimeEvent> fEventList = new ArrayList<>();
39 private List<ITimeEvent> fZoomedEventList = new ArrayList<>();
4999a196
GB
40
41 /**
42 * Constructor
43 *
4999a196 44 * @param name
1d46dc38 45 * The name of this entry
4999a196 46 * @param startTime
1d46dc38 47 * The start time of this entry
4999a196 48 * @param endTime
1d46dc38 49 * The end time of this entry
4999a196 50 */
1d46dc38 51 public TimeGraphEntry(String name, long startTime, long endTime) {
4999a196
GB
52 fName = name;
53 fStartTime = startTime;
54 fEndTime = endTime;
55 }
56
57 // ---------------------------------------------
58 // Getters and setters
59 // ---------------------------------------------
60
61 @Override
62 public ITimeGraphEntry getParent() {
63 return fParent;
64 }
65
66 /**
67 * Sets the entry's parent
68 *
69 * @param entry The new parent entry
70 */
71 protected void setParent(TimeGraphEntry entry) {
72 fParent = entry;
73 }
74
75 @Override
76 public boolean hasChildren() {
77 return fChildren.size() > 0;
78 }
79
80 @Override
81 public List<TimeGraphEntry> getChildren() {
82 return fChildren;
83 }
84
85 @Override
86 public String getName() {
87 return fName;
88 }
89
90 /**
91 * Update the entry name
92 *
93 * @param name
94 * the updated entry name
95 */
96 public void setName(String name) {
97 fName = name;
98 }
99
100 @Override
101 public long getStartTime() {
102 return fStartTime;
103 }
104
105 @Override
106 public long getEndTime() {
107 return fEndTime;
108 }
109
1cf25311
PT
110 /**
111 * Updates the end time
112 *
113 * @param endTime
114 * the end time
115 *
116 * @since 3.0
117 */
118 public void updateEndTime(long endTime) {
119 fEndTime = Math.max(endTime, fEndTime);
120 }
121
4999a196
GB
122 @Override
123 public boolean hasTimeEvents() {
124 return true;
125 }
126
127 @Override
128 public Iterator<ITimeEvent> getTimeEventsIterator() {
129 if (hasTimeEvents()) {
130 return new EventIterator(fEventList, fZoomedEventList);
131 }
132 return null;
133 }
134
135 @Override
136 public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
137 if (!hasTimeEvents()) {
138 return null;
139 }
140 return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);
141 }
142
143 /**
1d46dc38 144 * Add an event to this entry's event list. If necessary, update the start
1cf25311
PT
145 * and end time of the entry. If the event list's last event starts at the
146 * same time as the event to add, it is replaced by the new event.
4999a196
GB
147 *
148 * @param event
1cf25311 149 * The time event to add
4999a196
GB
150 */
151 public void addEvent(ITimeEvent event) {
152 long start = event.getTime();
153 long end = start + event.getDuration();
154 synchronized (fEventList) {
1cf25311
PT
155 int lastIndex = fEventList.size() - 1;
156 if (lastIndex >= 0 && fEventList.get(lastIndex).getTime() == event.getTime()) {
157 fEventList.set(lastIndex, event);
158 } else {
159 fEventList.add(event);
160 }
4999a196
GB
161 if (fStartTime == -1 || start < fStartTime) {
162 fStartTime = start;
163 }
164 if (fEndTime == -1 || end > fEndTime) {
165 fEndTime = end;
166 }
167 }
168 }
169
170 /**
171 * Set the general event list of this entry.
172 *
4999a196
GB
173 * @param eventList
174 * The list of time events
175 */
176 public void setEventList(List<ITimeEvent> eventList) {
3ce8c834 177 if (eventList != null) {
507b1336 178 fEventList = new ArrayList<>(eventList);
3ce8c834 179 } else {
507b1336 180 fEventList = new ArrayList<>();
3ce8c834 181 }
4999a196
GB
182 }
183
184 /**
185 * Set the zoomed event list of this entry.
186 *
4999a196
GB
187 * @param eventList
188 * The list of time events
189 */
190 public void setZoomedEventList(List<ITimeEvent> eventList) {
3ce8c834 191 if (eventList != null) {
507b1336 192 fZoomedEventList = new ArrayList<>(eventList);
3ce8c834 193 } else {
507b1336 194 fZoomedEventList = new ArrayList<>();
3ce8c834 195 }
4999a196
GB
196 }
197
198 /**
1d46dc38 199 * Add a child entry to this one
4999a196
GB
200 *
201 * @param child
202 * The child entry
203 */
204 public void addChild(TimeGraphEntry child) {
205 child.fParent = this;
206 fChildren.add(child);
207 }
208
b1b156f3
PT
209 @Override
210 public String toString() {
211 return getClass().getSimpleName() + '(' + fName + ')';
212 }
213
4999a196 214}
This page took 0.043705 seconds and 5 git commands to generate.