/*******************************************************************************
- * Copyright (c) 2009 Ericsson
- *
+ * Copyright (c) 2009, 2013 Ericsson
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Francois Chouinard - Initial API and implementation
- *******************************************************************************/
+ * Francois Chouinard - Updated as per TMF Trace Model 1.0
+ * Patrick Tasse - Updated for location in checkpoint
+ ******************************************************************************/
package org.eclipse.linuxtools.tmf.core.trace;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
/**
- * <b><u>TmfCheckpoint</u></b>
- * <p>
- * This class maps an event timestamp to a generic location.
+ * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
+ * to a generic location.
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ *
+ * @see ITmfLocation
+ * @see ITmfTimestamp
*/
-@SuppressWarnings("rawtypes")
-public class TmfCheckpoint implements Comparable<TmfCheckpoint>, Cloneable {
+public class TmfCheckpoint implements ITmfCheckpoint {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
-
- private ITmfTimestamp fTimestamp;
- private ITmfLocation<? extends Comparable> fLocation;
+
+ // The checkpoint location
+ private final ITmfLocation fLocation;
+
+ // The checkpoint timestamp
+ private final ITmfTimestamp fTimestamp;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- @SuppressWarnings("unused")
- private TmfCheckpoint() {
- fTimestamp = null;
- fLocation = null;
- }
-
/**
- * @param ts the checkpoint timestamp
+ * Full constructor
+ *
+ * @param timestamp the checkpoint timestamp
* @param location the corresponding trace location
+ * @since 2.0
*/
- public TmfCheckpoint(ITmfTimestamp ts, ITmfLocation<? extends Comparable> location) {
- fTimestamp = ts;
+ public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) {
+ fTimestamp = timestamp;
fLocation = location;
}
/**
- * Deep copy constructor
+ * Copy constructor
+ *
* @param other the other checkpoint
*/
- public TmfCheckpoint(TmfCheckpoint other) {
- if (other == null)
- throw new IllegalArgumentException();
- fTimestamp = other.fTimestamp.clone();
- fLocation = other.fLocation.clone();
+ public TmfCheckpoint(final TmfCheckpoint other) {
+ if (other == null) {
+ throw new IllegalArgumentException();
+ }
+ fTimestamp = other.fTimestamp;
+ fLocation = other.fLocation;
}
// ------------------------------------------------------------------------
- // Accessors
+ // ITmfCheckpoint
// ------------------------------------------------------------------------
/**
- * @return the checkpoint timestamp
+ * @since 2.0
*/
+ @Override
public ITmfTimestamp getTimestamp() {
return fTimestamp;
}
- /**
- * @return the checkpoint stream location
- */
- public ITmfLocation<?> getLocation() {
+ @Override
+ public ITmfLocation getLocation() {
return fLocation;
}
// ------------------------------------------------------------------------
- // Object
+ // Comparable
// ------------------------------------------------------------------------
@Override
- public TmfCheckpoint clone() {
- TmfCheckpoint result = null;
- try {
- result = (TmfCheckpoint) super.clone();
- result.fTimestamp = fTimestamp.clone();
- result.fLocation = fLocation.clone();
- return result;
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- return result;
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public int compareTo(final ITmfCheckpoint other) {
+ int comp = 0;
+ if ((fTimestamp != null) && (other.getTimestamp() != null)) {
+ comp = fTimestamp.compareTo(other.getTimestamp(), false);
+ if (comp != 0) {
+ return comp;
+ }
+ // compare locations if timestamps are the same
+ }
+
+ if ((fLocation == null) && (other.getLocation() == null)) {
+ return 0;
+ }
+
+ // treat location of other as null location which is before any location
+ if ((fLocation != null) && (other.getLocation() == null)) {
+ return 1;
+ }
+
+ // treat this as null location which is before any other locations
+ if ((fLocation == null) && (other.getLocation() != null)) {
+ return -1;
+ }
+
+ // compare location
+ final Comparable location1 = getLocation().getLocationInfo();
+ final Comparable location2 = other.getLocation().getLocationInfo();
+ return location1.compareTo(location2);
}
-
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
@Override
public int hashCode() {
- return fTimestamp.hashCode();
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
+ result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
+ return result;
}
-
+
@Override
- public boolean equals(Object other) {
- if (!(other instanceof TmfCheckpoint)) {
- return false;
- }
- TmfCheckpoint o = (TmfCheckpoint) other;
- return fTimestamp.equals(o.fTimestamp);
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof TmfCheckpoint)) {
+ return false;
+ }
+ final TmfCheckpoint other = (TmfCheckpoint) obj;
+ if (fLocation == null) {
+ if (other.fLocation != null) {
+ return false;
+ }
+ } else if (!fLocation.equals(other.fLocation)) {
+ return false;
+ }
+ if (fTimestamp == null) {
+ if (other.fTimestamp != null) {
+ return false;
+ }
+ } else if (!fTimestamp.equals(other.fTimestamp)) {
+ return false;
+ }
+ return true;
}
-
+
@Override
@SuppressWarnings("nls")
public String toString() {
- return "[TmfCheckpoint(" + fTimestamp + "," + fLocation + ")]";
- }
-
- // ------------------------------------------------------------------------
- // Comparable
- // ------------------------------------------------------------------------
-
- @SuppressWarnings("unchecked")
- @Override
- public int compareTo(TmfCheckpoint other) {
- if (fTimestamp == null || other.fTimestamp == null) {
- return fLocation.getLocation().compareTo(other.fLocation.getLocation());
- }
- return fTimestamp.compareTo(other.fTimestamp, false);
+ return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
}
}