[Bug304438] Improvement on ITmfLocation
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / event / LttngLocation.java
CommitLineData
5d10d135
ASL
1package org.eclipse.linuxtools.lttng.event;
2
9f584e4c 3import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
5d10d135 4
9f584e4c 5
452ad365 6public class LttngLocation implements ITmfLocation<Long[]> {
f26cc49c
WB
7
8 private final static Long DEFAULT_LAST_TIME = -1L;
9 private final static Long DEFAULT_CURR_TIME = 0L;
5d10d135 10
f26cc49c
WB
11 private Long lastReadTime = null;
12 private Long currentTime = null;
5d10d135 13
5d10d135 14
5d10d135
ASL
15
16 public LttngLocation() {
f26cc49c 17 this(DEFAULT_LAST_TIME, DEFAULT_CURR_TIME);
5d10d135
ASL
18 }
19
a55a769e
WB
20// public LttngLocation(LttngTimestamp timestamp) {
21// this(DEFAULT_LAST_TIME, timestamp.getValue());
22// }
9f584e4c 23
f26cc49c
WB
24 public LttngLocation(LttngLocation oldLocation) {
25 this(oldLocation.lastReadTime, oldLocation.currentTime);
5d10d135
ASL
26 }
27
f26cc49c
WB
28 public LttngLocation(Long newCurrentTimestamp) {
29 this(DEFAULT_LAST_TIME, newCurrentTimestamp);
5d10d135
ASL
30 }
31
f26cc49c
WB
32 public LttngLocation(Long newLastReadTime, Long newCurrentTimestamp) {
33 lastReadTime = newLastReadTime;
34 currentTime = newCurrentTimestamp;
5d10d135
ASL
35 }
36
37 @Override
38 public LttngLocation clone() {
39
40 LttngLocation newLocation = null;
41
42 try {
43 newLocation = (LttngLocation)super.clone();
44
45 // *** IMPORTANT ***
46 // Basic type in java are immutable!
47 // Thus, using assignation ("=") on basic type is VALID.
f26cc49c
WB
48 newLocation.currentTime = this.currentTime;
49 newLocation.lastReadTime = this.lastReadTime;
5d10d135
ASL
50 }
51 catch (CloneNotSupportedException e) {
52 System.out.println("Cloning failed with : " + e.getMessage());
53 }
54
55 return newLocation;
56 }
57
5d10d135 58
f26cc49c
WB
59 public void resetLocation() {
60 resetLocation(DEFAULT_CURR_TIME);
5d10d135
ASL
61 }
62
f26cc49c
WB
63 public void resetLocation(Long newCurrentTimestamp) {
64 lastReadTime = DEFAULT_LAST_TIME;
65 lastReadTime = DEFAULT_CURR_TIME;
5d10d135
ASL
66 }
67
5d10d135
ASL
68
69
f26cc49c
WB
70 public Long getLastReadTime() {
71 return lastReadTime;
5d10d135 72 }
5d10d135 73
f26cc49c
WB
74 public void setLastReadTime(Long newLastReadTime) {
75 this.lastReadTime = newLastReadTime;
5d10d135 76 }
5d10d135 77
f26cc49c
WB
78 public Long getCurrentTime() {
79 return currentTime;
5d10d135
ASL
80 }
81
f26cc49c
WB
82 public void setCurrentTime(Long newCurrentTime) {
83 this.currentTime = newCurrentTime;
5d10d135
ASL
84 }
85
5d10d135 86
17c0074a 87 @Override
f26cc49c
WB
88 public String toString() {
89 return "\tLttngLocation[ Last : " + lastReadTime + " Current : " + currentTime + " ]";
5d10d135 90 }
452ad365
FC
91
92 // ------------------------------------------------------------------------
93 // ITmfLocation
94 // ------------------------------------------------------------------------
95
96 public void setLocation(Long[] location) {
97 lastReadTime = ((Long[]) location)[0];
98 currentTime = ((Long[]) location)[1];
99 }
100
101 public Long[] getLocation() {
102 return new Long[] {lastReadTime, currentTime };
103 }
5d10d135
ASL
104
105}
This page took 0.030175 seconds and 5 git commands to generate.