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