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