1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
19 import java
.util
.NoSuchElementException
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
25 * An iterator for time events. Events from the zoomed event list override any
26 * events from the underlying event list. Gaps in the zoomed event list will not
27 * allow the underlying events to be included in the iterator, e.g. no
28 * underlying event will be included between the start of the first zoomed event
29 * and the end of the last zoomed event.
33 * zoomed list [D][E][F] [G]
34 * event list [ A ] [ B ][C]
35 * iterator [A][D][E][F] [G][B][C]
38 public class EventIterator
implements Iterator
<@NonNull ITimeEvent
> {
40 private final long fStartTime
;
41 private final long fEndTime
;
42 private List
<ITimeEvent
> fEventList
;
43 private List
<ITimeEvent
> fZoomedEventList
;
44 private long fZoomedStartTime
;
45 private long fZoomedEndTime
;
46 private int fIndex
= 0;
47 private int fZoomedIndex
= 0;
48 private ITimeEvent fNext
= null;
49 private ITimeEvent fSplitNext
= null;
50 private ITimeEvent fZoomedNext
= null;
53 * Basic constructor, with start time and end times equal to the lowest and
54 * highest values possible, respectively.
57 * The list on which this iterator will iterate
58 * @param zoomedEventList
61 public EventIterator(List
<ITimeEvent
> eventList
, List
<ITimeEvent
> zoomedEventList
) {
62 this(eventList
, zoomedEventList
, Long
.MIN_VALUE
, Long
.MAX_VALUE
);
66 * Complete constructor, where we specify start and end times.
69 * The list on which this iterator will iterate
70 * @param zoomedEventList
77 public EventIterator(List
<ITimeEvent
> eventList
,
78 List
<ITimeEvent
> zoomedEventList
, long startTime
, long endTime
) {
79 fEventList
= eventList
;
80 fZoomedEventList
= zoomedEventList
;
81 if (zoomedEventList
!= null && zoomedEventList
.size() > 0) {
82 fZoomedStartTime
= zoomedEventList
.get(0).getTime();
83 ITimeEvent lastEvent
= zoomedEventList
.get(zoomedEventList
.size() - 1);
84 fZoomedEndTime
= lastEvent
.getTime() + lastEvent
.getDuration();
86 fZoomedStartTime
= Long
.MAX_VALUE
;
87 fZoomedEndTime
= Long
.MIN_VALUE
;
89 fStartTime
= startTime
;
94 public boolean hasNext() {
95 if (fNext
== null && fEventList
!= null) {
96 while (fIndex
< fEventList
.size()) {
97 ITimeEvent event
= fEventList
.get(fIndex
++);
98 if (event
.getTime() + event
.getDuration() >= fStartTime
&& event
.getTime() <= fEndTime
&&
99 (event
.getTime() < fZoomedStartTime
|| event
.getTime() + event
.getDuration() > fZoomedEndTime
)) {
100 // the event is visible and is not completely hidden by the zoomed events
102 if (event
.getTime() < fZoomedEndTime
&& event
.getTime() + event
.getDuration() > fZoomedStartTime
) {
103 // the event is partially hidden by the zoomed events and must be split
105 if (event
.getTime() + event
.getDuration() > fZoomedEndTime
&& fZoomedEndTime
< fEndTime
) {
106 // the end of the event is partially hidden by the zoomed events and is visible
107 fNext
= event
.splitAfter(fZoomedEndTime
);
109 if (event
.getTime() < fZoomedStartTime
&& fZoomedStartTime
> fStartTime
) {
110 // the start of the event is partially hidden by the zoomed events and is visible
112 fNext
= event
.splitBefore(fZoomedStartTime
);
125 if (fZoomedNext
== null && fZoomedEventList
!= null) {
126 while (fZoomedIndex
< fZoomedEventList
.size()) {
127 ITimeEvent event
= fZoomedEventList
.get(fZoomedIndex
++);
128 if (event
.getTime() + event
.getDuration() >= fStartTime
&& event
.getTime() <= fEndTime
) {
129 // the zoomed event is visible
134 if (fZoomedNext
== null) {
135 fZoomedEventList
= null;
139 return fNext
!= null || fZoomedNext
!= null;
143 public ITimeEvent
next() {
145 if (fZoomedNext
!= null && (fNext
== null || fZoomedNext
.getTime() <= fNext
.getTime())) {
146 ITimeEvent event
= checkNotNull(fZoomedNext
);
150 ITimeEvent event
= checkNotNull(fNext
);
155 throw new NoSuchElementException();
159 public void remove() {
160 throw new UnsupportedOperationException();
This page took 0.04571 seconds and 5 git commands to generate.