Simplify TmfEvent constructors and update 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 * This class maps an event timestamp to a generic location.
20 *
21 * @since 1.0
22 * @version 1.0
23 * @author Francois Chouinard
24 *
25 * @see ITmfCheckpoint
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 ITmfLocation<? extends Comparable<?>> fLocation;
37
38 // The checkpoint timestamp
39 private ITmfTimestamp fTimestamp;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * Default constructor
47 */
48 @SuppressWarnings("unused")
49 private TmfCheckpoint() {
50 }
51
52 /**
53 * Full constructor
54 *
55 * @param timestamp the checkpoint timestamp
56 * @param location the corresponding trace location
57 */
58 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation<? extends Comparable<?>> location) {
59 fTimestamp = timestamp;
60 fLocation = location;
61 }
62
63 /**
64 * Copy constructor
65 *
66 * @param other the other checkpoint
67 */
68 public TmfCheckpoint(final TmfCheckpoint other) {
69 if (other == null)
70 throw new IllegalArgumentException();
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;
92 }
93
94 // ------------------------------------------------------------------------
95 // ITmfCheckpoint
96 // ------------------------------------------------------------------------
97
98 /* (non-Javadoc)
99 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
100 */
101 @Override
102 public ITmfTimestamp getTimestamp() {
103 return fTimestamp;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
108 */
109 @Override
110 public ITmfLocation<?> getLocation() {
111 return fLocation;
112 }
113
114 // ------------------------------------------------------------------------
115 // Comparable
116 // ------------------------------------------------------------------------
117
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 */
124 @Override
125 @SuppressWarnings({ "unchecked", "rawtypes" })
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);
131 }
132 return fTimestamp.compareTo(other.getTimestamp(), false);
133 }
134
135 // ------------------------------------------------------------------------
136 // Object
137 // ------------------------------------------------------------------------
138
139 /* (non-Javadoc)
140 * @see java.lang.Object#hashCode()
141 */
142 @Override
143 public int hashCode() {
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;
149 }
150
151 /* (non-Javadoc)
152 * @see java.lang.Object#equals(java.lang.Object)
153 */
154 @Override
155 public boolean equals(final Object obj) {
156 if (this == obj)
157 return true;
158 if (obj == null)
159 return false;
160 if (!(obj instanceof TmfCheckpoint))
161 return false;
162 final TmfCheckpoint other = (TmfCheckpoint) obj;
163 if (fLocation == null) {
164 if (other.fLocation != null)
165 return false;
166 } else if (!fLocation.equals(other.fLocation))
167 return false;
168 if (fTimestamp == null) {
169 if (other.fTimestamp != null)
170 return false;
171 } else if (!fTimestamp.equals(other.fTimestamp))
172 return false;
173 return true;
174 }
175
176 /* (non-Javadoc)
177 * @see java.lang.Object#toString()
178 */
179 @Override
180 @SuppressWarnings("nls")
181 public String toString() {
182 return "TmfCheckpoint [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
183 }
184
185 }
This page took 0.036908 seconds and 6 git commands to generate.