Refactor ITmfLocation and fix dependencies
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfIterator.java
CommitLineData
a3fc8213
AM
1package org.eclipse.linuxtools.tmf.core.ctfadaptor;
2
3import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
4import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
5import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
7
8public class CtfIterator extends CTFTraceReader implements ITmfContext,
9 Comparable<CtfIterator> {
10
11 private final CtfTmfTrace ctfTmfTrace;
12
13 private CtfLocation curLocation;
14 private long curRank;
15
16 /**
17 * Create a new CTF trace iterator, which initially points at the first
18 * event in the trace.
19 *
20 * @param trace
21 */
22 public CtfIterator(CtfTmfTrace trace) {
23 super(trace.getCTFTrace());
24 this.ctfTmfTrace = trace;
25
26 // FIXME put the real stuff here...
27 this.curLocation = new CtfLocation(trace.getStartTime());
28 this.curRank = 0;
29 }
30
31 public CtfIterator(CtfTmfTrace trace, long timestampValue, long rank) {
32 super(trace.getCTFTrace());
33 this.ctfTmfTrace = trace;
34 this.curLocation = (new CtfLocation(
35 this.getCurrentEvent().getTimestampValue()));
36 if (this.getCurrentEvent().getTimestampValue() != timestampValue) {
37 this.seek(timestampValue);
38 }
39
40 this.curRank = rank;
41 }
42
43 public CtfTmfTrace getCtfTmfTrace() {
44 return ctfTmfTrace;
45 }
46
47 public CtfTmfEvent getCurrentEvent() {
48 StreamInputReader top = super.prio.peek();
49 if (top != null) {
50 return new CtfTmfEvent(top.getCurrentEvent(), top, ctfTmfTrace);
51 }
52 return null;
53 }
54
55 @Override
56 public boolean seek(long timestamp) {
57 boolean ret = false;
58 ret = super.seek(timestamp);
59
60 if (ret) {
61 curLocation.setLocation(getCurrentEvent().getTimestampValue());
62 }
63 return ret;
64 }
65
66 @Override
67 public long getRank() {
68 final CtfTmfEvent current = getCurrentEvent();
69 if (current != null) {
70 return getCurrentEvent().getRank();
71 }
72 return 0;
73 }
74
75 @Override
76 public void setRank(long rank) {
77 // FIXME NYI
78 }
79
80 /*
81 * (non-Javadoc)
82 *
83 * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#clone()
84 */
85 @Override
86 public CtfIterator clone() {
87 CtfIterator clone = null;
88 clone = new CtfIterator(ctfTmfTrace,
89 this.getCurrentEvent().getTimestampValue(), curRank);
90 return clone;
91 }
92
93 @Override
94 public void dispose() {
95 // FIXME add dispose() stuff to CTFTrace and call it here...
96
97 }
98
99 @Override
100 public void setLocation(ITmfLocation<?> location) {
101 // FIXME alex: isn't there a cleaner way than a cast here?
102 this.curLocation = (CtfLocation) location;
103 }
104
105 @Override
106 public CtfLocation getLocation() {
107 return curLocation;
108 }
109
110 @Override
111 public void updateRank(int rank) {
112 curRank = rank;
113 }
114
115 @Override
116 public boolean isValidRank() {
117 return true;
118 }
119
120 @Override
121 public boolean advance() {
122 return super.advance();
123 }
124
125 @Override
126 public int compareTo(CtfIterator o) {
127 if (this.getRank() < o.getRank()) {
128 return -1;
129 } else if (this.getRank() > o.getRank()) {
130 return 1;
131 }
132 return 0;
133 }
134
135}
This page took 0.028945 seconds and 5 git commands to generate.