/*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 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: Matthew Khouzam - Initial API and implementation
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Alexandre Montplaisir - Extends TmfLocation
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.ctfadaptor;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation;
/**
- * The ctflocation is the nugget of information that is unique to a location in a trace.
- * it can be copied and used to restore a position in a given trace.
+ * The nugget of information that is unique to a location in a CTF trace.
+ *
+ * It can be copied and used to restore a position in a given trace.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
*/
-public class CtfLocation implements ITmfLocation<Long> {
+public final class CtfLocation extends TmfLocation {
- public static final Long INVALID_LOCATION = -1L;
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
/**
- * Constructor for CtfLocation.
- * @param location Long
+ * An invalid location
*/
- public CtfLocation(Long location) {
- setLocation(location);
- }
+ public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1);
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
/**
- * Constructor for CtfLocation.
- * @param timestamp ITmfTimestamp
+ * Basic constructor for CtfLocation. Uses a default index of 0.
+ *
+ * @param timestamp
+ * The timestamp of this location
+ * @since 2.0
*/
- public CtfLocation(ITmfTimestamp timestamp) {
- setLocation(timestamp.getValue());
+ public CtfLocation(final ITmfTimestamp timestamp) {
+ this(timestamp.getValue(), 0);
}
- private Long fTimestamp;
-
/**
- * Method setLocation.
- * @param location Long
+ * Constructor using timestamp object and index
+ *
+ * @param timestamp
+ * The timestamp of this location
+ * @param index
+ * The index of this location for this timestamp
+ * @since 2.0
*/
- public void setLocation(Long location) {
- this.fTimestamp = location;
+ public CtfLocation(final ITmfTimestamp timestamp, long index) {
+ this(timestamp.getValue(), index);
}
/**
- * Method getLocation.
- * @return Long
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
+ * Constructor using a long value for the timestamp, and an index
+ *
+ * @param timestampValue
+ * The new timestamp
+ * @param index
+ * The new index
+ * @since 2.0
*/
- @Override
- public Long getLocation() {
- return this.fTimestamp;
+ public CtfLocation(final long timestampValue, final long index) {
+ super(new CtfLocationInfo(timestampValue, index));
}
/**
- * Method clone.
- * @return CtfLocation
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#clone()
+ * Constructor using a pre-made locationInfo object
+ *
+ * @param locationInfo
+ * The locationInfo object to use
+ * @since 2.0
*/
- @Override
- public CtfLocation clone() {
- return new CtfLocation(getLocation());
+ public CtfLocation(CtfLocationInfo locationInfo) {
+ super(locationInfo);
}
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
+ /**
+ * Copy constructor
+ *
+ * @param location
+ * Other location to copy
+ * @since 2.0
*/
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = (prime * result)
- + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
- return result;
+ public CtfLocation(final CtfLocation location) {
+ super(location);
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
+ // ------------------------------------------------------------------------
+ // TmfLocation
+ // ------------------------------------------------------------------------
+
+ /**
+ * @since 2.0
*/
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof CtfLocation)) {
- return false;
- }
- CtfLocation other = (CtfLocation) obj;
- if (fTimestamp == null) {
- if (other.fTimestamp != null) {
- return false;
- }
- } else if (!fTimestamp.equals(other.fTimestamp)) {
- return false;
- }
- return true;
+ public CtfLocationInfo getLocationInfo() {
+ return (CtfLocationInfo) super.getLocationInfo();
}
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
@Override
public String toString() {
- if( this.getLocation().equals(CtfLocation.INVALID_LOCATION )) {
- return "CtfLocation: INVALID"; //$NON-NLS-1$
+ if( this.getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) {
+ return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$
}
- return "CtfLocation: " + getLocation().toString(); //$NON-NLS-1$
+ return super.toString();
}
}