Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / indexer / checkpoint / 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.indexer.checkpoint;
16
17 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
18 import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
19
20 /**
21 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
22 * to a generic location.
23 *
24 * @see ITmfLocation
25 * @see ITmfTimestamp
26 *
27 * @author Francois Chouinard
28 * @since 3.0
29 */
30 public class TmfCheckpoint implements ITmfCheckpoint {
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35
36 // The checkpoint location
37 private final ITmfLocation fLocation;
38
39 // The checkpoint timestamp
40 private final ITmfTimestamp fTimestamp;
41
42 // ------------------------------------------------------------------------
43 // Constructors
44 // ------------------------------------------------------------------------
45
46 /**
47 * Full constructor
48 *
49 * @param timestamp the checkpoint timestamp
50 * @param location the corresponding trace location
51 * @since 3.0
52 */
53 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) {
54 fTimestamp = timestamp;
55 fLocation = location;
56 }
57
58 /**
59 * Copy constructor
60 *
61 * @param other the other checkpoint
62 */
63 public TmfCheckpoint(final TmfCheckpoint other) {
64 if (other == null) {
65 throw new IllegalArgumentException();
66 }
67 fTimestamp = other.fTimestamp;
68 fLocation = other.fLocation;
69 }
70
71 // ------------------------------------------------------------------------
72 // ITmfCheckpoint
73 // ------------------------------------------------------------------------
74
75 /**
76 * @since 2.0
77 */
78 @Override
79 public ITmfTimestamp getTimestamp() {
80 return fTimestamp;
81 }
82
83 @Override
84 public ITmfLocation getLocation() {
85 return fLocation;
86 }
87
88 // ------------------------------------------------------------------------
89 // Comparable
90 // ------------------------------------------------------------------------
91
92 @Override
93 @SuppressWarnings({ "unchecked", "rawtypes" })
94 public int compareTo(final ITmfCheckpoint other) {
95 int comp = 0;
96 if ((fTimestamp != null) && (other.getTimestamp() != null)) {
97 comp = fTimestamp.compareTo(other.getTimestamp(), false);
98 if (comp != 0) {
99 return comp;
100 }
101 // compare locations if timestamps are the same
102 }
103
104 if ((fLocation == null) && (other.getLocation() == null)) {
105 return 0;
106 }
107
108 // treat location of other as null location which is before any location
109 if ((fLocation != null) && (other.getLocation() == null)) {
110 return 1;
111 }
112
113 // treat this as null location which is before any other locations
114 if ((fLocation == null) && (other.getLocation() != null)) {
115 return -1;
116 }
117
118 // compare location
119 final Comparable location1 = getLocation().getLocationInfo();
120 final Comparable location2 = other.getLocation().getLocationInfo();
121 return location1.compareTo(location2);
122 }
123
124 // ------------------------------------------------------------------------
125 // Object
126 // ------------------------------------------------------------------------
127
128 @Override
129 public int hashCode() {
130 final int prime = 31;
131 int result = 1;
132 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
133 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
134 return result;
135 }
136
137 @Override
138 public boolean equals(final Object obj) {
139 if (this == obj) {
140 return true;
141 }
142 if (obj == null) {
143 return false;
144 }
145 if (!(obj instanceof TmfCheckpoint)) {
146 return false;
147 }
148 final TmfCheckpoint other = (TmfCheckpoint) obj;
149 if (fLocation == null) {
150 if (other.fLocation != null) {
151 return false;
152 }
153 } else if (!fLocation.equals(other.fLocation)) {
154 return false;
155 }
156 if (fTimestamp == null) {
157 if (other.fTimestamp != null) {
158 return false;
159 }
160 } else if (!fTimestamp.equals(other.fTimestamp)) {
161 return false;
162 }
163 return true;
164 }
165
166 @Override
167 @SuppressWarnings("nls")
168 public String toString() {
169 return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
170 }
171
172 }
This page took 0.037841 seconds and 6 git commands to generate.