Commit | Line | Data |
---|---|---|
6c13869b | 1 | package org.eclipse.linuxtools.lttng.core.event; |
5d10d135 | 2 | |
6c13869b | 3 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
5d10d135 | 4 | |
9f584e4c | 5 | |
a79913eb | 6 | public class LttngLocation implements ITmfLocation<LttngTimestamp>, Comparable<LttngLocation> { |
f26cc49c | 7 | |
7f2f49e3 | 8 | private final static long DEFAULT_CURR_TIME = 0L; |
5d10d135 | 9 | |
7f2f49e3 WB |
10 | private boolean isLastOperationParse = false ; |
11 | private boolean isLastOperationReadNext = false; | |
12 | private boolean isLastOperationSeek = false; | |
5d10d135 | 13 | |
7f2f49e3 | 14 | private LttngTimestamp operationTime = null; |
5d10d135 ASL |
15 | |
16 | public LttngLocation() { | |
7f2f49e3 | 17 | this( DEFAULT_CURR_TIME ); |
5d10d135 ASL |
18 | } |
19 | ||
7f2f49e3 WB |
20 | public LttngLocation(long newCurrentTimestampValue) { |
21 | isLastOperationParse = false; | |
22 | isLastOperationReadNext = false; | |
23 | isLastOperationSeek = false; | |
24 | operationTime = new LttngTimestamp(newCurrentTimestampValue); | |
5d10d135 ASL |
25 | } |
26 | ||
7f2f49e3 WB |
27 | public LttngLocation(LttngTimestamp newCurrentTimestamp) { |
28 | isLastOperationParse = false; | |
29 | isLastOperationReadNext = false; | |
30 | isLastOperationSeek = false; | |
31 | operationTime = new LttngTimestamp(newCurrentTimestamp); | |
5d10d135 ASL |
32 | } |
33 | ||
7f2f49e3 WB |
34 | |
35 | public LttngLocation(LttngLocation oldLocation) { | |
36 | this.isLastOperationParse = oldLocation.isLastOperationParse; | |
37 | this.isLastOperationReadNext = oldLocation.isLastOperationReadNext; | |
38 | this.isLastOperationSeek = oldLocation.isLastOperationSeek; | |
39 | this.operationTime = oldLocation.operationTime; | |
5d10d135 ASL |
40 | } |
41 | ||
42 | @Override | |
43 | public LttngLocation clone() { | |
44 | ||
45 | LttngLocation newLocation = null; | |
46 | ||
47 | try { | |
48 | newLocation = (LttngLocation)super.clone(); | |
49 | ||
50 | // *** IMPORTANT *** | |
51 | // Basic type in java are immutable! | |
52 | // Thus, using assignation ("=") on basic type is VALID. | |
7f2f49e3 WB |
53 | newLocation.isLastOperationParse = this.isLastOperationParse; |
54 | newLocation.isLastOperationReadNext = this.isLastOperationReadNext; | |
55 | newLocation.isLastOperationSeek = this.isLastOperationSeek; | |
56 | ||
57 | // For other type, we need to create a new timestamp | |
58 | newLocation.operationTime = new LttngTimestamp( this.operationTime ); | |
5d10d135 ASL |
59 | } |
60 | catch (CloneNotSupportedException e) { | |
9c4eb5f7 | 61 | System.out.println("Cloning failed with : " + e.getMessage()); //$NON-NLS-1$ |
5d10d135 ASL |
62 | } |
63 | ||
64 | return newLocation; | |
65 | } | |
66 | ||
7f2f49e3 WB |
67 | public LttngTimestamp getOperationTime() { |
68 | return operationTime; | |
69 | } | |
5d10d135 | 70 | |
7f2f49e3 WB |
71 | public long getOperationTimeValue() { |
72 | return operationTime.getValue(); | |
5d10d135 ASL |
73 | } |
74 | ||
7f2f49e3 WB |
75 | public void setOperationTime(LttngTimestamp newOperationTime) { |
76 | this.operationTime.setValue(newOperationTime.getValue()); | |
5d10d135 ASL |
77 | } |
78 | ||
7f2f49e3 WB |
79 | public void setOperationTime(Long newOperationTimeValue) { |
80 | this.operationTime.setValue(newOperationTimeValue); | |
81 | } | |
5d10d135 ASL |
82 | |
83 | ||
7f2f49e3 WB |
84 | public void setLastOperationParse() { |
85 | isLastOperationParse = true; | |
86 | isLastOperationReadNext = false; | |
87 | isLastOperationSeek = false; | |
5d10d135 | 88 | } |
7f2f49e3 WB |
89 | |
90 | public boolean isLastOperationParse() { | |
91 | return isLastOperationParse; | |
5d10d135 | 92 | } |
5d10d135 | 93 | |
7f2f49e3 WB |
94 | |
95 | public void setLastOperationReadNext() { | |
96 | isLastOperationParse = false; | |
97 | isLastOperationReadNext = true; | |
98 | isLastOperationSeek = false; | |
99 | } | |
100 | ||
101 | public boolean isLastOperationReadNext() { | |
102 | return isLastOperationReadNext; | |
5d10d135 ASL |
103 | } |
104 | ||
7f2f49e3 WB |
105 | |
106 | public void setLastOperationSeek() { | |
107 | isLastOperationParse = false; | |
108 | isLastOperationReadNext = false; | |
109 | isLastOperationSeek = true; | |
110 | } | |
111 | ||
112 | public boolean isLastOperationSeek() { | |
113 | return isLastOperationSeek; | |
5d10d135 ASL |
114 | } |
115 | ||
7f2f49e3 WB |
116 | public void resetLocationState() { |
117 | isLastOperationParse = false; | |
118 | isLastOperationReadNext = false; | |
119 | isLastOperationSeek = false; | |
120 | } | |
5d10d135 | 121 | |
9b635e61 FC |
122 | // ------------------------------------------------------------------------ |
123 | // Object | |
124 | // ------------------------------------------------------------------------ | |
125 | ||
126 | @Override | |
127 | public boolean equals(Object other) { | |
128 | if (!(other instanceof LttngLocation)) { | |
129 | return false; | |
130 | } | |
131 | LttngLocation o = (LttngLocation) other; | |
132 | return (operationTime.equals(o.operationTime)) && (isLastOperationParse == o.isLastOperationParse) && | |
133 | (isLastOperationReadNext == o.isLastOperationReadNext) && (isLastOperationSeek == o.isLastOperationSeek); | |
134 | } | |
135 | ||
17c0074a | 136 | @Override |
f26cc49c | 137 | public String toString() { |
9b635e61 FC |
138 | // return "\tLttngLocation[ P/R/S : " + isLastOperationParse + "/" + isLastOperationReadNext + "/" + isLastOperationSeek + " Current : " + operationTime + " ]"; |
139 | return operationTime.toString(); | |
5d10d135 | 140 | } |
7f2f49e3 | 141 | |
452ad365 FC |
142 | // ------------------------------------------------------------------------ |
143 | // ITmfLocation | |
144 | // ------------------------------------------------------------------------ | |
9b635e61 | 145 | |
d4011df2 | 146 | @Override |
7f2f49e3 WB |
147 | public void setLocation(LttngTimestamp location) { |
148 | operationTime = (LttngTimestamp)location; | |
452ad365 FC |
149 | } |
150 | ||
d4011df2 | 151 | @Override |
7f2f49e3 WB |
152 | public LttngTimestamp getLocation() { |
153 | return new LttngTimestamp ( operationTime ); | |
452ad365 | 154 | } |
a79913eb FC |
155 | |
156 | @Override | |
157 | public int compareTo(LttngLocation o) { | |
158 | return operationTime.compareTo(o.operationTime); | |
159 | } | |
5d10d135 ASL |
160 | |
161 | } |