1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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 java
.util
.Iterator
;
16 import java
.util
.List
;
17 import java
.util
.NoSuchElementException
;
21 * An iterator for time events. Events from the zoomed event list override any
22 * events from the underlying event list.
24 public class EventIterator
implements Iterator
<ITimeEvent
> {
26 private final long fStartTime
;
27 private final long fEndTime
;
28 private List
<ITimeEvent
> fEventList
;
29 private List
<ITimeEvent
> fZoomedEventList
;
30 private long fZoomedStartTime
;
31 private long fZoomedEndTime
;
32 private int fIndex
= 0;
33 private int fZoomedIndex
= 0;
34 private ITimeEvent fNext
= null;
35 private ITimeEvent fSplitNext
= null;
36 private ITimeEvent fZoomedNext
= null;
39 * Basic constructor, with start time and end times equal to the lowest and
40 * highest values possible, respectively.
43 * The list on which this iterator will iterate
44 * @param zoomedEventList
47 public EventIterator(List
<ITimeEvent
> eventList
, List
<ITimeEvent
> zoomedEventList
) {
48 this(eventList
, zoomedEventList
, Long
.MIN_VALUE
, Long
.MAX_VALUE
);
52 * Complete constructor, where we specify start and end times.
55 * The list on which this iterator will iterate
56 * @param zoomedEventList
63 public EventIterator(List
<ITimeEvent
> eventList
,
64 List
<ITimeEvent
> zoomedEventList
, long startTime
, long endTime
) {
65 fEventList
= eventList
;
66 fZoomedEventList
= zoomedEventList
;
67 if (zoomedEventList
!= null && zoomedEventList
.size() > 0) {
68 fZoomedStartTime
= zoomedEventList
.get(0).getTime();
69 ITimeEvent lastEvent
= zoomedEventList
.get(zoomedEventList
.size() - 1);
70 fZoomedEndTime
= lastEvent
.getTime() + lastEvent
.getDuration();
72 fZoomedStartTime
= Long
.MAX_VALUE
;
73 fZoomedEndTime
= Long
.MIN_VALUE
;
75 fStartTime
= startTime
;
80 public boolean hasNext() {
81 if (fNext
== null && fEventList
!= null) {
82 while (fIndex
< fEventList
.size()) {
83 ITimeEvent event
= fEventList
.get(fIndex
++);
84 if (event
.getTime() + event
.getDuration() >= fStartTime
&& event
.getTime() <= fEndTime
&&
85 (event
.getTime() < fZoomedStartTime
|| event
.getTime() + event
.getDuration() > fZoomedEndTime
)) {
86 // the event is visible and is not completely hidden by the zoomed events
88 if (event
.getTime() < fZoomedEndTime
&& event
.getTime() + event
.getDuration() > fZoomedStartTime
) {
89 // the event is partially hidden by the zoomed events and must be split
91 if (event
.getTime() + event
.getDuration() > fZoomedEndTime
&& fZoomedEndTime
< fEndTime
) {
92 // the end of the event is partially hidden by the zoomed events and is visible
93 fNext
= event
.splitAfter(fZoomedEndTime
);
95 if (event
.getTime() < fZoomedStartTime
&& fZoomedStartTime
> fStartTime
) {
96 // the start of the event is partially hidden by the zoomed events and is visible
98 fNext
= event
.splitBefore(fZoomedStartTime
);
111 if (fZoomedNext
== null && fZoomedEventList
!= null) {
112 while (fZoomedIndex
< fZoomedEventList
.size()) {
113 ITimeEvent event
= fZoomedEventList
.get(fZoomedIndex
++);
114 if (event
.getTime() + event
.getDuration() >= fStartTime
&& event
.getTime() <= fEndTime
) {
115 // the zoomed event is visible
120 if (fZoomedNext
== null) {
121 fZoomedEventList
= null;
125 return fNext
!= null || fZoomedNext
!= null;
129 public ITimeEvent
next() {
131 if (fZoomedNext
!= null && (fNext
== null || fZoomedNext
.getTime() <= fNext
.getTime())) {
132 ITimeEvent event
= fZoomedNext
;
136 ITimeEvent event
= fNext
;
141 throw new NoSuchElementException();
145 public void remove() {
146 throw new UnsupportedOperationException();
This page took 0.073631 seconds and 6 git commands to generate.