LTTng: CPU usage analysis from the LTTng kernel trace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfLocation.java
index bd7791c78e3d98238393dbdd2be849d5df1132b4..e59a2d35c35079a00b0bc19b1bdd4f73bf6f0b96 100644 (file)
@@ -1,17 +1,21 @@
 /*******************************************************************************
- * 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 java.nio.ByteBuffer;
+
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation;
 
 /**
  * The nugget of information that is unique to a location in a CTF trace.
@@ -21,27 +25,34 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
  * @version 1.0
  * @author Matthew Khouzam
  */
-public class CtfLocation implements ITmfLocation<CtfLocationData>, Cloneable {
+public final class CtfLocation extends TmfLocation {
 
-    private CtfLocationData fLocation;
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
 
     /**
      * An invalid location
      */
-    public static final CtfLocationData INVALID_LOCATION = new CtfLocationData(-1, -1);
+    public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1);
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
 
     /**
-     * Constructor for CtfLocation. Uses a default index of 0.
+     * 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(new CtfLocationData(timestamp.getValue(), 0));
+    public CtfLocation(final ITmfTimestamp timestamp) {
+        this(timestamp.getValue(), 0);
     }
 
     /**
-     * Standard constructor
+     * Constructor using timestamp object and index
      *
      * @param timestamp
      *            The timestamp of this location
@@ -49,111 +60,88 @@ public class CtfLocation implements ITmfLocation<CtfLocationData>, Cloneable {
      *            The index of this location for this timestamp
      * @since 2.0
      */
-    public CtfLocation(ITmfTimestamp timestamp, long index) {
-        setLocation(new CtfLocationData(timestamp.getValue(), index));
+    public CtfLocation(final ITmfTimestamp timestamp, long index) {
+        this(timestamp.getValue(), index);
     }
 
     /**
-     * Copy constructor
+     * Constructor using a long value for the timestamp, and an index
      *
-     * @param location
-     *            Other location to copy
+     * @param timestampValue
+     *            The new timestamp
+     * @param index
+     *            The new index
      * @since 2.0
      */
-    public CtfLocation(CtfLocationData location) {
-        setLocation(location);
+    public CtfLocation(final long timestampValue, final long index) {
+       super(new CtfLocationInfo(timestampValue, index));
     }
 
     /**
-     * Move this location to another location's position.
+     * Constructor using a pre-made locationInfo object
      *
-     * @param location
-     *            The location to seek to
+     * @param locationInfo
+     *            The locationInfo object to use
      * @since 2.0
      */
-    public void setLocation(CtfLocationData location) {
-        this.fLocation = location;
+    public CtfLocation(CtfLocationInfo locationInfo) {
+        super(locationInfo);
     }
 
     /**
-     * Change this location's timestamp and index values.
+     * Copy constructor
      *
-     * @param timestampValue
-     *            The new timestamp
-     * @param index
-     *            The new index
+     * @param location
+     *            Other location to copy
      * @since 2.0
      */
-    public void setLocation(long timestampValue, long index) {
-       this.fLocation = new CtfLocationData(timestampValue, index);
+    public CtfLocation(final CtfLocation location) {
+        super(location);
     }
 
+    // ------------------------------------------------------------------------
+    // TmfLocation
+    // ------------------------------------------------------------------------
 
     /**
-     * Get the Location Data of this location
+     * Construct the location from the ByteBuffer.
      *
-     * @return The CtfLocationData
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
-     * @since 2.0
+     * @param bufferIn
+     *            the buffer to read from
+     *
+     * @since 3.0
      */
-    @Override
-    public CtfLocationData getLocation() {
-        return fLocation;
+    public CtfLocation(ByteBuffer bufferIn) {
+        super(new CtfLocationInfo(bufferIn));
     }
 
-    @Override
-    public CtfLocation clone() {
-        return new CtfLocation(new CtfLocationData(fLocation.getTimestamp(), fLocation.getIndex()));
-    }
-
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
+    /**
+     * @since 2.0
      */
     @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = (prime * result)
-                + ((fLocation == null) ? 0 : fLocation.hashCode());
-        return result;
+    public CtfLocationInfo getLocationInfo() {
+        return (CtfLocationInfo) super.getLocationInfo();
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
     @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 (fLocation == null) {
-            if (other.fLocation != null) {
-                return false;
-            }
-        } else if (!fLocation.equals(other.fLocation)) {
-            return false;
+    public String toString() {
+        if (getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) {
+            return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$
         }
-        return true;
+        return super.toString();
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#toString()
+    /**
+     * Constructs the location from the ByteBuffer. This typically happens when reading from disk.
+     *
+     * @since 3.0
      */
     @Override
-    public String toString() {
-        if( this.getLocation().equals(CtfLocation.INVALID_LOCATION )) {
-            return "CtfLocation: INVALID"; //$NON-NLS-1$
-        }
-        return "CtfLocation: " + getLocation().toString(); //$NON-NLS-1$
+    public void serialize(ByteBuffer bufferOut) {
+        getLocationInfo().serialize(bufferOut);
     }
-
-
 }
This page took 0.048896 seconds and 5 git commands to generate.