1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 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 ******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
19 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
20 * to a generic location.
23 * @author Francois Chouinard
28 public class TmfCheckpoint
implements ITmfCheckpoint
, Cloneable
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 // The checkpoint context
35 private ITmfContext fContext
;
37 // The checkpoint timestamp
38 private ITmfTimestamp fTimestamp
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
47 @SuppressWarnings("unused")
48 private TmfCheckpoint() {
54 * @param timestamp the checkpoint timestamp
55 * @param context the corresponding trace location
57 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfContext context
) {
58 fTimestamp
= timestamp
;
65 * @param other the other checkpoint
67 public TmfCheckpoint(final TmfCheckpoint other
) {
69 throw new IllegalArgumentException();
71 fTimestamp
= other
.fTimestamp
;
72 fContext
= other
.fContext
;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * @see java.lang.Object#clone()
83 public TmfCheckpoint
clone() {
84 TmfCheckpoint clone
= null;
86 clone
= (TmfCheckpoint
) super.clone();
87 clone
.fContext
= (fContext
!= null) ? fContext
.clone() : null;
88 clone
.fTimestamp
= fTimestamp
;
89 } catch (final CloneNotSupportedException e
) {
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
102 public ITmfTimestamp
getTimestamp() {
107 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
110 public ITmfContext
getContext() {
115 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
118 public ITmfLocation
getLocation() {
119 return fContext
.getLocation();
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
129 * Compares the checkpoints timestamp. If either is null, compares the
130 * trace checkpoints locations.
133 @SuppressWarnings({ "unchecked", "rawtypes" })
134 public int compareTo(final ITmfCheckpoint other
) {
136 if ((fTimestamp
!= null) && (other
.getTimestamp() != null)) {
137 comp
= fTimestamp
.compareTo(other
.getTimestamp(), false);
141 // compare locations if timestamps are the same
144 if ((getContext() == null) && (other
.getContext() == null)) {
148 // treat location of other as null location which is before any location
149 if ((getContext() != null) && (other
.getContext() == null)) {
153 // treat this as null location which is before any other locations
154 if ((getContext() == null) && (other
.getContext() != null)) {
159 final Comparable location1
= getLocation().getLocationInfo();
160 final Comparable location2
= other
.getLocation().getLocationInfo();
161 return location1
.compareTo(location2
);
164 // ------------------------------------------------------------------------
166 // ------------------------------------------------------------------------
169 * @see java.lang.Object#hashCode()
172 public int hashCode() {
173 final int prime
= 31;
175 result
= prime
* result
+ ((fContext
== null) ?
0 : fContext
.hashCode());
176 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
181 * @see java.lang.Object#equals(java.lang.Object)
184 public boolean equals(final Object obj
) {
191 if (!(obj
instanceof TmfCheckpoint
)) {
194 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
195 if (fContext
== null) {
196 if (other
.fContext
!= null) {
199 } else if (!fContext
.equals(other
.fContext
)) {
202 if (fTimestamp
== null) {
203 if (other
.fTimestamp
!= null) {
206 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
213 * @see java.lang.Object#toString()
216 @SuppressWarnings("nls")
217 public String
toString() {
218 return "TmfCheckpoint [fContext=" + fContext
+ ", fTimestamp=" + fTimestamp
+ "]";