TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".util"); //$NON-NLS-1$);
//$JUnit-BEGIN$
suite.addTestSuite(PairTest.class);
- suite.addTestSuite(TmfFixedArrayTest.class);
//$JUnit-END$
return suite;
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011 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:
- * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.util;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
-
-/**
- * <b><u>TmfFixedArrayTest</u></b>
- *
- * Implement me. Please.
- */
-@SuppressWarnings({ "nls", "javadoc" })
-public class TmfFixedArrayTest extends TestCase {
-
- // ------------------------------------------------------------------------
- // Field(s)
- // ------------------------------------------------------------------------
- TmfFixedArray<String> fFixedArray1 = null;
- TmfFixedArray<String> fFixedArray2 = null;
- String fString1, fString2, fString3, fString4, fString5;
-
- // ------------------------------------------------------------------------
- // Housekeeping
- // ------------------------------------------------------------------------
-
- public TmfFixedArrayTest() {
- fString1 = "First String";
- fString2 = "Second String";
- fString3 = "Third String";
- fString4 = "Fourth String";
- fString5 = "Fifth String";
- fFixedArray1 = new TmfFixedArray<String>(fString1, fString2, fString3);
- // Empty array at the beginning
- fFixedArray2 = new TmfFixedArray<String>();
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- // ------------------------------------------------------------------------
- // Get
- // ------------------------------------------------------------------------
-
- public void testGet() {
- assertTrue("get", fString1.equals(fFixedArray1.get(0)));
- assertTrue("get", fString2.equals(fFixedArray1.get(1)));
- assertTrue("get", fString3.equals(fFixedArray1.get(2)));
-
- try {
- fFixedArray2.get(0);
- fail();
- } catch (ArrayIndexOutOfBoundsException e) {
- // Success
- }
- }
-
- public void testGetArray() {
- String[] stringArray = fFixedArray1.getArray();
- assertNotNull("getArray", stringArray);
- assertTrue("getArray", fString1.equals(stringArray[0]));
- assertTrue("getArray", fString2.equals(stringArray[1]));
- assertTrue("getArray", fString3.equals(stringArray[2]));
- }
-
- // ------------------------------------------------------------------------
- // Equals
- // ------------------------------------------------------------------------
-
- public void testEqualsReflexivity() {
- assertTrue("equals", fFixedArray1.equals(fFixedArray1));
- assertTrue("equals", fFixedArray2.equals(fFixedArray2));
-
- assertTrue("equals", !fFixedArray1.equals(fFixedArray2));
- assertTrue("equals", !fFixedArray2.equals(fFixedArray1));
- }
-
- public void testEqualsSymmetry() {
- TmfFixedArray<String> fixedArray1 = (TmfFixedArray<String>) fFixedArray1.clone();
- TmfFixedArray<String> fixedArray2 = (TmfFixedArray<String>) fFixedArray2.clone();
-
- assertTrue("equals", fixedArray1.equals(fFixedArray1));
- assertTrue("equals", fFixedArray1.equals(fixedArray1));
-
- assertTrue("equals", fixedArray2.equals(fFixedArray2));
- assertTrue("equals", fFixedArray2.equals(fixedArray2));
- }
-
- public void testEqualsTransivity() {
- TmfFixedArray<String> fixedArray1 = (TmfFixedArray<String>) fFixedArray1.clone();
- TmfFixedArray<String> fixedArray2 = (TmfFixedArray<String>) fFixedArray1.clone();
- TmfFixedArray<String> fixedArray3 = (TmfFixedArray<String>) fFixedArray1.clone();
-
- assertTrue("equals", fixedArray1.equals(fixedArray2));
- assertTrue("equals", fixedArray2.equals(fixedArray3));
- assertTrue("equals", fixedArray1.equals(fixedArray3));
- }
-
- public void testEqualsNull() {
- assertTrue("equals", !fFixedArray1.equals(null));
- assertTrue("equals", !fFixedArray2.equals(null));
- }
-
- // ------------------------------------------------------------------------
- // Append
- // ------------------------------------------------------------------------
-
- public void testAppend() {
- TmfFixedArray<String> fixedArray = new TmfFixedArray<String>();
-
- fixedArray = fixedArray.append(fString1, fString2, fString3);
- assertEquals("append", 3, fixedArray.size());
- assertTrue("append", fString1.equals(fixedArray.get(0)));
- assertTrue("append", fString2.equals(fixedArray.get(1)));
- assertTrue("append", fString3.equals(fixedArray.get(2)));
-
- fixedArray = fixedArray.append(fString4);
- assertEquals("append", 4, fixedArray.size());
- assertTrue("append", fString4.equals(fixedArray.get(3)));
- }
-
- @SuppressWarnings("unchecked")
- public void testAppendFixedArray() {
- TmfFixedArray<String> fixedArrayToAppend1 = new TmfFixedArray<String>(fString4);
- TmfFixedArray<String> fixedArrayToAppend2 = new TmfFixedArray<String>(fString5);
- TmfFixedArray<String> fixedArray = new TmfFixedArray<String>();
-
- fixedArray = fixedArray.append(fFixedArray1, fixedArrayToAppend1);
- assertEquals("append", 4, fixedArray.size());
- assertTrue("append", fString1.equals(fixedArray.get(0)));
- assertTrue("append", fString2.equals(fixedArray.get(1)));
- assertTrue("append", fString3.equals(fixedArray.get(2)));
- assertTrue("append", fString4.equals(fixedArray.get(3)));
-
- fixedArray = fixedArray.append(fixedArrayToAppend2);
- assertEquals("append", 5, fixedArray.size());
- assertTrue("append", fString5.equals(fixedArray.get(4)));
- }
-
- // ------------------------------------------------------------------------
- // hashCode
- // ------------------------------------------------------------------------
-
- public void testHashCode() {
- TmfFixedArray<String> fixedArray1 = (TmfFixedArray<String>) fFixedArray1.clone();
- TmfFixedArray<String> fixedArray2 = (TmfFixedArray<String>) fFixedArray2.clone();
-
- assertTrue("hashCode", fixedArray1.hashCode() == fFixedArray1.hashCode());
- assertTrue("hashCode", fFixedArray2.hashCode() == fixedArray2.hashCode());
-
- assertTrue("hashCode", fFixedArray1.hashCode() != fixedArray2.hashCode());
- assertTrue("hashCode", fFixedArray2.hashCode() != fixedArray1.hashCode());
- }
-
- // ------------------------------------------------------------------------
- // toArray
- // ------------------------------------------------------------------------
-
- public void testToArray() {
- String[] expected1 = { fString1, fString2, fString3 };
- assertTrue("toArray", Arrays.equals(expected1, fFixedArray1.toArray()));
-
- String[] expected2 = {};
- assertTrue("toArray", Arrays.equals(expected2, fFixedArray2.toArray()));
- }
-
- public void testToArrayArg() {
- String[] stringArray = new String[3];
- fFixedArray1.toArray(stringArray);
- assertTrue("toArrayArg", stringArray[0].equals(fFixedArray1.get(0)));
- assertTrue("toArrayArg", stringArray[1].equals(fFixedArray1.get(1)));
- assertTrue("toArrayArg", stringArray[2].equals(fFixedArray1.get(2)));
-
- String[] stringBigArray = new String[10];
- fFixedArray1.toArray(stringBigArray);
- assertNull("toArrayArg", stringBigArray[3]);
-
- TmfFixedArray<Object> fFixedArrayObject = new TmfFixedArray<Object>(fString1);
- stringArray = fFixedArrayObject.toArray(new String[0]);
- assertTrue("toArrayArg", stringArray[0].equals(fString1));
- }
-
- // ------------------------------------------------------------------------
- // Size
- // ------------------------------------------------------------------------
-
- public void testSize() {
- assertEquals("toArray", 3, fFixedArray1.size());
-
- assertEquals("toArray", 0, fFixedArray2.size());
- }
-
- // ------------------------------------------------------------------------
- // SubArray
- // ------------------------------------------------------------------------
-
- public void testSubArray() {
- TmfFixedArray<String> subArray = fFixedArray1.subArray(1);
-
- assertEquals("SubArray", 2, subArray.size());
- assertTrue("SubArray", fString2.equals(subArray.get(0)));
- assertTrue("SubArray", fString3.equals(subArray.get(1)));
- }
-
- public void testSubArray2() {
- TmfFixedArray<String> subArray = fFixedArray1.subArray(1, 2);
-
- assertEquals("SubArray", 2, subArray.size());
- assertTrue("SubArray", fString2.equals(subArray.get(0)));
- assertTrue("SubArray", fString3.equals(subArray.get(1)));
- }
-
- // ------------------------------------------------------------------------
- // Set
- // ------------------------------------------------------------------------
-
- public void testSet() {
- String[] newString = {"new FirstString", "new SecondString", "new ThirdString"};
-
- fFixedArray1.set(0, newString[0]);
- assertTrue("getArray", newString[0].equals(newString[0]));
-
- fFixedArray1.set(1, newString[1]);
- assertTrue("getArray", newString[1].equals(newString[1]));
-
- fFixedArray1.set(2, newString[2]);
- assertTrue("getArray", newString[2].equals(newString[2]));
-
- try {
- fFixedArray2.set(0, "newString");
- fail();
- } catch (Exception e) {
- // Success
- }
- }
-
- // ------------------------------------------------------------------------
- // toString
- // ------------------------------------------------------------------------
-
- public void testToString() {
- String expected1 = Arrays.asList(fString1, fString2, fString3).toString();
- assertEquals("toString", expected1, fFixedArray1.toString());
-
- String expected2 = Arrays.asList().toString();
- assertEquals("toString", expected2, fFixedArray2.toString());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * 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:
- * Francois Godin <copelnug@gmail.com> - Initial design and implementation
- * Mathieu Denis <mathieu.denis@polymtl.ca> - Correction and refactoring
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.util;
-
-import java.lang.reflect.Array;
-import java.util.AbstractList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.RandomAccess;
-
-/**
- * Allow to create a List object that contain an already existing array. Works
- * like {@link java.util.Arrays#asList} but contains more functions :
- * <ul>
- * <li>{@link #hashCode()}</li>
- * <li>{@link #equals(Object)}</li>
- * </ul>
- * Those functions allow to use the FixedArray as the key of a
- * {@link java.util.HashMap}.
- *
- * @version 1.0
- * @author Francois Godin
- *
- * @param <T>
- * Type of the array content.
- */
-public final class TmfFixedArray<T> extends AbstractList<T> implements RandomAccess, Cloneable {
- /**
- * Replace {@link java.util.Arrays#copyOf(Object[], int)} that do not exist
- * in java 5.
- *
- * @param <E>
- * Content of the array.
- * @param array
- * Original array to copy from.
- * @param newLength
- * Length of the copy to be returned.
- * @return A new array consisting of the elements specified.
- */
- private static <E> E[] copyOf(final E[] array, int newLength) {
- // FIXME Is it useful to use newInstance?
- E[] result = (E[]) Array.newInstance(array.getClass().getComponentType(), newLength);
- System.arraycopy(array, 0, result, 0, Math.min(array.length, newLength));
- return result;
- }
-
- /**
- * Replace {@link java.util.Arrays#copyOf(Object[], int, Class)} that do not
- * exist in java 5.
- *
- * @param <E>
- * Content of the array.
- * @param array
- * Original array to copy from.
- * @param newLength
- * Length of the copy to be returned.
- * @param newType
- * Type of the array to be returned.
- * @return A new array consisting of the elements specified.
- */
- private static <E, U> E[] copyOf(final U[] array, int newLength, Class<? extends E[]> newType) {
- E[] result = (E[])Array.newInstance(newType.getComponentType(), newLength);
- System.arraycopy(array, 0, result, 0, Math.min(array.length, newLength));
- return result;
- }
-
- /**
- * Replace {@link java.util.Arrays#copyOfRange(Object[], int, int)} that do
- * not exist in java 5.
- *
- * @param <E>
- * Content of the array.
- * @param array
- * Original array to copy from.
- * @param start
- * Starting position of the range, inclusive.
- * @param end
- * Ending position of the range, exclusive.
- * @return A new array consisting of the elements specified. The length of
- * the new array is equal to end-start
- */
- private static <E> E[] copyOfRange(final E[] array, int start, int end) {
- E[] result = (E[])Array.newInstance(array.getClass().getComponentType(), end - start);
- System.arraycopy(array, start, result, 0, end - start);
- return result;
- }
-
- /**
- * The array.
- */
- private final T[] fArray;
-
- /**
- * Constructor.
- *
- * @param array
- * Array to use. WILL NOT BE COPIED.
- */
- public TmfFixedArray(final T... array) {
- fArray = array;
- }
-
- /**
- * Append a FixedArray to this FixedArray.
- *
- * @param value
- * The FixedArray to append.
- * @return A new FixedArray with the elements of the two FixedArray.
- */
- public TmfFixedArray<T> append(final TmfFixedArray<T> value) {
- TmfFixedArray<T> result = new TmfFixedArray<T>(copyOf(fArray, fArray.length + value.size()));
- System.arraycopy(value.fArray, 0, result.fArray, fArray.length, value.fArray.length);
- return result;
- }
-
- /**
- * Append in order many FixedArray to this FixedArray.
- *
- * @param values
- * The FixedArrays to append.
- * @return A new FixedArray with the element of all the FixedArray.
- */
- public TmfFixedArray<T> append(final TmfFixedArray<T>... values) {
- int newLength = 0;
- for (TmfFixedArray<T> value : values) {
- newLength += value.size();
- }
- TmfFixedArray<T> result = new TmfFixedArray<T>(copyOf(fArray, fArray.length + newLength));
- newLength = fArray.length;
- for (TmfFixedArray<T> value : values) {
- System.arraycopy(value.fArray, 0, result.fArray, newLength, value.fArray.length);
- newLength += value.fArray.length;
- }
- return result;
- }
-
- /**
- * Append an element to the array.
- *
- * @param value
- * Element to append.
- * @return A new FixedArray with the element appended.
- */
- public TmfFixedArray<T> append(final T value) {
- TmfFixedArray<T> result = new TmfFixedArray<T>(copyOf(fArray, fArray.length + 1));
- result.set(fArray.length, value);
- return result;
- }
-
- /**
- * Append an array of element to the array.
- *
- * @param values
- * Elements array to append.
- * @return A new FixedArray with the elements appended.
- */
- public TmfFixedArray<T> append(final T... values) {
- TmfFixedArray<T> result = new TmfFixedArray<T>(copyOf(fArray, fArray.length + values.length));
- for (int i = 0; i < values.length; ++i) {
- result.set(fArray.length + i, values[i]);
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public Object clone() {
- return new TmfFixedArray<T>(copyOf(fArray, fArray.length));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractList#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object o) {
- if (o instanceof TmfFixedArray<?>) {
- return Arrays.equals(fArray, ((TmfFixedArray<?>) o).fArray);
- }
- if (!(o instanceof List)) {
- return false;
- }
- for (int i = 0; i < fArray.length; ++i) {
- if (!fArray[i].equals(o)) {
- return false;
- }
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractList#get(int)
- */
- @Override
- public T get(int index) {
- return fArray[index];
- }
-
- /**
- * Get the array reference.
- *
- * @return The array reference.
- * @see #toArray FixedArray.toArray() to get a copy of the array.
- */
- public T[] getArray() {
- return fArray;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractList#hashCode()
- */
- @Override
- public int hashCode() {
- return Arrays.hashCode(fArray);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractList#set(int, java.lang.Object)
- */
- @Override
- public T set(int index, T element) {
- T temp = fArray[index];
- fArray[index] = element;
- return temp;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractCollection#size()
- */
- @Override
- public int size() {
- return fArray.length;
- }
-
- /**
- * Get a array covering only a part of the array.
- *
- * @param start
- * Starting position of the new array.
- * @return A new array covering the elements specified.
- */
- public TmfFixedArray<T> subArray(int start) {
- return new TmfFixedArray<T>(copyOfRange(fArray, start, fArray.length));
- }
-
- /**
- * Get a array covering only a part of the array.
- *
- * @param start
- * Starting position of the new array.
- * @param length
- * Number of element to include in the new array.
- * @return A new array covering the elements specified.
- */
- public TmfFixedArray<T> subArray(int start, int length) {
- return new TmfFixedArray<T>(copyOfRange(fArray, start, length + start));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractCollection#toArray()
- */
- @Override
- public T[] toArray() {
- return copyOf(fArray, fArray.length);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractCollection#toArray(T[])
- */
- @Override
- public <E> E[] toArray(E[] array) {
- if (array.length < fArray.length) {
- return copyOf(fArray, fArray.length, (Class<? extends E[]>) array.getClass());
- }
- System.arraycopy(fArray, 0, array, 0, fArray.length);
- if (array.length > fArray.length) {
- array[fArray.length] = null;
- }
- return array;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.AbstractCollection#toString()
- */
- @Override
- public String toString() {
- return Arrays.toString(fArray);
- }
-}
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider;
fStatsData = new TmfBaseStatisticsTree();
- fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
+ fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes);
fStatsData.setTotal(fTestName, true, 3);
fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), true, 1);
assertNotNull("getColumnData", columnsData);
assertEquals("getColumnData", 3, columnsData.size());
- TmfStatisticsTreeNode parentNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
- TmfStatisticsTreeNode treeNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
- TmfStatisticsTreeNode treeNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().getName()));
+ TmfStatisticsTreeNode parentNode = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode treeNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
+ TmfStatisticsTreeNode treeNode2 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().getName());
ViewerComparator vComp = null;
for (TmfBaseColumnData columnData : columnsData) {
assertNotNull("getColumnData", columnData);
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
TmfBaseStatisticsTree baseData = new TmfBaseStatisticsTree();
fTraceName = "trace1";
- fTreeNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>(fTraceName), baseData);
+ fTreeNode = new TmfStatisticsTreeNode(baseData, fTraceName);
fBaseColumnData = new TmfBaseColumnData(fHeader, fWidth, fAlignment, fToolTip, fLabelProvider, fComparator, fPercentageProvider);
}
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
assertEquals("getChildren", fTestName, treeNode.getKey());
// Getting children of the trace
- childrenTreeNode = fStatsData.getChildren(new TmfFixedArray<String>(fTestName));
+ childrenTreeNode = fStatsData.getChildren(fTestName);
assertEquals("getChildren", 1, childrenTreeNode.size());
treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
assertEquals("getChildren", fTestName, treeNode.getKey());
// Getting children of the trace
- childrenTreeNode = fStatsData.getAllChildren(new TmfFixedArray<String>(fTestName));
+ childrenTreeNode = fStatsData.getAllChildren(fTestName);
assertEquals("getChildren", 1, childrenTreeNode.size());
treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
* It should return the eventType even though the number of events
* equals 0
*/
- fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName())).reset();
+ fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()).reset();
// Getting children of a category
childrenTreeNode = fStatsData.get(treeNode.getPath()).getAllChildren();
assertEquals("getChildren", 2, childrenTreeNode.size());
* Test registering of events.
*/
public void testRegisterEvent() {
- TmfStatisticsTreeNode trace = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode trace = fStatsData.get(fTestName);
assertEquals("registerEvent", 3, trace.getValues().getTotal());
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(fTestName, Messages.TmfStatisticsData_EventTypes);
for (TmfStatisticsTreeNode child : childrenTreeNode) {
if (child.getKey().compareTo(fEvent1.getType().getName()) == 0) {
assertEquals("registerEvent", 1, child.getValues().getTotal());
* Test getter.
*/
public void testGet() {
- TmfStatisticsTreeNode traceRoot = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceRoot = fStatsData.get(fTestName);
assertNotNull("get", traceRoot);
- assertEquals("get", 0, traceRoot.getPath().toString().compareTo("[" + fTestName + "]"));
+ assertEquals("get", 0, traceRoot.getPath()[0].compareTo(fTestName));
assertEquals("get", 3, traceRoot.getValues().getTotal());
assertEquals("get", 1, traceRoot.getNbChildren());
}
* Test getting or creating of node entries.
*/
public void testGetOrCreate() {
- TmfFixedArray<String> newEventType = new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, "Fancy Type");
+ String[] newEventType = new String[] { fTestName, Messages.TmfStatisticsData_EventTypes, "Fancy Type" };
TmfStatisticsTreeNode newEventTypeNode;
// newEventType is not in the tree
TmfStatisticsTreeNode parentNode = fStatsData.getParent(AbsTmfStatisticsTree.ROOT);
assertNull("getParent", parentNode);
- parentNode = fStatsData.getParent(new TmfFixedArray<String>("TreeRootNode that should not exist"));
+ parentNode = fStatsData.getParent("TreeRootNode that should not exist");
assertNotNull("getParent", parentNode);
assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(AbsTmfStatisticsTree.ROOT).getKey().toString()));
- parentNode = fStatsData.getParent(new TmfFixedArray<String>("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist"));
+ parentNode = fStatsData.getParent("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist");
assertNull("getParent", parentNode);
- parentNode = fStatsData.getParent(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
+ parentNode = fStatsData.getParent(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
assertNull("getParent", parentNode);
- parentNode = fStatsData.getParent(new TmfFixedArray<String>(fTestName));
+ parentNode = fStatsData.getParent(fTestName);
assertNotNull("getParent", parentNode);
assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(AbsTmfStatisticsTree.ROOT.toString()));
- parentNode = fStatsData.getParent(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
+ parentNode = fStatsData.getParent(fTestName, Messages.TmfStatisticsData_EventTypes);
assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(new TmfFixedArray<String>(fTestName)).getPath().toString()));
+ assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(fTestName).getPath().toString()));
}
// ------------------------------------------------------------------------
* Test reset method
*/
public void testReset() {
- fStatsData.reset(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
+ fStatsData.reset(fTestName, Messages.TmfStatisticsData_EventTypes);
- assertEquals("reset", 0, fStatsData.getChildren(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)).size());
- assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())));
- assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType3.getName())));
+ assertEquals("reset", 0, fStatsData.getChildren(fTestName, Messages.TmfStatisticsData_EventTypes).size());
+ assertNull("reset", fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ assertNull("reset", fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType3.getName()));
- fStatsData.reset(new TmfFixedArray<String>(fTestName));
+ fStatsData.reset(fTestName);
- // A rootz should always have at least one child that is eventType
- assertEquals("reset", 1, fStatsData.getChildren(new TmfFixedArray<String>(fTestName)).size());
+ // A root should always have at least one child that is eventType
+ assertEquals("reset", 1, fStatsData.getChildren(fTestName).size());
}
}
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
*/
public void testContainsChild() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
// Creates a category from the key already created
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
*/
public void testGetChildren() {
// Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(AbsTmfStatisticsTree.ROOT).getChildren();
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(AbsTmfStatisticsTree.ROOT[0]).getChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", fTestName, treeNode.getKey());
// Getting children of the trace
- childrenTreeNode = fStatsData.get(new TmfFixedArray<String>(fTestName)).getChildren();
+ childrenTreeNode = fStatsData.get(fTestName).getChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
assertEquals("getChildren", fTestName, treeNode.getKey());
// Getting children of the trace
- childrenTreeNode = fStatsData.get(new TmfFixedArray<String>(fTestName)).getAllChildren();
+ childrenTreeNode = fStatsData.get(fTestName).getAllChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
* It should return the eventType even though the number of events
* equals 0
*/
- fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())).reset();
+ fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()).reset();
// Getting children of a category
childrenTreeNode = treeNode.getAllChildren();
assertEquals("getChildren", 2, childrenTreeNode.size());
*/
public void testGetNbChildren() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
assertEquals("getNbChildren", 1, rootNode.getNbChildren());
assertEquals("getNbChildren", 1, traceNode.getNbChildren());
*/
public void testHasChildren() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
assertTrue("hasChildren", rootNode.hasChildren());
assertTrue("hasChildren", traceNode.hasChildren());
TmfStatisticsTreeNode parentNode = rootNode.getParent();
assertNull("getParent", parentNode);
- TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>("newly created trace node"), fStatsData);
+ TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(fStatsData, "newly created trace node");
parentNode = newTraceNode.getParent();
assertNotNull("getParent", parentNode);
assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(AbsTmfStatisticsTree.ROOT).getKey().toString()));
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
parentNode = traceNode.getParent();
assertNotNull("getParent", parentNode);
assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(AbsTmfStatisticsTree.ROOT.toString()));
- TmfStatisticsTreeNode newNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist"), fStatsData);
+ TmfStatisticsTreeNode newNode = new TmfStatisticsTreeNode(fStatsData, "TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist");
parentNode = newNode.getParent();
assertNull("getParent", parentNode);
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
parentNode = elementNode.getParent();
assertNull("getParent", parentNode);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
parentNode = catNode.getParent();
assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(new TmfFixedArray<String>(fTestName)).getPath().toString()));
+ assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(fTestName).getPath().toString()));
parentNode = elementNode.getParent();
assertNotNull("getParent", parentNode);
- assertTrue("getParent", parentNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)));
+ assertTrue(arraysEqual(parentNode.getPath(), fTestName, Messages.TmfStatisticsData_EventTypes));
}
// ------------------------------------------------------------------------
*/
public void testGetKey() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
- assertEquals("getKey", 0, rootNode.getKey().compareTo(AbsTmfStatisticsTree.ROOT.get(0)));
+ assertEquals("getKey", 0, rootNode.getKey().compareTo(AbsTmfStatisticsTree.ROOT[0]));
assertEquals("getKey", 0, traceNode.getKey().compareTo(fTestName));
assertEquals("getKey", 0, catNode.getKey().compareTo(Messages.TmfStatisticsData_EventTypes));
assertEquals("getKey", 0, elementNode.getKey().compareTo(fType1.getName()));
*/
public void testGetPath() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
-
- assertTrue("getPath", rootNode.getPath().equals(AbsTmfStatisticsTree.ROOT));
- assertTrue("getPath", traceNode.getPath().equals(new TmfFixedArray<String>(fTestName)));
- assertTrue("getPath", catNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)));
- assertTrue("getPath", elementNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+
+ assertTrue("getPath", arraysEqual(rootNode.getPath(), AbsTmfStatisticsTree.ROOT));
+ assertTrue("getPath", arraysEqual(traceNode.getPath(), fTestName));
+ assertTrue("getPath", arraysEqual(catNode.getPath(),
+ fTestName, Messages.TmfStatisticsData_EventTypes));
+ assertTrue("getPath", arraysEqual(elementNode.getPath(),
+ fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
}
// ------------------------------------------------------------------------
*/
public void testGetValue() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
- TmfStatisticsTreeNode elementNode3 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName()));
+ TmfStatisticsTreeNode elementNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode elementNode3 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName());
assertEquals("getValue", 0, rootNode.getValues().getTotal());
assertEquals("getValue", 9, traceNode.getValues().getTotal());
*/
public void testReset() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
elementNode.reset();
assertEquals("reset", 0, elementNode.getValues().getTotal());
assertEquals("reset", 0, catNode.getValues().getTotal());
assertEquals("reset", 0, catNode.getValues().getPartial());
assertEquals("reset", 0, catNode.getNbChildren());
- assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())));
+ assertNull("reset", fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
traceNode.reset();
assertEquals("reset", 0, traceNode.getValues().getTotal());
*/
public void testResetGlobalValue() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
- TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName()));
+ TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName());
rootNode.resetGlobalValue();
*/
public void testResetTimeRangeValue() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
- TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName()));
+ TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName());
rootNode.resetTimeRangeValue();
assertTrue(catChildren.contains(eventTypeNode1));
assertTrue(catChildren.contains(eventTypeNode2));
}
+
+ /**
+ * Check if two String arrays are equals, by comparing their contents.
+ */
+ private static boolean arraysEqual(String[] array1, String... array2) {
+ if (array1.length != array2.length) {
+ return false;
+ }
+ for (int i = 0; i < array1.length; i++) {
+ if (!array1[i].equals(array2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
}
package org.eclipse.linuxtools.tmf.ui.tests.statistics;
import java.util.Arrays;
-import java.util.Collection;
-import java.util.Vector;
import junit.framework.TestCase;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
/**
* Test getting of children.
+ * FIXME this test was quickly adapted when we removed the TmfFixedArray,
+ * but it could be rewritten to be much more simple...
*/
public void testGetChildren() {
- Object[] objectArray = treeProvider.getChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)));
+ Object[] objectArray = treeProvider.getChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes));
TmfStatisticsTreeNode[] childrenNode = Arrays.asList(objectArray).toArray(new TmfStatisticsTreeNode[0]);
- Collection<TmfFixedArray<String>> childrenExpected = new Vector<TmfFixedArray<String>>();
- childrenExpected.add(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
- childrenExpected.add(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent2.getType().getName()));
+ String[][] childrenExpected = new String[][] {
+ new String[] { fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName() },
+ new String[] { fTestName, Messages.TmfStatisticsData_EventTypes, fEvent2.getType().getName() }
+ };
- assertEquals("getChildren", childrenExpected.size(), childrenNode.length);
+ assertEquals("getChildren", childrenExpected.length, childrenNode.length);
// assertTrue("getChildren", childrenPath.equals(childrenExpected));
for (TmfStatisticsTreeNode childNode : childrenNode) {
- if (childrenExpected.contains(childNode.getPath())) {
- childrenExpected.remove(childNode.getPath());
- } else {
+ if (!arrayOfArraysContains(childrenExpected, childNode.getPath())) {
fail();
}
}
}
+ private static boolean arrayOfArraysContains(String[][] arrayOfArrays, String[] array) {
+ for (String[] curArray : arrayOfArrays) {
+ if (arraysEqual(curArray, array)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean arraysEqual(String[] array1, String[] array2) {
+ if (array1.length != array2.length) {
+ return false;
+ }
+ for (int i = 0; i < array1.length; i++) {
+ if (!array1[i].equals(array2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
// ------------------------------------------------------------------------
// GetParent
// ------------------------------------------------------------------------
* Test getting of parent.
*/
public void testGetParent() {
- TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.get(new TmfFixedArray<String>(fTestName)));
+ TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.get(fTestName));
assertNotNull("getParent", parent);
assertTrue("getParent", parent.getPath().equals(AbsTmfStatisticsTree.ROOT));
Boolean hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(AbsTmfStatisticsTree.ROOT));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName)));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName())));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
assertFalse("hasChildren", hasChildren);
}
Object[] objectElements = treeProvider.getElements(fStatsData.get(AbsTmfStatisticsTree.ROOT));
TmfStatisticsTreeNode[] nodeElements = Arrays.asList(objectElements).toArray(new TmfStatisticsTreeNode[0]);
assertEquals("getElements", 1, nodeElements.length);
- assertTrue("getElements", nodeElements[0].getPath().equals(new TmfFixedArray<String>(fTestName)));
+ assertTrue("getElements", nodeElements[0].getPath()[0].equals(fTestName));
}
}
package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
-
/**
* Base class for the statistics storage. It allow to implement a tree structure
* while avoiding the need to run through the tree each time you need to add a
/**
* Identification of the root.
*/
- public static final TmfFixedArray<String> ROOT = new TmfFixedArray<String>("root"); //$NON-NLS-1$
+ public static final String[] ROOT = new String[] { "root" }; //$NON-NLS-1$
/**
* Function to merge many string more efficiently.
/**
* The nodes in the tree.
*/
- protected HashMap<TmfFixedArray<String>, TmfStatisticsTreeNode> fNodes;
+ protected Map<List<String>, TmfStatisticsTreeNode> fNodes;
/**
* Constructor.
*/
public AbsTmfStatisticsTree() {
- fNodes = new HashMap<TmfFixedArray<String>, TmfStatisticsTreeNode>();
+ fNodes = new HashMap<List<String>, TmfStatisticsTreeNode>();
fKeys = new HashMap<String, Set<String>>();
}
* Path to the node.
* @return The node or null.
*/
- public TmfStatisticsTreeNode get(final TmfFixedArray<String> path) {
- return fNodes.get(path);
+ public TmfStatisticsTreeNode get(String... path) {
+ List<String> pathAsList = Arrays.asList(path);
+ return fNodes.get(pathAsList);
}
/**
* Path to the node.
* @return Collection containing the children.
*/
- public abstract Collection<TmfStatisticsTreeNode> getChildren(final TmfFixedArray<String> path);
+ public abstract Collection<TmfStatisticsTreeNode> getChildren(final String... path);
/**
* Get every children of a node, even if it doesn't have any registered
* Path to the node.
* @return Collection containing all the children.
*/
- public abstract Collection<TmfStatisticsTreeNode> getAllChildren(final TmfFixedArray<String> path);
+ public abstract Collection<TmfStatisticsTreeNode> getAllChildren(final String... path);
/**
* Get the map of existing elements of path classified by parent.
* Path to the node.
* @return The node.
*/
- public TmfStatisticsTreeNode getOrCreate(final TmfFixedArray<String> path) {
- TmfStatisticsTreeNode current = fNodes.get(path);
+ public TmfStatisticsTreeNode getOrCreate(String... path) {
+ List<String> pathAsList = Arrays.asList(path);
+ TmfStatisticsTreeNode current = fNodes.get(pathAsList);
+
if (current == null) {
registerName(path);
- current = new TmfStatisticsTreeNode(path, this);
- fNodes.put(path, current);
+ current = new TmfStatisticsTreeNode(this, path);
+ fNodes.put(pathAsList, current);
}
return current;
}
* Path to the node.
* @return Parent node or null.
*/
- public TmfStatisticsTreeNode getParent(final TmfFixedArray<String> path) {
- if (path.size() == 1) {
+ public TmfStatisticsTreeNode getParent(final String... path) {
+ if (path.length == 1) {
if (path.equals(ROOT)) {
return null;
}
return get(ROOT);
}
- return get(path.subArray(0, path.size() - 1));
+
+ String[] parentPath = new String[path.length - 1];
+ System.arraycopy(path, 0, parentPath, 0, parentPath.length);
+ return get(parentPath);
}
/**
* @param path
* Path of the new node.
*/
- protected abstract void registerName(final TmfFixedArray<String> path);
+ protected abstract void registerName(final String... path);
/**
* Resets a node.
* @param path
* Path to the node.
*/
- public void reset(final TmfFixedArray<String> path) {
+ public void reset(final String... path) {
for (TmfStatisticsTreeNode node : getAllChildren(path)) {
reset(node.getPath());
- fNodes.remove(node.getPath());
+ List<String> nodePathList = Arrays.asList(node.getPath());
+ fNodes.remove(nodePathList);
}
}
* Path to the node.
* @since 2.0
*/
- public void resetGlobalValue(final TmfFixedArray<String> path) {
+ public void resetGlobalValue(final String... path) {
for (TmfStatisticsTreeNode node : getChildren(path)) {
node.resetGlobalValue();
}
* Path to the node.
* @since 2.0
*/
- public void resetTimeRangeValue(final TmfFixedArray<String> path) {
+ public void resetTimeRangeValue(final String... path) {
for (TmfStatisticsTreeNode node : getChildren(path)) {
node.resetTimeRangeValue();
}
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
-
/**
* Store information about base statistics data.
*
/**
* Root node key.
*/
- protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
+ protected static final String ROOT_NODE_KEY = mergeString(ROOT[0], NODE);
/**
* Default constructor. Creates base statistics tree for counting total
keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
// //////////// CREATE root
- keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time
+ keys.put(ROOT[0], new HashSet<String>(2)); // 1 trace at the time
getOrCreate(ROOT);
}
* (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
*/
@Override
- public Collection<TmfStatisticsTreeNode> getChildren(TmfFixedArray<String> path) {
- LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
+ public List<TmfStatisticsTreeNode> getChildren(String... path) {
+ List<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
- if (path.size() % 2 == 0) { // if we are at a Category
+ if (path.length % 2 == 0) { // if we are at a Category
TmfStatisticsTreeNode current = null;
- for (String value : getKeys().get(path.get(path.size() - 1))) {
- current = get(path.append(value));
- if (current != null && current.getValues().getTotal() != 0) {
- result.add(current);
+ for (String value : getKeys().get(path[path.length - 1])) {
+ current = get(addToArray(path, value));
+ if (current != null) {
+ if (current.getValues().getTotal() > 0 || current.getValues().getPartial() > 0) {
+ result.add(current);
+ }
}
}
- } else if (path.size() == 1) { // Special case.
+ } else if (path.length == 1) { // Special case.
if (path.equals(ROOT)) {
- for (String value : getKeys().get(ROOT.get(0))) {
- result.add(getOrCreate(new TmfFixedArray<String>(value)));
+ for (String value : getKeys().get(ROOT[0])) {
+ result.add(getOrCreate(value));
}
} else {
// Get value under the root
for (String value : getKeys().get(ROOT_NODE_KEY)) {
- result.add(getOrCreate(path.append(value)));
+ result.add(getOrCreate(addToArray(path, value)));
}
}
} else {// If we are at a value
- for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
+ for (String value : getKeys().get(mergeString(path[path.length - 2], NODE))) {
// Search the parent name + NODE
- result.add(getOrCreate(path.append(value)));
+ result.add(getOrCreate(addToArray(path, value)));
}
}
* (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
*/
@Override
- public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) {
+ public Collection<TmfStatisticsTreeNode> getAllChildren(String... path) {
LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
- if (path.size() % 2 == 0) { // if we are at a Category
+ if (path.length % 2 == 0) { // if we are at a Category
TmfStatisticsTreeNode current = null;
- for (String value : getKeys().get(path.get(path.size() - 1))) {
- current = get(path.append(value));
+ for (String value : getKeys().get(path[path.length - 1])) {
+ current = get(addToArray(path, value));
if (current != null) {
result.add(current);
}
}
- } else if (path.size() == 1) { // Special case.
+ } else if (path.length == 1) { // Special case.
if (path.equals(ROOT)) {
- for (String value : getKeys().get(ROOT.get(0))) {
- result.add(getOrCreate(new TmfFixedArray<String>(value)));
+ for (String value : getKeys().get(ROOT[0])) {
+ result.add(getOrCreate(value));
}
} else {
// Get value under the root
for (String value : getKeys().get(ROOT_NODE_KEY)) {
- result.add(getOrCreate(path.append(value)));
+ result.add(getOrCreate(addToArray(path, value)));
}
}
} else {// If we are at a value
- for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
+ for (String value : getKeys().get(mergeString(path[path.length - 2], NODE))) {
// Search the parent name + NODE
- result.add(getOrCreate(path.append(value)));
+ result.add(getOrCreate(addToArray(path, value)));
}
}
return result;
@Override
public void setTotal(String traceName, boolean isGlobal, long qty) {
- TmfFixedArray<String>[] paths = getNormalPaths(traceName);
- for (TmfFixedArray<String> path : paths) {
+ String[][] paths = getNormalPaths(traceName);
+ for (String path[] : paths) {
getOrCreate(path).getValues().setValue(isGlobal, qty);
}
}
@Override
public void setTypeCount(String traceName, String type, boolean isGlobal, long qty) {
- TmfFixedArray<String>[] paths = getTypePaths(traceName, type);
- for (TmfFixedArray<String> path : paths) {
+ String[][] paths = getTypePaths(traceName, type);
+ for (String[] path : paths) {
getOrCreate(path).getValues().setValue(isGlobal, qty);
}
}
* Extra information to pass along with the event
* @return Array of FixedArray representing the paths.
*/
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected TmfFixedArray<String>[] getTypePaths(String traceName, String type) {
- TmfFixedArray[] paths = { new TmfFixedArray<String>(traceName, HEADER_EVENT_TYPES, type) };
+ protected String[][] getTypePaths(String traceName, String type) {
+ String[][] paths = { new String[] {traceName, HEADER_EVENT_TYPES, type } };
return paths;
}
* Extra information to pass along with the event
* @return Array of FixedArray representing the paths.
*/
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected TmfFixedArray<String>[] getNormalPaths(String traceName) {
- TmfFixedArray[] paths = { new TmfFixedArray<String>(traceName) };
+ protected String[][] getNormalPaths(String traceName) {
+ String[][] paths = { new String[] { traceName } };
return paths;
}
* (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
*/
@Override
- protected void registerName(TmfFixedArray<String> path) {
- if (path.size() == 1) {
+ protected void registerName(String... path) {
+ if (path.length == 1) {
if (!path.equals(ROOT)) {
- getKeys().get(ROOT.get(0)).add(path.get(0));
+ getKeys().get(ROOT[0]).add(path[0]);
}
- } else if (path.size() % 2 != 0) {
- getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
+ } else if (path.length % 2 != 0) {
+ getKeys().get(path[path.length - 2]).add(path[path.length - 1]);
}
}
+
+ /**
+ * Return a new array that's a copy of the old one, plus 'newElem' added at
+ * the end.
+ */
+ private static String[] addToArray(String[] array, String newElem) {
+ String[] newArray = new String[array.length + 1];
+ System.arraycopy(array, 0, newArray, 0, array.length);
+ newArray[array.length] = newElem;
+ return newArray;
+ }
}
import java.util.Collection;
-import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
-
/**
* A tree where nodes can be accessed efficiently using paths.
*
* It works like file systems. Each node is identified by a key. A path is an
- * array ({@link TmfFixedArray}) of String. The elements of the array represent
- * the path from the root to this node.
+ * array of String. The elements of the array represent the path from the root
+ * to this node.
*
* @version 2.0
* @since 2.0
/**
* Path of the node.
*/
- protected TmfFixedArray<String> fPath;
+ protected String[] fPath;
/**
* Corresponding StatisticsData.
* @param nodes
* Corresponding StatisticsData.
*/
- public TmfStatisticsTreeNode(final TmfFixedArray<String> path,
- AbsTmfStatisticsTree nodes) {
+ public TmfStatisticsTreeNode(AbsTmfStatisticsTree nodes, final String... path) {
fPath = path;
fNodes = nodes;
fValues = new TmfStatisticsValues();
*/
public boolean containsChild(String key) {
if (AbsTmfStatisticsTree.ROOT.equals(fPath)) {
- return fNodes.get(new TmfFixedArray<String>(key)) != null;
+ return fNodes.get(key) != null;
}
- return (fNodes.get(fPath.append(key)) != null);
+
+ String[] childPath = new String[fPath.length + 1];
+ System.arraycopy(fPath, 0, childPath, 0, fPath.length);
+ childPath[fPath.length] = key;
+ return (fNodes.get(childPath) != null);
}
/**
* @return Key associated with this node.
*/
public String getKey() {
- return fPath.get(fPath.size() - 1);
+ return fPath[fPath.length - 1];
}
/**
*
* @return The path of the node.
*/
- public TmfFixedArray<String> getPath() {
+ public String[] getPath() {
return fPath;
}