Refactor ITmfContext and fix dependencies
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfContext.java
index bd5b10eb055265b3d2315035f7374c2f7798e38a..173a9b69da7495f33ed0976fbb690de09395043b 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 2012 Ericsson
  * 
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  * 
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.trace;
@@ -21,110 +22,180 @@ package org.eclipse.linuxtools.tmf.core.trace;
  */
 public class TmfContext implements ITmfContext, Cloneable {
 
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    // The trace location
     private ITmfLocation<? extends Comparable<?>> fLocation;
+
+    // The event rank
     private long fRank;
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
-    public TmfContext(ITmfLocation<? extends Comparable<?>> loc, long rank) {
-        fLocation = loc;
-        fRank = rank;
+    /**
+     * Default constructor
+     */
+    public TmfContext() {
+        this(null, UNKNOWN_RANK);
     }
 
+    /**
+     * Simple constructor (unknown rank)
+     * 
+     * @param location the event location
+     */
     public TmfContext(ITmfLocation<? extends Comparable<?>> location) {
         this(location, UNKNOWN_RANK);
     }
 
-    public TmfContext(TmfContext other) {
-        this(other.fLocation, other.fRank);
+    /**
+     * Full constructor
+     * 
+     * @param location the event location
+     * @param rank the event rank
+     */
+    public TmfContext(ITmfLocation<? extends Comparable<?>> location, long rank) {
+        fLocation = location;
+        fRank = rank;
     }
 
-    public TmfContext() {
-        this(null, UNKNOWN_RANK);
+    /**
+     * Copy constructor
+     * 
+     * @param context the other context
+     */
+    public TmfContext(TmfContext context) {
+        this(context.fLocation, context.fRank);
+    }
+
+    // ------------------------------------------------------------------------
+    // Cloneable
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public TmfContext clone() {
+        TmfContext clone = null;
+        try {
+            clone = (TmfContext) super.clone();
+            clone.fLocation = fLocation.clone();
+            clone.fRank = fRank;
+        } catch (CloneNotSupportedException e) {
+        }
+        return clone;
     }
 
     // ------------------------------------------------------------------------
     // ITmfContext
     // ------------------------------------------------------------------------
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
+     */
     @Override
-    public void dispose() {
-        // override if necessary
+    public ITmfLocation<? extends Comparable<?>> getLocation() {
+        return fLocation;
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
+     */
     @Override
     public void setLocation(ITmfLocation<? extends Comparable<?>> location) {
         fLocation = location;
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
+     */
     @Override
-    public ITmfLocation<? extends Comparable<?>> getLocation() {
-        return fLocation;
+    public long getRank() {
+        return fRank;
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
+     */
     @Override
     public void setRank(long rank) {
         fRank = rank;
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
+     */
     @Override
-    public long getRank() {
-        return fRank;
+    public void increaseRank() {
+        if (hasValidRank())
+            fRank++;
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
+     */
     @Override
-    public void updateRank(int delta) {
-        if (isValidRank())
-            fRank += delta;
+    public boolean hasValidRank() {
+        return fRank != UNKNOWN_RANK;
     }
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
+     */
     @Override
-    public boolean isValidRank() {
-        return fRank != UNKNOWN_RANK;
+    public void dispose() {
     }
 
     // ------------------------------------------------------------------------
     // Object
     // ------------------------------------------------------------------------
 
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
     @Override
     public int hashCode() {
-        int result = 17;
-        result = 37 * result + fLocation.hashCode();
-        result = 37 * result + (int) (fRank ^ (fRank >>> 32));
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
+        result = prime * result + (int) (fRank ^ (fRank >>> 32));
         return result;
     }
 
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
     @Override
-    public boolean equals(Object other) {
-        if (other == this) {
+    public boolean equals(Object obj) {
+        if (this == obj)
             return true;
-        }
-        if (!(other instanceof TmfContext)) {
+        if (obj == null)
             return false;
-        }
-        TmfContext o = (TmfContext) other;
-        return fLocation.equals(o.fLocation) && (fRank == o.fRank);
+        if (getClass() != obj.getClass())
+            return false;
+        TmfContext other = (TmfContext) obj;
+        if (fLocation == null) {
+            if (other.fLocation != null)
+                return false;
+        } else if (!fLocation.equals(other.fLocation))
+            return false;
+        if (fRank != other.fRank)
+            return false;
+        return true;
     }
 
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
     @Override
     @SuppressWarnings("nls")
     public String toString() {
-        return "[TmfContext(" + fLocation.toString() + "," + fRank + ")]";
-    }
-
-    @Override
-    public TmfContext clone() {
-        TmfContext clone = null;
-        try {
-            clone = (TmfContext) super.clone();
-            clone.fLocation = fLocation.clone();
-            clone.fRank = fRank;
-        } catch (CloneNotSupportedException e) {
-        }
-        return clone;
+        return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
     }
 
 }
This page took 0.026322 seconds and 5 git commands to generate.