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 * <b><u>TmfCheckpoint</u></b>
21 * This class maps an event timestamp to a generic location.
23 public class TmfCheckpoint
implements ITmfCheckpoint
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
29 // The checkpoint location
30 private ITmfLocation
<?
extends Comparable
<?
>> fLocation
;
32 // The checkpoint timestamp
33 private ITmfTimestamp fTimestamp
;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
42 @SuppressWarnings("unused")
43 private TmfCheckpoint() {
49 * @param timestamp the checkpoint timestamp
50 * @param location the corresponding trace location
52 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation
<?
extends Comparable
<?
>> location
) {
53 fTimestamp
= timestamp
;
60 * @param other the other checkpoint
62 public TmfCheckpoint(final TmfCheckpoint other
) {
64 throw new IllegalArgumentException();
65 fTimestamp
= other
.fTimestamp
;
66 fLocation
= other
.fLocation
;
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 * @see java.lang.Object#clone()
77 public TmfCheckpoint
clone() {
78 TmfCheckpoint clone
= null;
80 clone
= (TmfCheckpoint
) super.clone();
81 clone
.fLocation
= (fLocation
!= null) ? fLocation
.clone() : null;
82 clone
.fTimestamp
= (fTimestamp
!= null) ? fTimestamp
.clone() : null;
83 } catch (final CloneNotSupportedException e
) {
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
93 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
96 public ITmfTimestamp
getTimestamp() {
101 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
104 public ITmfLocation
<?
> getLocation() {
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
113 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
115 * Compares the checkpoints timestamp. If either is null, compares the
116 * trace checkpoints locations.
119 @SuppressWarnings({ "unchecked", "rawtypes" })
120 public int compareTo(final ITmfCheckpoint other
) {
121 if (fTimestamp
== null || other
.getTimestamp() == null) {
122 final Comparable location1
= fLocation
.getLocation();
123 final Comparable location2
= other
.getLocation().getLocation();
124 return location1
.compareTo(location2
);
126 return fTimestamp
.compareTo(other
.getTimestamp(), false);
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
134 * @see java.lang.Object#hashCode()
137 public int hashCode() {
138 final int prime
= 31;
140 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
141 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
146 * @see java.lang.Object#equals(java.lang.Object)
149 public boolean equals(final Object obj
) {
154 if (!(obj
instanceof TmfCheckpoint
))
156 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
157 if (fLocation
== null) {
158 if (other
.fLocation
!= null)
160 } else if (!fLocation
.equals(other
.fLocation
))
162 if (fTimestamp
== null) {
163 if (other
.fTimestamp
!= null)
165 } else if (!fTimestamp
.equals(other
.fTimestamp
))
171 * @see java.lang.Object#toString()
174 @SuppressWarnings("nls")
175 public String
toString() {
176 return "TmfCheckpoint [fLocation=" + fLocation
+ ", fTimestamp=" + fTimestamp
+ "]";