tmf: Switch tmf.core.tests to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeGraphEntry.java
CommitLineData
4999a196
GB
1/*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson, É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 * 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;
19
4999a196
GB
20/**
21 * An entry for use in the time graph views
22 *
23 * @since 2.1
24 */
25public class TimeGraphEntry implements ITimeGraphEntry {
26
4999a196
GB
27 /** Entry's parent */
28 private TimeGraphEntry fParent = null;
29
30 /** List of child entries */
31 private final List<TimeGraphEntry> fChildren = new ArrayList<TimeGraphEntry>();
32
33 /** Name of this entry (text to show) */
34 private String fName;
35 private long fStartTime = -1;
36 private long fEndTime = -1;
37 private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();
1d46dc38 38 private List<ITimeEvent> fZoomedEventList = new ArrayList<ITimeEvent>();
4999a196
GB
39
40 /**
41 * Constructor
42 *
4999a196 43 * @param name
1d46dc38 44 * The name of this entry
4999a196 45 * @param startTime
1d46dc38 46 * The start time of this entry
4999a196 47 * @param endTime
1d46dc38 48 * The end time of this entry
4999a196 49 */
1d46dc38 50 public TimeGraphEntry(String name, long startTime, long endTime) {
4999a196
GB
51 fName = name;
52 fStartTime = startTime;
53 fEndTime = endTime;
54 }
55
56 // ---------------------------------------------
57 // Getters and setters
58 // ---------------------------------------------
59
60 @Override
61 public ITimeGraphEntry getParent() {
62 return fParent;
63 }
64
65 /**
66 * Sets the entry's parent
67 *
68 * @param entry The new parent entry
69 */
70 protected void setParent(TimeGraphEntry entry) {
71 fParent = entry;
72 }
73
74 @Override
75 public boolean hasChildren() {
76 return fChildren.size() > 0;
77 }
78
79 @Override
80 public List<TimeGraphEntry> getChildren() {
81 return fChildren;
82 }
83
84 @Override
85 public String getName() {
86 return fName;
87 }
88
89 /**
90 * Update the entry name
91 *
92 * @param name
93 * the updated entry name
94 */
95 public void setName(String name) {
96 fName = name;
97 }
98
99 @Override
100 public long getStartTime() {
101 return fStartTime;
102 }
103
104 @Override
105 public long getEndTime() {
106 return fEndTime;
107 }
108
109 @Override
110 public boolean hasTimeEvents() {
111 return true;
112 }
113
114 @Override
115 public Iterator<ITimeEvent> getTimeEventsIterator() {
116 if (hasTimeEvents()) {
117 return new EventIterator(fEventList, fZoomedEventList);
118 }
119 return null;
120 }
121
122 @Override
123 public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
124 if (!hasTimeEvents()) {
125 return null;
126 }
127 return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);
128 }
129
130 /**
1d46dc38
PT
131 * Add an event to this entry's event list. If necessary, update the start
132 * and end time of the entry.
4999a196
GB
133 *
134 * @param event
135 * The time event
136 */
137 public void addEvent(ITimeEvent event) {
138 long start = event.getTime();
139 long end = start + event.getDuration();
140 synchronized (fEventList) {
141 fEventList.add(event);
142 if (fStartTime == -1 || start < fStartTime) {
143 fStartTime = start;
144 }
145 if (fEndTime == -1 || end > fEndTime) {
146 fEndTime = end;
147 }
148 }
149 }
150
151 /**
152 * Set the general event list of this entry.
153 *
4999a196
GB
154 * @param eventList
155 * The list of time events
156 */
157 public void setEventList(List<ITimeEvent> eventList) {
3ce8c834
PT
158 if (eventList != null) {
159 fEventList = new ArrayList<ITimeEvent>(eventList);
160 } else {
3ce8c834
PT
161 fEventList = new ArrayList<ITimeEvent>();
162 }
4999a196
GB
163 }
164
165 /**
166 * Set the zoomed event list of this entry.
167 *
4999a196
GB
168 * @param eventList
169 * The list of time events
170 */
171 public void setZoomedEventList(List<ITimeEvent> eventList) {
3ce8c834
PT
172 if (eventList != null) {
173 fZoomedEventList = new ArrayList<ITimeEvent>(eventList);
174 } else {
1d46dc38 175 fZoomedEventList = new ArrayList<ITimeEvent>();
3ce8c834 176 }
4999a196
GB
177 }
178
179 /**
1d46dc38 180 * Add a child entry to this one
4999a196
GB
181 *
182 * @param child
183 * The child entry
184 */
185 public void addChild(TimeGraphEntry child) {
186 child.fParent = this;
187 fChildren.add(child);
188 }
189
b1b156f3
PT
190 @Override
191 public String toString() {
192 return getClass().getSimpleName() + '(' + fName + ')';
193 }
194
4999a196 195}
This page took 0.041928 seconds and 5 git commands to generate.