tmf/lttng: Remove unneeded (non-Javadoc) comments
[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 @Override
83 public ITmfLocation getLocation() {
84 return fLocation;
85 }
86
87 // ------------------------------------------------------------------------
88 // Comparable
89 // ------------------------------------------------------------------------
90
91 @Override
92 @SuppressWarnings({ "unchecked", "rawtypes" })
93 public int compareTo(final ITmfCheckpoint other) {
94 int comp = 0;
95 if ((fTimestamp != null) && (other.getTimestamp() != null)) {
96 comp = fTimestamp.compareTo(other.getTimestamp(), false);
97 if (comp != 0) {
98 return comp;
99 }
100 // compare locations if timestamps are the same
101 }
102
103 if ((fLocation == null) && (other.getLocation() == null)) {
104 return 0;
105 }
106
107 // treat location of other as null location which is before any location
108 if ((fLocation != null) && (other.getLocation() == null)) {
109 return 1;
110 }
111
112 // treat this as null location which is before any other locations
113 if ((fLocation == null) && (other.getLocation() != null)) {
114 return -1;
115 }
116
117 // compare location
118 final Comparable location1 = getLocation().getLocationInfo();
119 final Comparable location2 = other.getLocation().getLocationInfo();
120 return location1.compareTo(location2);
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 }
141 if (obj == null) {
142 return false;
143 }
144 if (!(obj instanceof TmfCheckpoint)) {
145 return false;
146 }
147 final TmfCheckpoint other = (TmfCheckpoint) obj;
148 if (fLocation == null) {
149 if (other.fLocation != null) {
150 return false;
151 }
152 } else if (!fLocation.equals(other.fLocation)) {
153 return false;
154 }
155 if (fTimestamp == null) {
156 if (other.fTimestamp != null) {
157 return false;
158 }
159 } else if (!fTimestamp.equals(other.fTimestamp)) {
160 return false;
161 }
162 return true;
163 }
164
165 @Override
166 @SuppressWarnings("nls")
167 public String toString() {
168 return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
169 }
170
171 }
This page took 0.034278 seconds and 5 git commands to generate.