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