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
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 // The checkpoint context
35 private final ITmfContext fContext
;
37 // The checkpoint timestamp
38 private final ITmfTimestamp fTimestamp
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
47 * @param timestamp the checkpoint timestamp
48 * @param context the corresponding trace location
50 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfContext context
) {
51 fTimestamp
= timestamp
;
58 * @param other the other checkpoint
60 public TmfCheckpoint(final TmfCheckpoint other
) {
62 throw new IllegalArgumentException();
64 fTimestamp
= other
.fTimestamp
;
65 fContext
= other
.fContext
;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
76 public ITmfTimestamp
getTimestamp() {
81 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
84 public ITmfContext
getContext() {
89 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
92 public ITmfLocation
getLocation() {
93 return fContext
.getLocation();
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
103 * Compares the checkpoints timestamp. If either is null, compares the
104 * trace checkpoints locations.
107 @SuppressWarnings({ "unchecked", "rawtypes" })
108 public int compareTo(final ITmfCheckpoint other
) {
110 if ((fTimestamp
!= null) && (other
.getTimestamp() != null)) {
111 comp
= fTimestamp
.compareTo(other
.getTimestamp(), false);
115 // compare locations if timestamps are the same
118 if ((getContext() == null) && (other
.getContext() == null)) {
122 // treat location of other as null location which is before any location
123 if ((getContext() != null) && (other
.getContext() == null)) {
127 // treat this as null location which is before any other locations
128 if ((getContext() == null) && (other
.getContext() != null)) {
133 final Comparable location1
= getLocation().getLocationInfo();
134 final Comparable location2
= other
.getLocation().getLocationInfo();
135 return location1
.compareTo(location2
);
138 // ------------------------------------------------------------------------
140 // ------------------------------------------------------------------------
143 * @see java.lang.Object#hashCode()
146 public int hashCode() {
147 final int prime
= 31;
149 result
= prime
* result
+ ((fContext
== null) ?
0 : fContext
.hashCode());
150 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
155 * @see java.lang.Object#equals(java.lang.Object)
158 public boolean equals(final Object obj
) {
165 if (!(obj
instanceof TmfCheckpoint
)) {
168 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
169 if (fContext
== null) {
170 if (other
.fContext
!= null) {
173 } else if (!fContext
.equals(other
.fContext
)) {
176 if (fTimestamp
== null) {
177 if (other
.fTimestamp
!= null) {
180 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
187 * @see java.lang.Object#toString()
190 @SuppressWarnings("nls")
191 public String
toString() {
192 return "TmfCheckpoint [fContext=" + fContext
+ ", fTimestamp=" + fTimestamp
+ "]";
This page took 0.035364 seconds and 5 git commands to generate.