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 * @return the checkpoint timestamp
96 public ITmfTimestamp
getTimestamp() {
101 * @return the checkpoint stream location
104 public ITmfLocation
<?
> getLocation() {
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
112 @SuppressWarnings({ "unchecked", "rawtypes" })
114 public int compareTo(final ITmfCheckpoint other
) {
115 if (fTimestamp
== null || other
.getTimestamp() == null) {
116 final Comparable location1
= fLocation
.getLocation();
117 final Comparable location2
= other
.getLocation().getLocation();
118 return location1
.compareTo(location2
);
120 return fTimestamp
.compareTo(other
.getTimestamp(), false);
123 // ------------------------------------------------------------------------
125 // ------------------------------------------------------------------------
128 public int hashCode() {
129 final int prime
= 31;
131 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
132 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
137 public boolean equals(final Object obj
) {
142 if (!(obj
instanceof TmfCheckpoint
))
144 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
145 if (fLocation
== null) {
146 if (other
.fLocation
!= null)
148 } else if (!fLocation
.equals(other
.fLocation
))
150 if (fTimestamp
== null) {
151 if (other
.fTimestamp
!= null)
153 } else if (!fTimestamp
.equals(other
.fTimestamp
))
159 @SuppressWarnings("nls")
160 public String
toString() {
161 return "TmfCheckpoint [fLocation=" + fLocation
+ ", fTimestamp=" + fTimestamp
+ "]";