tmf: Remove Cloneable from (I)TmfCheckpoint
[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 * @version 1.0
23 * @author Francois Chouinard
24 *
25 * @see ITmfLocation
26 * @see ITmfTimestamp
27 */
28 public class TmfCheckpoint implements ITmfCheckpoint {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
33
34 // The checkpoint context
35 private final ITmfContext fContext;
36
37 // The checkpoint timestamp
38 private final ITmfTimestamp fTimestamp;
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43
44 /**
45 * Full constructor
46 *
47 * @param timestamp the checkpoint timestamp
48 * @param context the corresponding trace location
49 */
50 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfContext context) {
51 fTimestamp = timestamp;
52 fContext = context;
53 }
54
55 /**
56 * Copy constructor
57 *
58 * @param other the other checkpoint
59 */
60 public TmfCheckpoint(final TmfCheckpoint other) {
61 if (other == null) {
62 throw new IllegalArgumentException();
63 }
64 fTimestamp = other.fTimestamp;
65 fContext = other.fContext;
66 }
67
68 // ------------------------------------------------------------------------
69 // ITmfCheckpoint
70 // ------------------------------------------------------------------------
71
72 /* (non-Javadoc)
73 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
74 */
75 @Override
76 public ITmfTimestamp getTimestamp() {
77 return fTimestamp;
78 }
79
80 /* (non-Javadoc)
81 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
82 */
83 @Override
84 public ITmfContext getContext() {
85 return fContext;
86 }
87
88 /* (non-Javadoc)
89 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
90 */
91 @Override
92 public ITmfLocation getLocation() {
93 return fContext.getLocation();
94 }
95
96 // ------------------------------------------------------------------------
97 // Comparable
98 // ------------------------------------------------------------------------
99
100 /* (non-Javadoc)
101 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
102 *
103 * Compares the checkpoints timestamp. If either is null, compares the
104 * trace checkpoints locations.
105 */
106 @Override
107 @SuppressWarnings({ "unchecked", "rawtypes" })
108 public int compareTo(final ITmfCheckpoint other) {
109 int comp = 0;
110 if ((fTimestamp != null) && (other.getTimestamp() != null)) {
111 comp = fTimestamp.compareTo(other.getTimestamp(), false);
112 if (comp != 0) {
113 return comp;
114 }
115 // compare locations if timestamps are the same
116 }
117
118 if ((getContext() == null) && (other.getContext() == null)) {
119 return 0;
120 }
121
122 // treat location of other as null location which is before any location
123 if ((getContext() != null) && (other.getContext() == null)) {
124 return 1;
125 }
126
127 // treat this as null location which is before any other locations
128 if ((getContext() == null) && (other.getContext() != null)) {
129 return -1;
130 }
131
132 // compare location
133 final Comparable location1 = getLocation().getLocationInfo();
134 final Comparable location2 = other.getLocation().getLocationInfo();
135 return location1.compareTo(location2);
136 }
137
138 // ------------------------------------------------------------------------
139 // Object
140 // ------------------------------------------------------------------------
141
142 /* (non-Javadoc)
143 * @see java.lang.Object#hashCode()
144 */
145 @Override
146 public int hashCode() {
147 final int prime = 31;
148 int result = 1;
149 result = prime * result + ((fContext == null) ? 0 : fContext.hashCode());
150 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
151 return result;
152 }
153
154 /* (non-Javadoc)
155 * @see java.lang.Object#equals(java.lang.Object)
156 */
157 @Override
158 public boolean equals(final Object obj) {
159 if (this == obj) {
160 return true;
161 }
162 if (obj == null) {
163 return false;
164 }
165 if (!(obj instanceof TmfCheckpoint)) {
166 return false;
167 }
168 final TmfCheckpoint other = (TmfCheckpoint) obj;
169 if (fContext == null) {
170 if (other.fContext != null) {
171 return false;
172 }
173 } else if (!fContext.equals(other.fContext)) {
174 return false;
175 }
176 if (fTimestamp == null) {
177 if (other.fTimestamp != null) {
178 return false;
179 }
180 } else if (!fTimestamp.equals(other.fTimestamp)) {
181 return false;
182 }
183 return true;
184 }
185
186 /* (non-Javadoc)
187 * @see java.lang.Object#toString()
188 */
189 @Override
190 @SuppressWarnings("nls")
191 public String toString() {
192 return "TmfCheckpoint [fContext=" + fContext + ", fTimestamp=" + fTimestamp + "]";
193 }
194
195 }
This page took 0.035364 seconds and 5 git commands to generate.