X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Finternal%2Ftmf%2Fcore%2Ftrace%2FTmfLocationArray.java;h=4d3c5fb616b55f80ba0709a5366a68bee27a2ec7;hb=d62bb1853c3388385d5ce10b0302b3dde139c3ab;hp=c781fe0974ecf173c7b78cc5db1a2072b8332738;hpb=024e3f3b3d75dbdaa74ff3c1cfbe5d82d84401b4;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java index c781fe0974..4d3c5fb616 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2011, 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 * 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 @@ -17,20 +17,21 @@ 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. - * + * * @version 1.0 * @author Patrick Tasse */ -public class TmfLocationArray implements Comparable, Cloneable { +public final class TmfLocationArray implements Comparable { // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - private ITmfLocation>[] fLocations; + private final ITmfLocation[] fLocations; // ------------------------------------------------------------------------ // Constructors @@ -38,40 +39,43 @@ public class TmfLocationArray implements Comparable, Cloneable /** * The standard constructor - * + * * @param locations the locations */ - public TmfLocationArray(ITmfLocation>[] locations) { + public TmfLocationArray(ITmfLocation[] locations) { fLocations = locations; } - // ------------------------------------------------------------------------ - // Getters - // ------------------------------------------------------------------------ - /** - * The standard constructor - * + * The "update" constructor. Copies the array of locations and updates + * a single entry. + * * @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 = (ITmfLocation>[]) new ITmfLocation[fLocations.length]; - for (int i = 0; i < fLocations.length; i++) { - clones[i] = fLocations[i].clone(); + public ITmfLocation getLocation(int index) { + if (fLocations != null && index >= 0 && index < fLocations.length) { + return fLocations[index]; } - return new TmfLocationArray(clones); + return null; } // ------------------------------------------------------------------------ @@ -82,9 +86,9 @@ public class TmfLocationArray implements Comparable, Cloneable @SuppressWarnings({ "unchecked", "rawtypes" }) public int compareTo(TmfLocationArray o) { for (int i = 0; i < fLocations.length; i++) { - ITmfLocation l1 = (ITmfLocation) fLocations[i].getLocation(); - ITmfLocation l2 = (ITmfLocation) o.fLocations[i].getLocation(); - int result = l1.getLocation().compareTo(l2.getLocation()); + Comparable l1 = fLocations[i].getLocationInfo(); + Comparable l2 = o.fLocations[i].getLocationInfo(); + int result = l1.compareTo(l2); if (result != 0) { return result; }