Fix NLS-related Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfCheckpoint.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
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
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 * Patrick Tasse - Updated for location in checkpoint
13 ******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.core.trace;
16
17 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
18
19 /**
20 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
21 * to a generic location.
22 *
23 * @version 1.0
24 * @author Francois Chouinard
25 *
26 * @see ITmfLocation
27 * @see ITmfTimestamp
28 */
29 public class TmfCheckpoint implements ITmfCheckpoint {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 // The checkpoint location
36 private final ITmfLocation fLocation;
37
38 // The checkpoint timestamp
39 private final ITmfTimestamp fTimestamp;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * Full constructor
47 *
48 * @param timestamp the checkpoint timestamp
49 * @param location the corresponding trace location
50 * @since 2.0
51 */
52 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) {
53 fTimestamp = timestamp;
54 fLocation = location;
55 }
56
57 /**
58 * Copy constructor
59 *
60 * @param other the other checkpoint
61 */
62 public TmfCheckpoint(final TmfCheckpoint other) {
63 if (other == null) {
64 throw new IllegalArgumentException();
65 }
66 fTimestamp = other.fTimestamp;
67 fLocation = other.fLocation;
68 }
69
70 // ------------------------------------------------------------------------
71 // ITmfCheckpoint
72 // ------------------------------------------------------------------------
73
74 /**
75 * @since 2.0
76 */
77 @Override
78 public ITmfTimestamp getTimestamp() {
79 return fTimestamp;
80 }
81
82 /* (non-Javadoc)
83 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
84 */
85 @Override
86 public ITmfLocation getLocation() {
87 return fLocation;
88 }
89
90 // ------------------------------------------------------------------------
91 // Comparable
92 // ------------------------------------------------------------------------
93
94 /* (non-Javadoc)
95 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
96 *
97 * Compares the checkpoints timestamp. If either is null, compares the
98 * trace checkpoints locations.
99 */
100 @Override
101 @SuppressWarnings({ "unchecked", "rawtypes" })
102 public int compareTo(final ITmfCheckpoint other) {
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
110 }
111
112 if ((fLocation == null) && (other.getLocation() == null)) {
113 return 0;
114 }
115
116 // treat location of other as null location which is before any location
117 if ((fLocation != null) && (other.getLocation() == null)) {
118 return 1;
119 }
120
121 // treat this as null location which is before any other locations
122 if ((fLocation == null) && (other.getLocation() != null)) {
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);
130 }
131
132 // ------------------------------------------------------------------------
133 // Object
134 // ------------------------------------------------------------------------
135
136 /* (non-Javadoc)
137 * @see java.lang.Object#hashCode()
138 */
139 @Override
140 public int hashCode() {
141 final int prime = 31;
142 int result = 1;
143 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
144 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
145 return result;
146 }
147
148 /* (non-Javadoc)
149 * @see java.lang.Object#equals(java.lang.Object)
150 */
151 @Override
152 public boolean equals(final Object obj) {
153 if (this == obj) {
154 return true;
155 }
156 if (obj == null) {
157 return false;
158 }
159 if (!(obj instanceof TmfCheckpoint)) {
160 return false;
161 }
162 final TmfCheckpoint other = (TmfCheckpoint) obj;
163 if (fLocation == null) {
164 if (other.fLocation != null) {
165 return false;
166 }
167 } else if (!fLocation.equals(other.fLocation)) {
168 return false;
169 }
170 if (fTimestamp == null) {
171 if (other.fTimestamp != null) {
172 return false;
173 }
174 } else if (!fTimestamp.equals(other.fTimestamp)) {
175 return false;
176 }
177 return true;
178 }
179
180 /* (non-Javadoc)
181 * @see java.lang.Object#toString()
182 */
183 @Override
184 @SuppressWarnings("nls")
185 public String toString() {
186 return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
187 }
188
189 }
This page took 0.034778 seconds and 5 git commands to generate.