Commit | Line | Data |
---|---|---|
5945cec9 | 1 | package org.eclipse.linuxtools.internal.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> { |
5d837f9b FC |
7 | |
8 | private final static long DEFAULT_CURR_TIME = 0L; | |
9 | ||
10 | private boolean isLastOperationParse = false ; | |
11 | private boolean isLastOperationReadNext = false; | |
12 | private boolean isLastOperationSeek = false; | |
13 | ||
14 | private LttngTimestamp operationTime = null; | |
15 | ||
16 | public LttngLocation() { | |
17 | this( DEFAULT_CURR_TIME ); | |
18 | } | |
19 | ||
20 | public LttngLocation(final long newCurrentTimestampValue) { | |
21 | isLastOperationParse = false; | |
22 | isLastOperationReadNext = false; | |
23 | isLastOperationSeek = false; | |
24 | operationTime = new LttngTimestamp(newCurrentTimestampValue); | |
25 | } | |
26 | ||
27 | public LttngLocation(final LttngTimestamp newCurrentTimestamp) { | |
28 | isLastOperationParse = false; | |
29 | isLastOperationReadNext = false; | |
30 | isLastOperationSeek = false; | |
31 | operationTime = new LttngTimestamp(newCurrentTimestamp); | |
32 | } | |
33 | ||
34 | ||
35 | public LttngLocation(final LttngLocation oldLocation) { | |
36 | this.isLastOperationParse = oldLocation.isLastOperationParse; | |
37 | this.isLastOperationReadNext = oldLocation.isLastOperationReadNext; | |
38 | this.isLastOperationSeek = oldLocation.isLastOperationSeek; | |
39 | this.operationTime = oldLocation.operationTime; | |
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. | |
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 ); | |
59 | } | |
60 | catch (final CloneNotSupportedException e) { | |
61 | System.out.println("Cloning failed with : " + e.getMessage()); //$NON-NLS-1$ | |
62 | } | |
63 | ||
64 | return newLocation; | |
65 | } | |
66 | ||
67 | public LttngTimestamp getOperationTime() { | |
68 | return operationTime; | |
69 | } | |
70 | ||
71 | public long getOperationTimeValue() { | |
72 | return operationTime.getValue(); | |
73 | } | |
74 | ||
75 | public void setOperationTime(final LttngTimestamp newOperationTime) { | |
76 | this.operationTime.setValue(newOperationTime.getValue()); | |
77 | } | |
78 | ||
79 | public void setOperationTime(final Long newOperationTimeValue) { | |
80 | this.operationTime.setValue(newOperationTimeValue); | |
81 | } | |
82 | ||
83 | ||
84 | public void setLastOperationParse() { | |
85 | isLastOperationParse = true; | |
86 | isLastOperationReadNext = false; | |
87 | isLastOperationSeek = false; | |
88 | } | |
89 | ||
90 | public boolean isLastOperationParse() { | |
91 | return isLastOperationParse; | |
92 | } | |
93 | ||
94 | ||
95 | public void setLastOperationReadNext() { | |
96 | isLastOperationParse = false; | |
97 | isLastOperationReadNext = true; | |
98 | isLastOperationSeek = false; | |
99 | } | |
100 | ||
101 | public boolean isLastOperationReadNext() { | |
102 | return isLastOperationReadNext; | |
103 | } | |
104 | ||
105 | ||
106 | public void setLastOperationSeek() { | |
107 | isLastOperationParse = false; | |
108 | isLastOperationReadNext = false; | |
109 | isLastOperationSeek = true; | |
110 | } | |
111 | ||
112 | public boolean isLastOperationSeek() { | |
113 | return isLastOperationSeek; | |
114 | } | |
115 | ||
116 | public void resetLocationState() { | |
117 | isLastOperationParse = false; | |
118 | isLastOperationReadNext = false; | |
119 | isLastOperationSeek = false; | |
120 | } | |
121 | ||
122 | // ------------------------------------------------------------------------ | |
123 | // Object | |
124 | // ------------------------------------------------------------------------ | |
125 | ||
126 | /* (non-Javadoc) | |
1cceddbe | 127 | * @see java.lang.Object#hashCode() |
128 | */ | |
129 | @Override | |
130 | public int hashCode() { | |
131 | final int prime = 31; | |
132 | int result = 1; | |
133 | result = prime * result + (isLastOperationParse ? 1231 : 1237); | |
134 | result = prime * result + (isLastOperationReadNext ? 1231 : 1237); | |
135 | result = prime * result + (isLastOperationSeek ? 1231 : 1237); | |
136 | result = prime * result + ((operationTime == null) ? 0 : operationTime.hashCode()); | |
137 | return result; | |
138 | } | |
139 | ||
140 | /* (non-Javadoc) | |
141 | * @see java.lang.Object#equals(java.lang.Object) | |
142 | */ | |
143 | @Override | |
5d837f9b FC |
144 | public boolean equals(final Object obj) { |
145 | if (this == obj) | |
1cceddbe | 146 | return true; |
5d837f9b | 147 | if (obj == null) |
1cceddbe | 148 | return false; |
5d837f9b | 149 | if (!(obj instanceof LttngLocation)) |
1cceddbe | 150 | return false; |
5d837f9b | 151 | final LttngLocation o = (LttngLocation) obj; |
1cceddbe | 152 | return (operationTime.equals(o.operationTime)) |
5d837f9b FC |
153 | && (isLastOperationParse == o.isLastOperationParse) |
154 | && (isLastOperationReadNext == o.isLastOperationReadNext) | |
155 | && (isLastOperationSeek == o.isLastOperationSeek); | |
156 | } | |
157 | ||
158 | @Override | |
159 | public String toString() { | |
160 | // return "\tLttngLocation[ P/R/S : " + isLastOperationParse + "/" + isLastOperationReadNext + "/" + isLastOperationSeek + " Current : " + operationTime + " ]"; | |
161 | return operationTime.toString(); | |
162 | } | |
163 | ||
164 | // ------------------------------------------------------------------------ | |
165 | // ITmfLocation | |
166 | // ------------------------------------------------------------------------ | |
167 | ||
168 | // @Override | |
169 | public void setLocation(final LttngTimestamp location) { | |
170 | operationTime = location; | |
171 | } | |
172 | ||
173 | @Override | |
174 | public LttngTimestamp getLocation() { | |
175 | return new LttngTimestamp ( operationTime ); | |
1cceddbe | 176 | } |
177 | ||
178 | @Override | |
5d837f9b FC |
179 | public int compareTo(final LttngLocation o) { |
180 | return operationTime.compareTo(o.operationTime); | |
181 | } | |
182 | ||
5d10d135 | 183 | } |