1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
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
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 ******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
20 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
21 * to a generic location.
24 * @author Francois Chouinard
29 public class TmfCheckpoint
implements ITmfCheckpoint
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 // The checkpoint location
36 private final ITmfLocation fLocation
;
38 // The checkpoint timestamp
39 private final ITmfTimestamp fTimestamp
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
48 * @param timestamp the checkpoint timestamp
49 * @param location the corresponding trace location
52 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation location
) {
53 fTimestamp
= timestamp
;
60 * @param other the other checkpoint
62 public TmfCheckpoint(final TmfCheckpoint other
) {
64 throw new IllegalArgumentException();
66 fTimestamp
= other
.fTimestamp
;
67 fLocation
= other
.fLocation
;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
78 public ITmfTimestamp
getTimestamp() {
83 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
86 public ITmfLocation
getLocation() {
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
97 * Compares the checkpoints timestamp. If either is null, compares the
98 * trace checkpoints locations.
101 @SuppressWarnings({ "unchecked", "rawtypes" })
102 public int compareTo(final ITmfCheckpoint other
) {
104 if ((fTimestamp
!= null) && (other
.getTimestamp() != null)) {
105 comp
= fTimestamp
.compareTo(other
.getTimestamp(), false);
109 // compare locations if timestamps are the same
112 if ((fLocation
== null) && (other
.getLocation() == null)) {
116 // treat location of other as null location which is before any location
117 if ((fLocation
!= null) && (other
.getLocation() == null)) {
121 // treat this as null location which is before any other locations
122 if ((fLocation
== null) && (other
.getLocation() != null)) {
127 final Comparable location1
= getLocation().getLocationInfo();
128 final Comparable location2
= other
.getLocation().getLocationInfo();
129 return location1
.compareTo(location2
);
132 // ------------------------------------------------------------------------
134 // ------------------------------------------------------------------------
137 * @see java.lang.Object#hashCode()
140 public int hashCode() {
141 final int prime
= 31;
143 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
144 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
149 * @see java.lang.Object#equals(java.lang.Object)
152 public boolean equals(final Object obj
) {
159 if (!(obj
instanceof TmfCheckpoint
)) {
162 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
163 if (fLocation
== null) {
164 if (other
.fLocation
!= null) {
167 } else if (!fLocation
.equals(other
.fLocation
)) {
170 if (fTimestamp
== null) {
171 if (other
.fTimestamp
!= null) {
174 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
181 * @see java.lang.Object#toString()
184 @SuppressWarnings("nls")
185 public String
toString() {
186 return getClass().getSimpleName() + " [fLocation=" + fLocation
+ ", fTimestamp=" + fTimestamp
+ "]";
This page took 0.034778 seconds and 5 git commands to generate.