Make the TmfLocation final and get rid of clone()
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / trace / TmfLocationArray.java
index 41c35566f332f9f47ce2589c75bd0faecc98cd2f..4d3c5fb616b55f80ba0709a5366a68bee27a2ec7 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Arrays;
 
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 
+
 /**
  * A convenience class to store trace location arrays. The main purpose is to
  * provide a Comparable implementation for TmfExperimentLocation.
@@ -24,7 +25,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
  * @version 1.0
  * @author Patrick Tasse
  */
-public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable {
+public final class TmfLocationArray implements Comparable<TmfLocationArray> {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -45,34 +46,36 @@ public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable
         fLocations = locations;
     }
 
-    // ------------------------------------------------------------------------
-    // Getters
-    // ------------------------------------------------------------------------
-
     /**
-     * Get the locations inside this array
+     * The "update" constructor. Copies the array of locations and updates
+     * a single entry.
      *
-     * @return the locations
+     * @param locations the locations
+     * @param index the entry to modify
+     * @param location the new entry
      */
-    public ITmfLocation[] getLocations() {
-        return fLocations;
+    public TmfLocationArray(TmfLocationArray locations, int index, ITmfLocation location) {
+        assert(locations != null && index >= 0 && index < locations.fLocations.length);
+        fLocations = Arrays.copyOf(locations.fLocations, locations.fLocations.length);
+        fLocations[index] = location;
     }
 
     // ------------------------------------------------------------------------
-    // Cloneable
+    // Getters
     // ------------------------------------------------------------------------
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#clone()
+    /**
+     * Get a specific location
+     *
+     * @param index the location element
+     *
+     * @return the specific location (possibly null)
      */
-    @Override
-    public TmfLocationArray clone() {
-        ITmfLocation[] clones = new ITmfLocation[fLocations.length];
-        for (int i = 0; i < fLocations.length; i++) {
-            ITmfLocation location = fLocations[i];
-            clones[i] = (location != null) ? location.clone() : null;
+    public ITmfLocation getLocation(int index) {
+        if (fLocations != null && index >= 0 && index < fLocations.length) {
+            return fLocations[index];
         }
-        return new TmfLocationArray(clones);
+        return null;
     }
 
     // ------------------------------------------------------------------------
This page took 0.024475 seconds and 5 git commands to generate.