~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
 
 * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
 
2
 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
3
3
 *
4
4
 * All rights reserved. This program and the accompanying materials are
5
5
 * made available under the terms of the Eclipse Public License v1.0 which
14
14
package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
15
15
 
16
16
import java.util.ArrayList;
 
17
import java.util.Arrays;
 
18
import java.util.Comparator;
17
19
import java.util.Iterator;
18
20
import java.util.List;
 
21
import java.util.concurrent.CopyOnWriteArrayList;
19
22
 
20
23
/**
21
24
 * An entry for use in the time graph views
25
28
public class TimeGraphEntry implements ITimeGraphEntry {
26
29
 
27
30
    /** Entry's parent */
28
 
    private TimeGraphEntry fParent = null;
 
31
    private ITimeGraphEntry fParent = null;
29
32
 
30
33
    /** List of child entries */
31
 
    private final List<TimeGraphEntry> fChildren = new ArrayList<TimeGraphEntry>();
 
34
    private final List<ITimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
32
35
 
33
36
    /** Name of this entry (text to show) */
34
37
    private String fName;
35
38
    private long fStartTime = -1;
36
39
    private long fEndTime = -1;
37
 
    private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();
38
 
    private List<ITimeEvent> fZoomedEventList = new ArrayList<ITimeEvent>();
 
40
    private List<ITimeEvent> fEventList = new ArrayList<>();
 
41
    private List<ITimeEvent> fZoomedEventList = new ArrayList<>();
 
42
    private Comparator<ITimeGraphEntry> fComparator;
39
43
 
40
44
    /**
41
45
     * Constructor
67
71
     *
68
72
     * @param entry The new parent entry
69
73
     */
 
74
    /*
 
75
     * TODO: This method can be removed in the next major API version.
 
76
     */
70
77
    protected void setParent(TimeGraphEntry entry) {
71
78
        fParent = entry;
72
79
    }
73
80
 
 
81
    /**
 
82
     * Sets the entry's parent
 
83
     *
 
84
     * @param entry The new parent entry
 
85
     * @since 3.1
 
86
     */
 
87
    /*
 
88
     * TODO: This method should be added to the interface in the next major API version.
 
89
     */
 
90
    protected void setParent(ITimeGraphEntry entry) {
 
91
        fParent = entry;
 
92
    }
 
93
 
74
94
    @Override
75
 
    public boolean hasChildren() {
 
95
    public synchronized boolean hasChildren() {
76
96
        return fChildren.size() > 0;
77
97
    }
78
98
 
79
99
    @Override
80
 
    public List<TimeGraphEntry> getChildren() {
 
100
    public synchronized List<? extends ITimeGraphEntry> getChildren() {
81
101
        return fChildren;
82
102
    }
83
103
 
106
126
        return fEndTime;
107
127
    }
108
128
 
 
129
    /**
 
130
     * Updates the end time
 
131
     *
 
132
     * @param endTime
 
133
     *            the end time
 
134
     *
 
135
     * @since 3.0
 
136
     */
 
137
    public void updateEndTime(long endTime) {
 
138
        fEndTime = Math.max(endTime, fEndTime);
 
139
    }
 
140
 
109
141
    @Override
110
142
    public boolean hasTimeEvents() {
111
143
        return true;
129
161
 
130
162
    /**
131
163
     * Add an event to this entry's event list. If necessary, update the start
132
 
     * and end time of the entry.
 
164
     * and end time of the entry. If the event list's last event starts at the
 
165
     * same time as the event to add, it is replaced by the new event.
133
166
     *
134
167
     * @param event
135
 
     *            The time event
 
168
     *            The time event to add
136
169
     */
137
170
    public void addEvent(ITimeEvent event) {
138
171
        long start = event.getTime();
139
172
        long end = start + event.getDuration();
140
173
        synchronized (fEventList) {
141
 
            fEventList.add(event);
 
174
            int lastIndex = fEventList.size() - 1;
 
175
            if (lastIndex >= 0 && fEventList.get(lastIndex).getTime() == event.getTime()) {
 
176
                fEventList.set(lastIndex, event);
 
177
            } else {
 
178
                fEventList.add(event);
 
179
            }
142
180
            if (fStartTime == -1 || start < fStartTime) {
143
181
                fStartTime = start;
144
182
            }
156
194
     */
157
195
    public void setEventList(List<ITimeEvent> eventList) {
158
196
        if (eventList != null) {
159
 
            fEventList = new ArrayList<ITimeEvent>(eventList);
 
197
            fEventList = new ArrayList<>(eventList);
160
198
        } else {
161
 
            fEventList = new ArrayList<ITimeEvent>();
 
199
            fEventList = new ArrayList<>();
162
200
        }
163
201
    }
164
202
 
170
208
     */
171
209
    public void setZoomedEventList(List<ITimeEvent> eventList) {
172
210
        if (eventList != null) {
173
 
            fZoomedEventList = new ArrayList<ITimeEvent>(eventList);
 
211
            fZoomedEventList = new ArrayList<>(eventList);
174
212
        } else {
175
 
            fZoomedEventList = new ArrayList<ITimeEvent>();
 
213
            fZoomedEventList = new ArrayList<>();
176
214
        }
177
215
    }
178
216
 
182
220
     * @param child
183
221
     *            The child entry
184
222
     */
185
 
    public void addChild(TimeGraphEntry child) {
186
 
        child.fParent = this;
187
 
        fChildren.add(child);
 
223
    /*
 
224
     * TODO: This method can be removed in the next major API version.
 
225
     */
 
226
    public synchronized void addChild(TimeGraphEntry child) {
 
227
        addChild((ITimeGraphEntry) child);
 
228
    }
 
229
 
 
230
    /**
 
231
     * Add a child entry to this one. If a comparator was previously set with
 
232
     * {@link #sortChildren(Comparator)}, the entry will be inserted in its
 
233
     * sort-order position. Otherwise it will be added to the end of the list.
 
234
     *
 
235
     * @param child
 
236
     *            The child entry
 
237
     * @since 3.1
 
238
     */
 
239
    public synchronized void addChild(ITimeGraphEntry child) {
 
240
        /*
 
241
         * TODO: Use setParent() once it is added to the interface.
 
242
         */
 
243
        if (child instanceof TimeGraphEntry) {
 
244
            ((TimeGraphEntry) child).fParent = this;
 
245
        }
 
246
        if (fComparator == null) {
 
247
            fChildren.add(child);
 
248
        } else {
 
249
            int i;
 
250
            for (i = 0; i < fChildren.size(); i++) {
 
251
                ITimeGraphEntry entry = fChildren.get(i);
 
252
                if (fComparator.compare(child, entry) < 0) {
 
253
                    break;
 
254
                }
 
255
            }
 
256
            fChildren.add(i, child);
 
257
        }
 
258
    }
 
259
 
 
260
    /**
 
261
     * Add a child entry to this one at the specified position
 
262
     *
 
263
     * @param index
 
264
     *            Index at which the specified entry is to be inserted
 
265
     * @param child
 
266
     *            The child entry
 
267
     * @since 3.1
 
268
     */
 
269
    public synchronized void addChild(int index, ITimeGraphEntry child) {
 
270
        /*
 
271
         * TODO: Use setParent() once it is added to the interface.
 
272
         */
 
273
        if (child instanceof TimeGraphEntry) {
 
274
            ((TimeGraphEntry) child).fParent = this;
 
275
        }
 
276
        fChildren.add(index, child);
 
277
    }
 
278
 
 
279
    /**
 
280
     * Sort the children of this entry using the provided comparator. Subsequent
 
281
     * calls to {@link #addChild(ITimeGraphEntry)} will use this comparator to
 
282
     * maintain the sort order.
 
283
     *
 
284
     * @param comparator
 
285
     *            The entry comparator
 
286
     * @since 3.1
 
287
     */
 
288
    public synchronized void sortChildren(Comparator<ITimeGraphEntry> comparator) {
 
289
        fComparator = comparator;
 
290
        if (comparator == null) {
 
291
            return;
 
292
        }
 
293
        ITimeGraphEntry[] array = fChildren.toArray(new ITimeGraphEntry[0]);
 
294
        Arrays.sort(array, comparator);
 
295
        fChildren.clear();
 
296
        fChildren.addAll(Arrays.asList(array));
188
297
    }
189
298
 
190
299
    @Override