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.
24 * @author Francois Chouinard
30 public class TmfCheckpoint
implements ITmfCheckpoint
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 // The checkpoint location
37 private ITmfLocation
<?
extends Comparable
<?
>> fLocation
;
39 // The checkpoint timestamp
40 private ITmfTimestamp fTimestamp
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
49 @SuppressWarnings("unused")
50 private TmfCheckpoint() {
56 * @param timestamp the checkpoint timestamp
57 * @param location the corresponding trace location
59 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation
<?
extends Comparable
<?
>> location
) {
60 fTimestamp
= timestamp
;
67 * @param other the other checkpoint
69 public TmfCheckpoint(final TmfCheckpoint other
) {
71 throw new IllegalArgumentException();
72 fTimestamp
= other
.fTimestamp
;
73 fLocation
= other
.fLocation
;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * @see java.lang.Object#clone()
84 public TmfCheckpoint
clone() {
85 TmfCheckpoint clone
= null;
87 clone
= (TmfCheckpoint
) super.clone();
88 clone
.fLocation
= (fLocation
!= null) ? fLocation
.clone() : null;
89 clone
.fTimestamp
= (fTimestamp
!= null) ? fTimestamp
.clone() : null;
90 } catch (final CloneNotSupportedException e
) {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
103 public ITmfTimestamp
getTimestamp() {
108 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
111 public ITmfLocation
<?
> getLocation() {
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
120 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
122 * Compares the checkpoints timestamp. If either is null, compares the
123 * trace checkpoints locations.
126 @SuppressWarnings({ "unchecked", "rawtypes" })
127 public int compareTo(final ITmfCheckpoint other
) {
128 if (fTimestamp
== null || other
.getTimestamp() == null) {
129 final Comparable location1
= fLocation
.getLocation();
130 final Comparable location2
= other
.getLocation().getLocation();
131 return location1
.compareTo(location2
);
133 return fTimestamp
.compareTo(other
.getTimestamp(), false);
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
141 * @see java.lang.Object#hashCode()
144 public int hashCode() {
145 final int prime
= 31;
147 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
148 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
153 * @see java.lang.Object#equals(java.lang.Object)
156 public boolean equals(final Object obj
) {
161 if (!(obj
instanceof TmfCheckpoint
))
163 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
164 if (fLocation
== null) {
165 if (other
.fLocation
!= null)
167 } else if (!fLocation
.equals(other
.fLocation
))
169 if (fTimestamp
== null) {
170 if (other
.fTimestamp
!= null)
172 } else if (!fTimestamp
.equals(other
.fTimestamp
))
178 * @see java.lang.Object#toString()
181 @SuppressWarnings("nls")
182 public String
toString() {
183 return "TmfCheckpoint [fLocation=" + fLocation
+ ", fTimestamp=" + fTimestamp
+ "]";