Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
5d837f9b | 2 | * Copyright (c) 2009, 2012 Ericsson |
8c8bf09f ASL |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
5d837f9b FC |
11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
12 | ******************************************************************************/ | |
8c8bf09f | 13 | |
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
4df4581d | 16 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
8c8bf09f ASL |
17 | |
18 | /** | |
2848c377 FC |
19 | * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp |
20 | * to a generic location. | |
f7703ed6 | 21 | * |
f7703ed6 FC |
22 | * @version 1.0 |
23 | * @author Francois Chouinard | |
24 | * | |
f7703ed6 FC |
25 | * @see ITmfLocation |
26 | * @see ITmfTimestamp | |
8c8bf09f | 27 | */ |
0316808c | 28 | public class TmfCheckpoint implements ITmfCheckpoint, Cloneable { |
8c8bf09f ASL |
29 | |
30 | // ------------------------------------------------------------------------ | |
31 | // Attributes | |
32 | // ------------------------------------------------------------------------ | |
cbdacf03 | 33 | |
5d837f9b FC |
34 | // The checkpoint location |
35 | private ITmfLocation<? extends Comparable<?>> fLocation; | |
36 | ||
37 | // The checkpoint timestamp | |
4df4581d | 38 | private ITmfTimestamp fTimestamp; |
8c8bf09f ASL |
39 | |
40 | // ------------------------------------------------------------------------ | |
41 | // Constructors | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
5d837f9b FC |
44 | /** |
45 | * Default constructor | |
46 | */ | |
ff4ed569 | 47 | @SuppressWarnings("unused") |
cbdacf03 | 48 | private TmfCheckpoint() { |
ff4ed569 FC |
49 | } |
50 | ||
8c8bf09f | 51 | /** |
5d837f9b FC |
52 | * Full constructor |
53 | * | |
54 | * @param timestamp the checkpoint timestamp | |
ff4ed569 | 55 | * @param location the corresponding trace location |
8c8bf09f | 56 | */ |
5d837f9b FC |
57 | public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation<? extends Comparable<?>> location) { |
58 | fTimestamp = timestamp; | |
8c8bf09f ASL |
59 | fLocation = location; |
60 | } | |
61 | ||
ff4ed569 | 62 | /** |
5d837f9b | 63 | * Copy constructor |
cbdacf03 | 64 | * |
ff4ed569 FC |
65 | * @param other the other checkpoint |
66 | */ | |
cbdacf03 | 67 | public TmfCheckpoint(final TmfCheckpoint other) { |
0316808c | 68 | if (other == null) { |
cbdacf03 | 69 | throw new IllegalArgumentException(); |
0316808c | 70 | } |
5d837f9b FC |
71 | fTimestamp = other.fTimestamp; |
72 | fLocation = other.fLocation; | |
73 | } | |
74 | ||
75 | // ------------------------------------------------------------------------ | |
76 | // Cloneable | |
77 | // ------------------------------------------------------------------------ | |
78 | ||
79 | /* (non-Javadoc) | |
80 | * @see java.lang.Object#clone() | |
81 | */ | |
82 | @Override | |
83 | public TmfCheckpoint clone() { | |
84 | TmfCheckpoint clone = null; | |
85 | try { | |
86 | clone = (TmfCheckpoint) super.clone(); | |
87 | clone.fLocation = (fLocation != null) ? fLocation.clone() : null; | |
88 | clone.fTimestamp = (fTimestamp != null) ? fTimestamp.clone() : null; | |
89 | } catch (final CloneNotSupportedException e) { | |
90 | } | |
91 | return clone; | |
ff4ed569 FC |
92 | } |
93 | ||
8c8bf09f | 94 | // ------------------------------------------------------------------------ |
8ca8c4f1 | 95 | // ITmfCheckpoint |
8c8bf09f ASL |
96 | // ------------------------------------------------------------------------ |
97 | ||
8ca8c4f1 FC |
98 | /* (non-Javadoc) |
99 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp() | |
8c8bf09f | 100 | */ |
5d837f9b | 101 | @Override |
4df4581d | 102 | public ITmfTimestamp getTimestamp() { |
8c8bf09f ASL |
103 | return fTimestamp; |
104 | } | |
105 | ||
8ca8c4f1 FC |
106 | /* (non-Javadoc) |
107 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation() | |
8c8bf09f | 108 | */ |
5d837f9b | 109 | @Override |
452ad365 | 110 | public ITmfLocation<?> getLocation() { |
8c8bf09f ASL |
111 | return fLocation; |
112 | } | |
113 | ||
cbd4ad82 | 114 | // ------------------------------------------------------------------------ |
5d837f9b | 115 | // Comparable |
cbd4ad82 FC |
116 | // ------------------------------------------------------------------------ |
117 | ||
8ca8c4f1 FC |
118 | /* (non-Javadoc) |
119 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint) | |
120 | * | |
121 | * Compares the checkpoints timestamp. If either is null, compares the | |
122 | * trace checkpoints locations. | |
123 | */ | |
550d787e | 124 | @Override |
ff1ccee6 | 125 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
5d837f9b FC |
126 | public int compareTo(final ITmfCheckpoint other) { |
127 | if (fTimestamp == null || other.getTimestamp() == null) { | |
128 | final Comparable location1 = fLocation.getLocation(); | |
129 | final Comparable location2 = other.getLocation().getLocation(); | |
130 | return location1.compareTo(location2); | |
cbdacf03 | 131 | } |
5d837f9b | 132 | return fTimestamp.compareTo(other.getTimestamp(), false); |
550d787e | 133 | } |
cbdacf03 | 134 | |
5d837f9b FC |
135 | // ------------------------------------------------------------------------ |
136 | // Object | |
137 | // ------------------------------------------------------------------------ | |
138 | ||
8ca8c4f1 FC |
139 | /* (non-Javadoc) |
140 | * @see java.lang.Object#hashCode() | |
141 | */ | |
cbd4ad82 FC |
142 | @Override |
143 | public int hashCode() { | |
5d837f9b FC |
144 | final int prime = 31; |
145 | int result = 1; | |
146 | result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode()); | |
147 | result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode()); | |
148 | return result; | |
cbd4ad82 | 149 | } |
cbdacf03 | 150 | |
8ca8c4f1 FC |
151 | /* (non-Javadoc) |
152 | * @see java.lang.Object#equals(java.lang.Object) | |
153 | */ | |
cbd4ad82 | 154 | @Override |
5d837f9b | 155 | public boolean equals(final Object obj) { |
0316808c | 156 | if (this == obj) { |
5d837f9b | 157 | return true; |
0316808c FC |
158 | } |
159 | if (obj == null) { | |
5d837f9b | 160 | return false; |
0316808c FC |
161 | } |
162 | if (!(obj instanceof TmfCheckpoint)) { | |
cbdacf03 | 163 | return false; |
0316808c | 164 | } |
5d837f9b FC |
165 | final TmfCheckpoint other = (TmfCheckpoint) obj; |
166 | if (fLocation == null) { | |
0316808c | 167 | if (other.fLocation != null) { |
5d837f9b | 168 | return false; |
0316808c FC |
169 | } |
170 | } else if (!fLocation.equals(other.fLocation)) { | |
5d837f9b | 171 | return false; |
0316808c | 172 | } |
5d837f9b | 173 | if (fTimestamp == null) { |
0316808c | 174 | if (other.fTimestamp != null) { |
5d837f9b | 175 | return false; |
0316808c FC |
176 | } |
177 | } else if (!fTimestamp.equals(other.fTimestamp)) { | |
5d837f9b | 178 | return false; |
0316808c | 179 | } |
5d837f9b | 180 | return true; |
cbd4ad82 | 181 | } |
cbdacf03 | 182 | |
8ca8c4f1 FC |
183 | /* (non-Javadoc) |
184 | * @see java.lang.Object#toString() | |
185 | */ | |
ff4ed569 | 186 | @Override |
3b38ea61 | 187 | @SuppressWarnings("nls") |
ff4ed569 | 188 | public String toString() { |
5d837f9b | 189 | return "TmfCheckpoint [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]"; |
8c8bf09f ASL |
190 | } |
191 | ||
192 | } |