tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / trace / TmfLocationArray.java
index 06a324528abf723604a632fe8a92eefb7e030889..13deef2d00934425e74d6aa844f357dd93f66bd6 100644 (file)
@@ -1,14 +1,15 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
- * 
+ * Copyright (c) 2011, 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:
  * Patrick Tasse - Initial API and implementation
  * Francois Chouinard - Put in shape for 1.0
+ * Patrick Tasse - Updated for ranks in experiment location
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.core.trace;
@@ -17,32 +18,61 @@ 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.
- * 
+ * provide an immutable and Comparable implementation for TmfExperimentLocation.
+ *
  * @version 1.0
  * @author Patrick Tasse
  */
-public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable {
+public final class TmfLocationArray implements Comparable<TmfLocationArray> {
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
 
-    private ITmfLocation<? extends Comparable<?>>[] fLocations;
+    private final ITmfLocation[] fLocations;
+    private final long [] fRanks;
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
     /**
-     * The standard constructor
-     * 
+     * The standard constructor.
+     *
      * @param locations the locations
+     * @param ranks the ranks
+     */
+    public TmfLocationArray(ITmfLocation[] locations, long[] ranks) {
+        fLocations = Arrays.copyOf(locations, locations.length);
+        fRanks = Arrays.copyOf(ranks, ranks.length);
+    }
+
+    /**
+     * The update constructor. Copies the arrays and updates a single entry.
+     *
+     * @param locationArray the location array
+     * @param index the updated index
+     * @param location the updated location
+     * @param rank the updated rank
      */
-    public TmfLocationArray(ITmfLocation<? extends Comparable<?>>[] locations) {
-        fLocations = locations;
+    public TmfLocationArray(TmfLocationArray locationArray, int index, ITmfLocation location, long rank) {
+        fLocations = Arrays.copyOf(locationArray.fLocations, locationArray.fLocations.length);
+        fLocations[index] = location;
+        fRanks = Arrays.copyOf(locationArray.fRanks, locationArray.fRanks.length);
+        fRanks[index] = rank;
+    }
+
+    /**
+     * The empty constructor.
+     *
+     * @param size the number of elements in the array
+     */
+    public TmfLocationArray(int size) {
+        fLocations = new ITmfLocation[size];
+        fRanks = new long[size];
     }
 
     // ------------------------------------------------------------------------
@@ -50,29 +80,58 @@ public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable
     // ------------------------------------------------------------------------
 
     /**
-     * The standard constructor
-     * 
-     * @param locations the locations
+     * Returns the number of elements in this array.
+     *
+     * @return the number of elements in this array
      */
-    public ITmfLocation<? extends Comparable<?>>[] getLocations() {
-        return fLocations;
+    public int size() {
+        return fLocations.length;
     }
 
-    // ------------------------------------------------------------------------
-    // Cloneable
-    // ------------------------------------------------------------------------
+    /**
+     * Get the locations inside this array.
+     *
+     * @return a copy of the locations array
+     */
+    public ITmfLocation[] getLocations() {
+        return Arrays.copyOf(fLocations, fLocations.length);
+    }
 
-    /* (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<? extends Comparable<?>>[] clones = (ITmfLocation<? extends Comparable<?>>[]) 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 (index >= 0 && index < fLocations.length) {
+            return fLocations[index];
         }
-        return new TmfLocationArray(clones);
+        return null;
+    }
+
+    /**
+     * Get the ranks inside this array.
+     *
+     * @return a copy of the ranks array
+     */
+    public long[] getRanks() {
+        return Arrays.copyOf(fRanks, fRanks.length);
+    }
+
+    /**
+     * Get a specific rank
+     *
+     * @param index the rank element
+     *
+     * @return the specific rank
+     */
+    public long getRank(int index) {
+        if (index >= 0 && index < fRanks.length) {
+            return fRanks[index];
+        }
+        return 0;
     }
 
     // ------------------------------------------------------------------------
@@ -80,12 +139,11 @@ public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable
     // ------------------------------------------------------------------------
 
     @Override
-    @SuppressWarnings({ "unchecked", "rawtypes" })
     public int compareTo(TmfLocationArray o) {
-        for (int i = 0; i < fLocations.length; i++) {
-            ITmfLocation<? extends Comparable> l1 = (ITmfLocation<? extends Comparable>) fLocations[i].getLocation();
-            ITmfLocation<? extends Comparable> l2 = (ITmfLocation<? extends Comparable>) o.fLocations[i].getLocation();
-            int result = l1.getLocation().compareTo(l2.getLocation());
+        for (int i = 0; i < fRanks.length; i++) {
+            Long rank1 = fRanks[i];
+            Long rank2 = o.fRanks[i];
+            int result = rank1.compareTo(rank2);
             if (result != 0) {
                 return result;
             }
@@ -97,20 +155,15 @@ public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable
     // Object
     // ------------------------------------------------------------------------
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result + Arrays.hashCode(fLocations);
+        result = prime * result + Arrays.hashCode(fRanks);
         return result;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
     public boolean equals(Object obj) {
         if (this == obj) {
@@ -126,16 +179,25 @@ public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable
         if (!Arrays.equals(fLocations, other.fLocations)) {
             return false;
         }
+        if (!Arrays.equals(fRanks, other.fRanks)) {
+            return false;
+        }
         return true;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#toString()
-     */
     @Override
     @SuppressWarnings("nls")
     public String toString() {
-        return "TmfLocationArray [locations=" + Arrays.toString(fLocations) + "]";
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName() + " [");
+        for (int i = 0; i < fLocations.length; i++) {
+            if (i > 0) {
+                sb.append(", ");
+            }
+            sb.append("[location=" + fLocations[i] + ",rank=" + fRanks[i] + "]");
+        }
+        sb.append("]");
+        return sb.toString();
     }
 
 }
This page took 0.026509 seconds and 5 git commands to generate.