lttng: More luna annotation updates
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfCheckpoint.java
CommitLineData
8c8bf09f 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 Ericsson
6256d8ad 3 *
8c8bf09f
ASL
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
6256d8ad 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
5d837f9b 11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
ea271da6 12 * Patrick Tasse - Updated for location in checkpoint
5d837f9b 13 ******************************************************************************/
8c8bf09f 14
6c13869b 15package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 16
3bd46eef 17import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
8c8bf09f
ASL
18
19/**
2848c377
FC
20 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
21 * to a generic location.
6256d8ad 22 *
f7703ed6
FC
23 * @version 1.0
24 * @author Francois Chouinard
25 *
f7703ed6
FC
26 * @see ITmfLocation
27 * @see ITmfTimestamp
8c8bf09f 28 */
a12b0e0f 29public class TmfCheckpoint implements ITmfCheckpoint {
8c8bf09f
ASL
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
cbdacf03 34
ea271da6
PT
35 // The checkpoint location
36 private final ITmfLocation fLocation;
5d837f9b
FC
37
38 // The checkpoint timestamp
a12b0e0f 39 private final ITmfTimestamp fTimestamp;
8c8bf09f
ASL
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
8c8bf09f 45 /**
5d837f9b 46 * Full constructor
6256d8ad 47 *
5d837f9b 48 * @param timestamp the checkpoint timestamp
3bd46eef 49 * @param location the corresponding trace location
ea271da6 50 * @since 2.0
8c8bf09f 51 */
ea271da6 52 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) {
5d837f9b 53 fTimestamp = timestamp;
ea271da6 54 fLocation = location;
8c8bf09f
ASL
55 }
56
ff4ed569 57 /**
5d837f9b 58 * Copy constructor
6256d8ad 59 *
ff4ed569
FC
60 * @param other the other checkpoint
61 */
cbdacf03 62 public TmfCheckpoint(final TmfCheckpoint other) {
0316808c 63 if (other == null) {
cbdacf03 64 throw new IllegalArgumentException();
0316808c 65 }
5d837f9b 66 fTimestamp = other.fTimestamp;
ea271da6 67 fLocation = other.fLocation;
5d837f9b
FC
68 }
69
8c8bf09f 70 // ------------------------------------------------------------------------
8ca8c4f1 71 // ITmfCheckpoint
8c8bf09f
ASL
72 // ------------------------------------------------------------------------
73
3bd46eef
AM
74 /**
75 * @since 2.0
8c8bf09f 76 */
5d837f9b 77 @Override
4df4581d 78 public ITmfTimestamp getTimestamp() {
8c8bf09f
ASL
79 return fTimestamp;
80 }
81
37419bf3 82 @Override
1e1bef82 83 public ITmfLocation getLocation() {
ea271da6 84 return fLocation;
8c8bf09f
ASL
85 }
86
cbd4ad82 87 // ------------------------------------------------------------------------
5d837f9b 88 // Comparable
cbd4ad82
FC
89 // ------------------------------------------------------------------------
90
550d787e 91 @Override
ff1ccee6 92 @SuppressWarnings({ "unchecked", "rawtypes" })
5d837f9b 93 public int compareTo(final ITmfCheckpoint other) {
3eade83c
BH
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
cbdacf03 101 }
3eade83c 102
ea271da6 103 if ((fLocation == null) && (other.getLocation() == null)) {
3eade83c
BH
104 return 0;
105 }
106
107 // treat location of other as null location which is before any location
ea271da6 108 if ((fLocation != null) && (other.getLocation() == null)) {
3eade83c
BH
109 return 1;
110 }
111
112 // treat this as null location which is before any other locations
ea271da6 113 if ((fLocation == null) && (other.getLocation() != null)) {
3eade83c
BH
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);
550d787e 121 }
cbdacf03 122
5d837f9b
FC
123 // ------------------------------------------------------------------------
124 // Object
125 // ------------------------------------------------------------------------
126
cbd4ad82
FC
127 @Override
128 public int hashCode() {
5d837f9b
FC
129 final int prime = 31;
130 int result = 1;
ea271da6 131 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
5d837f9b
FC
132 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
133 return result;
cbd4ad82 134 }
cbdacf03 135
cbd4ad82 136 @Override
5d837f9b 137 public boolean equals(final Object obj) {
0316808c 138 if (this == obj) {
5d837f9b 139 return true;
0316808c
FC
140 }
141 if (obj == null) {
5d837f9b 142 return false;
0316808c
FC
143 }
144 if (!(obj instanceof TmfCheckpoint)) {
cbdacf03 145 return false;
0316808c 146 }
5d837f9b 147 final TmfCheckpoint other = (TmfCheckpoint) obj;
ea271da6
PT
148 if (fLocation == null) {
149 if (other.fLocation != null) {
5d837f9b 150 return false;
0316808c 151 }
ea271da6 152 } else if (!fLocation.equals(other.fLocation)) {
5d837f9b 153 return false;
0316808c 154 }
5d837f9b 155 if (fTimestamp == null) {
0316808c 156 if (other.fTimestamp != null) {
5d837f9b 157 return false;
0316808c
FC
158 }
159 } else if (!fTimestamp.equals(other.fTimestamp)) {
5d837f9b 160 return false;
0316808c 161 }
5d837f9b 162 return true;
cbd4ad82 163 }
cbdacf03 164
ff4ed569 165 @Override
3b38ea61 166 @SuppressWarnings("nls")
ff4ed569 167 public String toString() {
ea271da6 168 return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
8c8bf09f
ASL
169 }
170
171}
This page took 0.0571390000000001 seconds and 5 git commands to generate.