Refactor TmfCheckpoint and dependencies
[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 * <b><u>TmfCheckpoint</u></b>
20 * <p>
21 * This class maps an event timestamp to a generic location.
22 */
23 public class TmfCheckpoint implements ITmfCheckpoint {
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 // The checkpoint location
30 private ITmfLocation<? extends Comparable<?>> fLocation;
31
32 // The checkpoint timestamp
33 private ITmfTimestamp fTimestamp;
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
39 /**
40 * Default constructor
41 */
42 @SuppressWarnings("unused")
43 private TmfCheckpoint() {
44 }
45
46 /**
47 * Full constructor
48 *
49 * @param timestamp the checkpoint timestamp
50 * @param location the corresponding trace location
51 */
52 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation<? extends Comparable<?>> 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 fTimestamp = other.fTimestamp;
66 fLocation = other.fLocation;
67 }
68
69 // ------------------------------------------------------------------------
70 // Cloneable
71 // ------------------------------------------------------------------------
72
73 /* (non-Javadoc)
74 * @see java.lang.Object#clone()
75 */
76 @Override
77 public TmfCheckpoint clone() {
78 TmfCheckpoint clone = null;
79 try {
80 clone = (TmfCheckpoint) super.clone();
81 clone.fLocation = (fLocation != null) ? fLocation.clone() : null;
82 clone.fTimestamp = (fTimestamp != null) ? fTimestamp.clone() : null;
83 } catch (final CloneNotSupportedException e) {
84 }
85 return clone;
86 }
87
88 // ------------------------------------------------------------------------
89 // Accessors
90 // ------------------------------------------------------------------------
91
92 /**
93 * @return the checkpoint timestamp
94 */
95 @Override
96 public ITmfTimestamp getTimestamp() {
97 return fTimestamp;
98 }
99
100 /**
101 * @return the checkpoint stream location
102 */
103 @Override
104 public ITmfLocation<?> getLocation() {
105 return fLocation;
106 }
107
108 // ------------------------------------------------------------------------
109 // Comparable
110 // ------------------------------------------------------------------------
111
112 @SuppressWarnings({ "unchecked", "rawtypes" })
113 @Override
114 public int compareTo(final ITmfCheckpoint other) {
115 if (fTimestamp == null || other.getTimestamp() == null) {
116 final Comparable location1 = fLocation.getLocation();
117 final Comparable location2 = other.getLocation().getLocation();
118 return location1.compareTo(location2);
119 }
120 return fTimestamp.compareTo(other.getTimestamp(), false);
121 }
122
123 // ------------------------------------------------------------------------
124 // Object
125 // ------------------------------------------------------------------------
126
127 @Override
128 public int hashCode() {
129 final int prime = 31;
130 int result = 1;
131 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
132 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
133 return result;
134 }
135
136 @Override
137 public boolean equals(final Object obj) {
138 if (this == obj)
139 return true;
140 if (obj == null)
141 return false;
142 if (!(obj instanceof TmfCheckpoint))
143 return false;
144 final TmfCheckpoint other = (TmfCheckpoint) obj;
145 if (fLocation == null) {
146 if (other.fLocation != null)
147 return false;
148 } else if (!fLocation.equals(other.fLocation))
149 return false;
150 if (fTimestamp == null) {
151 if (other.fTimestamp != null)
152 return false;
153 } else if (!fTimestamp.equals(other.fTimestamp))
154 return false;
155 return true;
156 }
157
158 @Override
159 @SuppressWarnings("nls")
160 public String toString() {
161 return "TmfCheckpoint [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
162 }
163
164 }
This page took 0.035038 seconds and 6 git commands to generate.