fStatsData = new TmfStatisticsTree();
- fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes);
+ fStatsData.getOrCreateNode(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(fTestName);
- TmfStatisticsTreeNode treeNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
- TmfStatisticsTreeNode treeNode2 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().getName());
+ TmfStatisticsTreeNode parentNode = fStatsData.getNode(fTestName);
+ TmfStatisticsTreeNode treeNode1 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
+ TmfStatisticsTreeNode treeNode2 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().getName());
ViewerComparator vComp = null;
for (TmfBaseColumnData columnData : columnsData) {
assertNotNull("getColumnData", columnData);
// Testing labelProvider
ColumnLabelProvider labelProvider = columnData.getLabelProvider();
if (columnData.getHeader().compareTo(LEVEL_COLUMN) == 0) {
- assertEquals("getColumnData", 0, labelProvider.getText(treeNode1).compareTo(treeNode1.getKey()));
+ assertEquals("getColumnData", 0, labelProvider.getText(treeNode1).compareTo(treeNode1.getName()));
} else if (columnData.getHeader().compareTo(EVENTS_COUNT_COLUMN) == 0) {
assertEquals("getColumnData", 0, labelProvider.getText(treeNode1).compareTo(Long.toString(1)));
}
fLabelProvider = new ColumnLabelProvider() {
@Override
public String getText(Object element) {
- return ((TmfStatisticsTreeNode) element).getKey();
+ return ((TmfStatisticsTreeNode) element).getName();
}
@Override
TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
- return n1.getKey().compareTo(n2.getKey());
+ return n1.getName().compareTo(n2.getName());
}
};
fPercentageProvider = new ITmfColumnPercentageProvider() {
TmfStatisticsTree baseData = new TmfStatisticsTree();
fTraceName = "trace1";
- fTreeNode = new TmfStatisticsTreeNode(baseData, fTraceName);
+ fTreeNode = new TmfStatisticsTreeNode(baseData, baseData.getRootNode(), fTraceName);
fBaseColumnData = new TmfBaseColumnData(fHeader, fWidth, fAlignment, fToolTip, fLabelProvider, fComparator, fPercentageProvider);
}
package org.eclipse.linuxtools.tmf.ui.tests.statistics;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
private final TmfEventField fContent2;
private final TmfEventField fContent3;
- private final TmfStatisticsTree fStatsData;
+ private final TmfStatisticsTree fStatsTree;
// ------------------------------------------------------------------------
// Housekeeping
fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType3, fContent3, fReference);
- fStatsData = new TmfStatisticsTree();
+ fStatsTree = new TmfStatisticsTree();
- fStatsData.setTotal(fTestName, true, 3);
- fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), true, 1);
- fStatsData.setTypeCount(fTestName, fEvent2.getType().getName(), true, 1);
- fStatsData.setTypeCount(fTestName, fEvent3.getType().getName(), true, 1);
+ fStatsTree.setTotal(fTestName, true, 3);
+ fStatsTree.setTypeCount(fTestName, fEvent1.getType().getName(), true, 1);
+ fStatsTree.setTypeCount(fTestName, fEvent2.getType().getName(), true, 1);
+ fStatsTree.setTypeCount(fTestName, fEvent3.getType().getName(), true, 1);
}
// ------------------------------------------------------------------------
*/
public void testGetChildren() {
// Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(TmfStatisticsTree.ROOT);
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsTree.getRootNode().getChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", fTestName, treeNode.getKey());
+ assertEquals("getChildren", fTestName, treeNode.getName());
// Getting children of the trace
- childrenTreeNode = fStatsData.getChildren(fTestName);
+ childrenTreeNode = fStatsTree.getNode(fTestName).getChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
+ assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getName());
Vector<String> keyExpected = new Vector<String>();
keyExpected.add(fEvent1.getType().getName());
keyExpected.add(fEvent3.getType().getName());
// Getting children of a category
- childrenTreeNode = fStatsData.getChildren(treeNode.getPath());
+ childrenTreeNode = treeNode.getChildren();
assertEquals("getChildren", 2, childrenTreeNode.size());
Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator();
TmfStatisticsTreeNode temp;
while (iterChild.hasNext()) {
temp = iterChild.next();
- assertEquals(0, fStatsData.getChildren(temp.getPath()).size());
- if (keyExpected.contains(temp.getKey())) {
- keyExpected.removeElement(temp.getKey());
+ assertEquals(0, temp.getChildren().size());
+ if (keyExpected.contains(temp.getName())) {
+ keyExpected.removeElement(temp.getName());
} else {
fail();
}
}
// Get children of a specific event type
- childrenTreeNode = fStatsData.getChildren(childrenTreeNode.iterator().next().getPath());
- assertEquals("getChildren", 0, childrenTreeNode.size());
- }
-
- // ------------------------------------------------------------------------
- // GetAllChildren
- // ------------------------------------------------------------------------
-
- /**
- * Test getting of all children.
- */
- public void testGetAllChildren() {
- // Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getAllChildren(TmfStatisticsTree.ROOT);
- assertEquals("getChildren", 1, childrenTreeNode.size());
- TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", fTestName, treeNode.getKey());
-
- // Getting children of the trace
- childrenTreeNode = fStatsData.getAllChildren(fTestName);
- assertEquals("getChildren", 1, childrenTreeNode.size());
- treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
-
- Vector<String> keyExpected = new Vector<String>();
- keyExpected.add(fEvent1.getType().getName());
- keyExpected.add(fEvent3.getType().getName());
- /*
- * It should return the eventType even though the number of events
- * equals 0
- */
- 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());
-
- Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator();
- TmfStatisticsTreeNode temp;
- while (iterChild.hasNext()) {
- temp = iterChild.next();
- assertEquals(0, fStatsData.getAllChildren(temp.getPath()).size());
- if (keyExpected.contains(temp.getKey())) {
- keyExpected.removeElement(temp.getKey());
- } else {
- fail();
- }
- }
-
- // Get children of a specific event type
- childrenTreeNode = fStatsData.getAllChildren(childrenTreeNode.iterator().next().getPath());
+ childrenTreeNode = childrenTreeNode.iterator().next().getChildren();
assertEquals("getChildren", 0, childrenTreeNode.size());
}
* Test registering of events.
*/
public void testRegisterEvent() {
- TmfStatisticsTreeNode trace = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode trace = fStatsTree.getNode(fTestName);
assertEquals("registerEvent", 3, trace.getValues().getTotal());
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(fTestName, Messages.TmfStatisticsData_EventTypes);
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes).getChildren();
for (TmfStatisticsTreeNode child : childrenTreeNode) {
- if (child.getKey().compareTo(fEvent1.getType().getName()) == 0) {
+ if (child.getName().compareTo(fEvent1.getType().getName()) == 0) {
assertEquals("registerEvent", 1, child.getValues().getTotal());
- } else if (child.getKey().compareTo(fEvent3.getType().getName()) == 0) {
+ } else if (child.getName().compareTo(fEvent3.getType().getName()) == 0) {
assertEquals("registerEvent", 1, child.getValues().getTotal());
}
}
* Test getter.
*/
public void testGet() {
- TmfStatisticsTreeNode traceRoot = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode traceRoot = fStatsTree.getNode(fTestName);
assertNotNull("get", traceRoot);
assertEquals("get", 0, traceRoot.getPath()[0].compareTo(fTestName));
assertEquals("get", 3, traceRoot.getValues().getTotal());
TmfStatisticsTreeNode newEventTypeNode;
// newEventType is not in the tree
- newEventTypeNode = fStatsData.get(newEventType);
- assertNull("getOrCreate", newEventTypeNode);
+ newEventTypeNode = fStatsTree.getNode(newEventType);
+ assertNull(newEventTypeNode);
- newEventTypeNode = fStatsData.getOrCreate(newEventType);
- assertNotNull("getOrCreate", newEventTypeNode);
- assertTrue("getOrCreate", newEventTypeNode.getPath().equals(newEventType));
+ newEventTypeNode = fStatsTree.getOrCreateNode(newEventType);
+ assertNotNull(newEventTypeNode);
+ assertTrue(Arrays.equals(newEventType, newEventTypeNode.getPath()));
// newEventType is in the tree
newEventTypeNode.reset();
- newEventTypeNode = fStatsData.get(newEventType);
- assertNotNull("getOrCreate", newEventTypeNode);
+ newEventTypeNode = fStatsTree.getNode(newEventType);
+ assertNotNull(newEventTypeNode);
- newEventTypeNode = fStatsData.getOrCreate(newEventType);
- assertNotNull("getOrCreate", newEventTypeNode);
- assertTrue("getOrCreate", newEventTypeNode.getPath().equals(newEventType));
+ newEventTypeNode = fStatsTree.getOrCreateNode(newEventType);
+ assertNotNull(newEventTypeNode);
+ assertTrue(Arrays.equals(newEventType, newEventTypeNode.getPath()));
}
// ------------------------------------------------------------------------
* Test getting of parent node.
*/
public void testGetParent() {
- TmfStatisticsTreeNode parentNode = fStatsData.getParent(TmfStatisticsTree.ROOT);
- assertNull("getParent", parentNode);
-
- parentNode = fStatsData.getParent("TreeRootNode that should not exist");
- assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(TmfStatisticsTree.ROOT).getKey().toString()));
+ TmfStatisticsTreeNode parentNode = fStatsTree.getRootNode().getParent();
+ assertNull(parentNode);
- parentNode = fStatsData.getParent("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist");
- assertNull("getParent", parentNode);
- parentNode = fStatsData.getParent(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName());
- assertNull("getParent", parentNode);
+ parentNode = fStatsTree.getNode(fTestName).getParent();
+ assertNotNull(parentNode);
+ assertEquals(parentNode.getPath().toString(), fStatsTree.getRootNode().getPath().toString());
- parentNode = fStatsData.getParent(fTestName);
- assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(TmfStatisticsTree.ROOT.toString()));
-
- parentNode = fStatsData.getParent(fTestName, Messages.TmfStatisticsData_EventTypes);
- assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(fTestName).getPath().toString()));
+ parentNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes).getParent();
+ assertNotNull(parentNode);
+ assertEquals(parentNode.getPath().toString(), fStatsTree.getNode(fTestName).getPath().toString());
}
// ------------------------------------------------------------------------
* Test reset method
*/
public void testReset() {
- fStatsData.reset(fTestName, Messages.TmfStatisticsData_EventTypes);
-
- 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()));
+ fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes).reset();
- fStatsData.reset(fTestName);
+ assertEquals(0, fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes).getChildren().size());
+ assertNull(fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ assertNull(fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fType3.getName()));
- // A root should always have at least one child that is eventType
- assertEquals("reset", 1, fStatsData.getChildren(fTestName).size());
+ fStatsTree.getNode(fTestName).reset();
+ assertEquals(0, fStatsTree.getNode(fTestName).getChildren().size());
}
}
TmfStatisticsTreeNode returnRootNode = TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey1, fStatisticsData1);
assertSame(fStatisticsData1, TmfStatisticsTreeManager.getStatTree(fDataKey1));
- assertSame(fStatisticsData1.get(TmfStatisticsTree.ROOT), returnRootNode);
+ assertSame(fStatisticsData1.getRootNode(), returnRootNode);
// Overwriting the value
returnRootNode = TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey1, fStatisticsData2);
assertSame(fStatisticsData2, TmfStatisticsTreeManager.getStatTree(fDataKey1));
- assertSame(fStatisticsData2.get(TmfStatisticsTree.ROOT), returnRootNode);
+ assertSame(fStatisticsData2.getRootNode(), returnRootNode);
// Success
} catch(Exception e) {
import junit.framework.TestCase;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-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.ui.viewers.statistics.model.Messages;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
/**
* TmfStatisticsTreeNode Test Cases.
*/
-@SuppressWarnings("nls")
public class TmfStatisticsTreeNodeTest extends TestCase {
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
- private String fTestName = null;
+ private final String fTypeId1 = "Some type1"; //$NON-NLS-1$
+ private final String fTypeId2 = "Some type2"; //$NON-NLS-1$
+ private final String fTypeId3 = "Some type3"; //$NON-NLS-1$
- private final String fContext = "UnitTest";
- private final String fTypeId1 = "Some type1";
- private final String fTypeId2 = "Some type2";
+ private final TmfStatisticsTree fStatsTree;
- private final String fLabel0 = "label1";
- private final String fLabel1 = "label2";
- private final String fLabel2 = "label3";
- private final String[] fLabels = new String[] { fLabel0, fLabel1, fLabel2 };
-
- private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5);
- private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5);
- private final TmfTimestamp fTimestamp3 = new TmfTimestamp(12355, (byte) 2, 5);
-
- private final String fSource = "Source";
-
- private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
-
- private final String fReference = "Some reference";
-
- private final TmfEvent fEvent1;
- private final TmfEvent fEvent2;
- private final TmfEvent fEvent3;
-
- private final TmfEventField fContent1;
- private final TmfEventField fContent2;
- private final TmfEventField fContent3;
-
- private final TmfStatisticsTree fStatsData;
+ private String fTestName = null;
// ------------------------------------------------------------------------
// Housekeeping
super(name);
fTestName = name;
-
- fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content");
- fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType1, fContent1, fReference);
-
- fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other content");
- fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType1, fContent2, fReference);
-
- fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
- fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType2, fContent3, fReference);
-
- fStatsData = new TmfStatisticsTree();
-
- fStatsData.setTotal(fTestName, true, 9);
- fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), true, 2);
- fStatsData.setTypeCount(fTestName, fEvent2.getType().getName(), true, 3);
- fStatsData.setTypeCount(fTestName, fEvent3.getType().getName(), true, 4);
-
- // Registers some events in time range
- fStatsData.setTotal(fTestName, false, 9);
- fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), false, 2);
- fStatsData.setTypeCount(fTestName, fEvent2.getType().getName(), false, 3);
- fStatsData.setTypeCount(fTestName, fEvent3.getType().getName(), false, 4);
+ fStatsTree = new TmfStatisticsTree();
+
+ /* Enter some global values */
+ fStatsTree.setTotal(fTestName, true, 18);
+ fStatsTree.setTypeCount(fTestName, fTypeId1, true, 5);
+ fStatsTree.setTypeCount(fTestName, fTypeId2, true, 6);
+ fStatsTree.setTypeCount(fTestName, fTypeId3, true, 7);
+
+ /* Enter some time range values */
+ fStatsTree.setTotal(fTestName, false, 9);
+ fStatsTree.setTypeCount(fTestName, fTypeId1, false, 2);
+ fStatsTree.setTypeCount(fTestName, fTypeId2, false, 3);
+ fStatsTree.setTypeCount(fTestName, fTypeId3, false, 4);
}
// ------------------------------------------------------------------------
* Test checking for child.
*/
public void testContainsChild() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
+ TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
// Creates a category from the key already created
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- assertTrue("containsChild", rootNode.containsChild(fTestName));
- assertFalse("containsChild", rootNode.containsChild(catNode.getKey()));
- assertFalse("containsChild", rootNode.containsChild(null));
+ assertTrue(rootNode.containsChild(fTestName));
+ assertFalse(rootNode.containsChild(catNode.getName()));
+ assertFalse(rootNode.containsChild(null));
- assertTrue("containsChild", traceNode.containsChild(catNode.getKey()));
- assertFalse("containsChild", traceNode.containsChild(fType1.getName()));
- assertFalse("containsChild", traceNode.containsChild(null));
+ assertTrue(traceNode.containsChild(catNode.getName()));
+ assertFalse(traceNode.containsChild(fTypeId1));
+ assertFalse(traceNode.containsChild(null));
- assertTrue("containsChild", catNode.containsChild(fType1.getName()));
- assertTrue("containsChild", catNode.containsChild(fType2.getName()));
- assertFalse("containsChild", catNode.containsChild(null));
+ assertTrue(catNode.containsChild(fTypeId1));
+ assertTrue(catNode.containsChild(fTypeId2));
+ assertFalse(catNode.containsChild(null));
}
// ------------------------------------------------------------------------
*/
public void testGetChildren() {
// Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(TmfStatisticsTree.ROOT[0]).getChildren();
- assertEquals("getChildren", 1, childrenTreeNode.size());
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsTree.getRootNode().getChildren();
+ assertEquals(1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", fTestName, treeNode.getKey());
+ assertEquals(fTestName, treeNode.getName());
// Getting children of the trace
- childrenTreeNode = fStatsData.get(fTestName).getChildren();
- assertEquals("getChildren", 1, childrenTreeNode.size());
+ childrenTreeNode = fStatsTree.getNode(fTestName).getChildren();
+ assertEquals(1, childrenTreeNode.size());
treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
+ assertEquals(Messages.TmfStatisticsData_EventTypes, treeNode.getName());
Vector<String> keyExpected = new Vector<String>();
- keyExpected.add(fType1.getName());
- keyExpected.add(fType2.getName());
+ keyExpected.add(fTypeId1);
+ keyExpected.add(fTypeId2);
+ keyExpected.add(fTypeId3);
// Getting children of a category
childrenTreeNode = treeNode.getChildren();
- assertEquals("getChildren", 2, childrenTreeNode.size());
+ assertEquals(3, childrenTreeNode.size());
Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator();
TmfStatisticsTreeNode temp;
while (iterChild.hasNext()) {
temp = iterChild.next();
- if (keyExpected.contains(temp.getKey())) {
- keyExpected.removeElement(temp.getKey());
+ if (keyExpected.contains(temp.getName())) {
+ keyExpected.removeElement(temp.getName());
} else {
fail();
}
}
// Get children of a specific event type
- childrenTreeNode = fStatsData.get(childrenTreeNode.iterator().next().getPath()).getChildren();
- assertEquals("getChildren", 0, childrenTreeNode.size());
- }
-
- // ------------------------------------------------------------------------
- // GetAllChildren
- // ------------------------------------------------------------------------
-
- /**
- * Test getting of all children.
- */
- public void testGetAllChildren() {
- // Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(TmfStatisticsTree.ROOT).getAllChildren();
- assertEquals("getChildren", 1, childrenTreeNode.size());
- TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", fTestName, treeNode.getKey());
-
- // Getting children of the trace
- childrenTreeNode = fStatsData.get(fTestName).getAllChildren();
- assertEquals("getChildren", 1, childrenTreeNode.size());
- treeNode = childrenTreeNode.iterator().next();
- assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
-
- Vector<String> keyExpected = new Vector<String>();
- keyExpected.add(fType1.getName());
- keyExpected.add(fType2.getName());
- /*
- * It should return the eventType even though the number of events
- * equals 0
- */
- fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()).reset();
- // Getting children of a category
- childrenTreeNode = treeNode.getAllChildren();
- assertEquals("getChildren", 2, childrenTreeNode.size());
-
- Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator();
- TmfStatisticsTreeNode temp;
- while (iterChild.hasNext()) {
- temp = iterChild.next();
- if (keyExpected.contains(temp.getKey())) {
- keyExpected.removeElement(temp.getKey());
- } else {
- fail();
- }
- }
-
- // Get children of a specific event type
- childrenTreeNode = fStatsData.get(childrenTreeNode.iterator().next().getPath()).getAllChildren();
- assertEquals("getChildren", 0, childrenTreeNode.size());
+ childrenTreeNode = fStatsTree.getNode(childrenTreeNode.iterator().next().getPath()).getChildren();
+ assertEquals(0, childrenTreeNode.size());
}
// ------------------------------------------------------------------------
* Test getting of number of children.
*/
public void testGetNbChildren() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
+ TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
- assertEquals("getNbChildren", 1, rootNode.getNbChildren());
- assertEquals("getNbChildren", 1, traceNode.getNbChildren());
- assertEquals("getNbChildren", 2, catNode.getNbChildren());
- assertEquals("getNbChildren", 0, elementNode.getNbChildren());
+ assertEquals(1, rootNode.getNbChildren());
+ assertEquals(1, traceNode.getNbChildren());
+ assertEquals(3, catNode.getNbChildren());
+ assertEquals(0, elementNode.getNbChildren());
}
// ------------------------------------------------------------------------
* Test checking for children.
*/
public void testHasChildren() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
+ TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
- assertTrue("hasChildren", rootNode.hasChildren());
- assertTrue("hasChildren", traceNode.hasChildren());
- assertTrue("hasChildren", catNode.hasChildren());
- assertFalse("hasChildren", elementNode.hasChildren());
+ assertTrue(rootNode.hasChildren());
+ assertTrue(traceNode.hasChildren());
+ assertTrue(catNode.hasChildren());
+ assertFalse(elementNode.hasChildren());
}
// ------------------------------------------------------------------------
* Test getting of parent.
*/
public void testGetParent() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
+ final TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode parentNode = rootNode.getParent();
- assertNull("getParent", parentNode);
+ assertNull(parentNode);
- TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(fStatsData, "newly created trace node");
+ TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(fStatsTree, rootNode, "newly created trace node"); //$NON-NLS-1$
parentNode = newTraceNode.getParent();
- assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(TmfStatisticsTree.ROOT).getKey().toString()));
+ assertNotNull(parentNode);
+ assertTrue(fStatsTree.getRootNode() == parentNode);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
parentNode = traceNode.getParent();
- assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(TmfStatisticsTree.ROOT.toString()));
+ assertNotNull(parentNode);
+ assertTrue(rootNode == parentNode);
- TmfStatisticsTreeNode newNode = new TmfStatisticsTreeNode(fStatsData, "TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist");
- parentNode = newNode.getParent();
- assertNull("getParent", parentNode);
-
- TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
parentNode = elementNode.getParent();
- assertNull("getParent", parentNode);
+ assertTrue(parentNode == fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
parentNode = catNode.getParent();
- assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(fTestName).getPath().toString()));
+ assertNotNull(parentNode);
+ assertTrue(parentNode == fStatsTree.getNode(fTestName));
parentNode = elementNode.getParent();
- assertNotNull("getParent", parentNode);
+ assertNotNull(parentNode);
assertTrue(arraysEqual(parentNode.getPath(), fTestName, Messages.TmfStatisticsData_EventTypes));
}
/**
* Test getting of key.
*/
- public void testGetKey() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
+ public void testgetName() {
+ TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
+ TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
- assertEquals("getKey", 0, rootNode.getKey().compareTo(TmfStatisticsTree.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()));
+ assertEquals(0, rootNode.getName().compareTo("root")); //$NON-NLS-1$
+ assertEquals(0, traceNode.getName().compareTo(fTestName));
+ assertEquals(0, catNode.getName().compareTo(Messages.TmfStatisticsData_EventTypes));
+ assertEquals(0, elementNode.getName().compareTo(fTypeId1));
}
// ------------------------------------------------------------------------
* Test getting of path to node.
*/
public void testGetPath() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
+ TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
+ TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
- assertTrue("getPath", arraysEqual(rootNode.getPath(), TmfStatisticsTree.ROOT));
- assertTrue("getPath", arraysEqual(traceNode.getPath(), fTestName));
- assertTrue("getPath", arraysEqual(catNode.getPath(),
+ assertEquals(0, rootNode.getPath().length); /* Root node has an empty path */
+ assertTrue(arraysEqual(traceNode.getPath(), fTestName));
+ assertTrue(arraysEqual(catNode.getPath(),
fTestName, Messages.TmfStatisticsData_EventTypes));
- assertTrue("getPath", arraysEqual(elementNode.getPath(),
- fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ assertTrue(arraysEqual(elementNode.getPath(),
+ fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1));
}
// ------------------------------------------------------------------------
* Test getting statistic value.
*/
public void testGetValue() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
- TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- 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());
- assertEquals("getValue", 0, catNode.getValues().getTotal());
- assertEquals("getValue", 3, elementNode1.getValues().getTotal());
- assertEquals("getValue", 4, elementNode3.getValues().getTotal());
-
- assertEquals("getValue", 0, rootNode.getValues().getPartial());
- assertEquals("getValue", 9, traceNode.getValues().getPartial());
- assertEquals("getValue", 0, catNode.getValues().getPartial());
- assertEquals("getValue", 3, elementNode1.getValues().getPartial());
- assertEquals("getValue", 4, elementNode3.getValues().getPartial());
+ TmfStatisticsTreeNode rootNode, traceNode, catNode, elementNode1, elementNode2, elementNode3;
+ rootNode = fStatsTree.getRootNode();
+ traceNode = fStatsTree.getNode(fTestName);
+ catNode = traceNode.getChildren().iterator().next();
+ elementNode1 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
+ elementNode2 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId2);
+ elementNode3 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId3);
+
+ assertEquals(0, rootNode.getValues().getTotal());
+ assertEquals(18, traceNode.getValues().getTotal());
+ assertEquals(0, catNode.getValues().getTotal());
+ assertEquals(5, elementNode1.getValues().getTotal());
+ assertEquals(6, elementNode2.getValues().getTotal());
+ assertEquals(7, elementNode3.getValues().getTotal());
+
+ assertEquals(0, rootNode.getValues().getPartial());
+ assertEquals(9, traceNode.getValues().getPartial());
+ assertEquals(0, catNode.getValues().getPartial());
+ assertEquals(2, elementNode1.getValues().getPartial());
+ assertEquals(3, elementNode2.getValues().getPartial());
+ assertEquals(4, elementNode3.getValues().getPartial());
}
// ------------------------------------------------------------------------
* Test reset of tree.
*/
public void testReset() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
- TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
+ TmfStatisticsTreeNode rootNode, traceNode, catNode, elementNode;
+ rootNode = fStatsTree.getRootNode();
+ traceNode = fStatsTree.getNode(fTestName);
+ catNode = traceNode.getChildren().iterator().next();
+ elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
elementNode.reset();
- assertEquals("reset", 0, elementNode.getValues().getTotal());
- assertEquals("reset", 0, elementNode.getValues().getPartial());
+ assertEquals(0, elementNode.getValues().getTotal());
+ assertEquals(0, elementNode.getValues().getPartial());
catNode.reset();
- assertEquals("reset", 0, catNode.getValues().getTotal());
- assertEquals("reset", 0, catNode.getValues().getPartial());
- assertEquals("reset", 0, catNode.getNbChildren());
- assertNull("reset", fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()));
+ assertEquals(0, catNode.getValues().getTotal());
+ assertEquals(0, catNode.getValues().getPartial());
+ assertEquals(0, catNode.getNbChildren());
+ assertNull(fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1));
traceNode.reset();
- assertEquals("reset", 0, traceNode.getValues().getTotal());
- assertEquals("reset", 0, traceNode.getValues().getPartial());
- // A trace always have at least one child that is eventType
- assertEquals("reset", 1, traceNode.getNbChildren());
+ assertEquals(0, traceNode.getValues().getTotal());
+ assertEquals(0, traceNode.getValues().getPartial());
+ assertEquals(0, traceNode.getNbChildren());
rootNode.reset();
- assertEquals("reset", 0, rootNode.getValues().getTotal());
- assertEquals("reset", 0, rootNode.getValues().getPartial());
- assertEquals("reset", 1, rootNode.getNbChildren());
+ assertEquals(0, rootNode.getValues().getTotal());
+ assertEquals(0, rootNode.getValues().getPartial());
+ assertEquals(0, rootNode.getNbChildren());
}
/**
* the global value without removing any node from the tree.
*/
public void testResetGlobalValue() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
- TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
- TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName());
+ TmfStatisticsTreeNode rootNode, traceNode, catNode, eventTypeNode1, eventTypeNode2, eventTypeNode3;
+ rootNode = fStatsTree.getRootNode();
+ traceNode = fStatsTree.getNode(fTestName);
+ catNode = traceNode.getChildren().iterator().next();
+ eventTypeNode1 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
+ eventTypeNode2 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId2);
+ eventTypeNode3 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId3);
rootNode.resetGlobalValue();
assertEquals(0, catNode.getValues().getTotal());
assertEquals(0, eventTypeNode1.getValues().getTotal());
assertEquals(0, eventTypeNode2.getValues().getTotal());
+ assertEquals(0, eventTypeNode3.getValues().getTotal());
// Checks the state of the statistics tree
- Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getAllChildren();
+ Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getChildren();
assertEquals(1, rootChildren.size());
assertTrue(rootChildren.contains(traceNode));
- Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getAllChildren();
+ Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getChildren();
assertEquals(1, traceChildren.size());
assertTrue(traceChildren.contains(catNode));
- Collection<TmfStatisticsTreeNode> catChildren = catNode.getAllChildren();
- assertEquals(2, catChildren.size());
+ Collection<TmfStatisticsTreeNode> catChildren = catNode.getChildren();
+ assertEquals(3, catChildren.size());
assertTrue(catChildren.contains(eventTypeNode1));
assertTrue(catChildren.contains(eventTypeNode2));
+ assertTrue(catChildren.contains(eventTypeNode3));
}
/**
* the time range value without removing any node from the tree.
*/
public void testResetTimeRangeValue() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
- TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
- TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName());
- TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName());
+ TmfStatisticsTreeNode rootNode, traceNode, catNode, eventTypeNode1, eventTypeNode2, eventTypeNode3;
+ rootNode = fStatsTree.getRootNode();
+ traceNode = fStatsTree.getNode(fTestName);
+ catNode = traceNode.getChildren().iterator().next();
+ eventTypeNode1 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
+ eventTypeNode2 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId2);
+ eventTypeNode3 = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId3);
rootNode.resetTimeRangeValue();
assertEquals(0, eventTypeNode2.getValues().getPartial());
// Checks the state of the statistics tree
- Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getAllChildren();
+ Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getChildren();
assertEquals(1, rootChildren.size());
assertTrue(rootChildren.contains(traceNode));
- Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getAllChildren();
+ Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getChildren();
assertEquals(1, traceChildren.size());
assertTrue(traceChildren.contains(catNode));
- Collection<TmfStatisticsTreeNode> catChildren = catNode.getAllChildren();
- assertEquals(2, catChildren.size());
+ Collection<TmfStatisticsTreeNode> catChildren = catNode.getChildren();
+ assertEquals(3, catChildren.size());
assertTrue(catChildren.contains(eventTypeNode1));
assertTrue(catChildren.contains(eventTypeNode2));
+ assertTrue(catChildren.contains(eventTypeNode3));
}
/**
* Check if two String arrays are equals, by comparing their contents.
+ * Unlike Arrays.equals(), we can use varargs for the second argument.
*/
private static boolean arraysEqual(String[] array1, String... array2) {
if (array1.length != array2.length) {
* but it could be rewritten to be much more simple...
*/
public void testGetChildren() {
- Object[] objectArray = treeProvider.getChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes));
+ Object[] objectArray = treeProvider.getChildren(fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes));
TmfStatisticsTreeNode[] childrenNode = Arrays.asList(objectArray).toArray(new TmfStatisticsTreeNode[0]);
String[][] childrenExpected = new String[][] {
* Test getting of parent.
*/
public void testGetParent() {
- TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.get(fTestName));
+ TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.getNode(fTestName));
assertNotNull("getParent", parent);
- assertTrue("getParent", parent.getPath().equals(TmfStatisticsTree.ROOT));
+ assertTrue("getParent", parent.getPath().equals(fStatsData.getRootNode().getPath()));
}
// ------------------------------------------------------------------------
* Test checking for children.
*/
public void testHasChildren() {
- Boolean hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(TmfStatisticsTree.ROOT));
+ Boolean hasChildren = treeProvider.hasChildren(fStatsData.getRootNode());
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreateNode(fTestName));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
assertFalse("hasChildren", hasChildren);
}
* Test getting of elements.
*/
public void testGetElements() {
- Object[] objectElements = treeProvider.getElements(fStatsData.get(TmfStatisticsTree.ROOT));
+ Object[] objectElements = treeProvider.getElements(fStatsData.getRootNode());
TmfStatisticsTreeNode[] nodeElements = Arrays.asList(objectElements).toArray(new TmfStatisticsTreeNode[0]);
assertEquals("getElements", 1, nodeElements.length);
assertTrue("getElements", nodeElements[0].getPath()[0].equals(fTestName));
fColumnData.add(new TmfBaseColumnData(LEVEL_COLUMN, 200, SWT.LEFT, LEVEL_COLUMN_TIP, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
- return ((TmfStatisticsTreeNode) element).getKey();
+ return ((TmfStatisticsTreeNode) element).getName();
}
@Override
public Image getImage(Object element) {
TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
- if (fFolderLevels.contains(node.getKey())) {
+ if (fFolderLevels.contains(node.getName())) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
- return n1.getKey().compareTo(n2.getKey());
+ return n1.getName().compareTo(n2.getName());
}
}, null));
@Override
public String getText(Object element) {
TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
- if (!fFolderLevels.contains(node.getKey())) {
+ if (!fFolderLevels.contains(node.getName())) {
return Long.toString(node.getValues().getTotal());
}
return ""; //$NON-NLS-1$
@Override
public String getText(Object element) {
TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
- if (!fFolderLevels.contains(node.getKey())) {
+ if (!fFolderLevels.contains(node.getName())) {
return Long.toString(node.getValues().getPartial());
}
return ""; //$NON-NLS-1$
*
* Contributors:
* Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
- *
+ * Alexandre Montplaisir - Merge TmfBaseStatisticsTree and AbsStatisticsTree
+ * Move the tree structure logic into the nodes
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
/**
* Base class for the statistics storage. It allow to implement a tree structure
*/
public class TmfStatisticsTree {
- /**
- * Identification of the root.
- */
- public static final String[] ROOT = new String[] { "root" }; //$NON-NLS-1$
-
- /**
- * Header for the event type categories.
- */
+ /** Header for the event type categories. */
public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
- /**
- * Indicate that it's a value.
- *
- * Used when checking the possible child node for a node.
- *
- * It differentiate a category of a value by being appended to a value.
- */
- protected static final String NODE = "z"; //$NON-NLS-1$
-
- /**
- * Root node key.
- */
- protected static final String ROOT_NODE_KEY = mergeString(ROOT[0], NODE);
-
- /**
- * Define what children a node can have. The management and usage of this map
- * is done by subclasses. HashSet are always faster than TreeSet for String keys.
- */
- protected Map<String, Set<String>> fKeys;
-
- /**
- * The nodes in the tree.
- */
- protected Map<List<String>, TmfStatisticsTreeNode> fNodes;
+ /** Root node of this tree */
+ private final TmfStatisticsTreeNode rootNode;
/**
* Default constructor. Creates base statistics tree for counting total
* number of events and number of events per event type.
*/
public TmfStatisticsTree() {
- fNodes = new HashMap<List<String>, TmfStatisticsTreeNode>();
- fKeys = new HashMap<String, Set<String>>();
-
- Map<String, Set<String>> keys = getKeys();
-
- // //////////// Adding category sets
- // common
- keys.put(HEADER_EVENT_TYPES, new HashSet<String>());
-
- // /////////// Adding value sets
- // Under a trace
- Set<String> temp = new HashSet<String>(8);
- temp.add(HEADER_EVENT_TYPES);
- keys.put(ROOT_NODE_KEY, temp);
- // Under an event type
- temp = new HashSet<String>(16);
- keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
-
- // //////////// CREATE root
- keys.put(ROOT[0], new HashSet<String>(2)); // 1 trace at the time
- getOrCreate(ROOT);
- }
-
- /**
- * Get a node.
- *
- * @param path
- * Path to the node.
- * @return The node or null.
- */
- public TmfStatisticsTreeNode get(String... path) {
- List<String> pathAsList = Arrays.asList(path);
- return fNodes.get(pathAsList);
+ rootNode = new TmfStatisticsTreeNode(this, null, new String[0]);
}
/**
- * Get the children of a node.
+ * Retrieve the root node of this tree.
*
- * @param path
- * Path to the node.
- * @return Collection containing the children.
+ * @return The root node
*/
- public List<TmfStatisticsTreeNode> getChildren(String... path) {
- List<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
-
- if (path.length % 2 == 0) { // if we are at a Category
- TmfStatisticsTreeNode current = null;
- 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.length == 1) { // Special case.
- if (path.equals(ROOT)) {
- 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(addToArray(path, value)));
- }
- }
- } else {// If we are at a value
- for (String value : getKeys().get(mergeString(path[path.length - 2], NODE))) {
- // Search the parent name + NODE
- result.add(getOrCreate(addToArray(path, value)));
- }
- }
-
- return result;
+ public TmfStatisticsTreeNode getRootNode() {
+ return rootNode;
}
/**
- * Get every children of a node, even if it doesn't have any registered
- * events, as opposed to getChildren
+ * Get a node.
*
* @param path
* Path to the node.
- * @return Collection containing all the children.
- */
- public List<TmfStatisticsTreeNode> getAllChildren(String... path) {
- LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
-
- if (path.length % 2 == 0) { // if we are at a Category
- TmfStatisticsTreeNode current = null;
- for (String value : getKeys().get(path[path.length - 1])) {
- current = get(addToArray(path, value));
- if (current != null) {
- result.add(current);
- }
- }
- } else if (path.length == 1) { // Special case.
- if (path.equals(ROOT)) {
- 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(addToArray(path, value)));
- }
- }
- } else {// If we are at a value
- for (String value : getKeys().get(mergeString(path[path.length - 2], NODE))) {
- // Search the parent name + NODE
- result.add(getOrCreate(addToArray(path, value)));
+ * @return The node, or null if it doesn't current exist in the tree.
+ */
+ public TmfStatisticsTreeNode getNode(String... path) {
+ TmfStatisticsTreeNode curNode = rootNode;
+ for (String pathElem : path) {
+ curNode = curNode.getChild(pathElem);
+ if (curNode == null) {
+ /* The requested path doesn't exist, return null */
+ break;
}
}
- return result;
- }
-
- /**
- * Get the map of existing elements of path classified by parent.
- *
- * @return The map.
- */
- public Map<String, Set<String>> getKeys() {
- return fKeys;
+ return curNode;
}
/**
*
* @param path
* Path to the node.
- * @return The node.
- */
- public TmfStatisticsTreeNode getOrCreate(String... path) {
- List<String> pathAsList = Arrays.asList(path);
- TmfStatisticsTreeNode current = fNodes.get(pathAsList);
-
- if (current == null) {
- registerName(path);
- current = new TmfStatisticsTreeNode(this, path);
- fNodes.put(pathAsList, current);
- }
- return current;
- }
-
- /**
- * Get the parent of a node.
- *
- * @param path
- * Path to the node.
- * @return Parent node or null.
- */
- public TmfStatisticsTreeNode getParent(final String... path) {
- if (path.length == 1) {
- if (path.equals(ROOT)) {
- return null;
+ * @return The requested node. Will be created if it didn't exist.
+ */
+ public TmfStatisticsTreeNode getOrCreateNode(String... path) {
+ TmfStatisticsTreeNode curNode = rootNode;
+ TmfStatisticsTreeNode nextNode;
+ for (String pathElem : path) {
+ nextNode = curNode.getChild(pathElem);
+ if (nextNode == null) {
+ nextNode = curNode.addChild(pathElem);
}
- return get(ROOT);
+ curNode = nextNode;
}
-
- String[] parentPath = new String[path.length - 1];
- System.arraycopy(path, 0, parentPath, 0, parentPath.length);
- return get(parentPath);
+ return curNode;
}
/**
public void setTotal(String traceName, boolean isGlobal, long qty) {
String[][] paths = getNormalPaths(traceName);
for (String path[] : paths) {
- getOrCreate(path).getValues().setValue(isGlobal, qty);
+ getOrCreateNode(path).getValues().setValue(isGlobal, qty);
}
}
public void setTypeCount(String traceName, String type, boolean isGlobal, long qty) {
String[][] paths = getTypePaths(traceName, type);
for (String[] path : paths) {
- getOrCreate(path).getValues().setValue(isGlobal, qty);
+ getOrCreateNode(path).getValues().setValue(isGlobal, qty);
}
}
return paths;
}
- /**
- * Register that a new node was created.
- *
- * Must make sure the {@link #getChildren(TmfFixedArray)} on the parent node
- * will return the newly created node.
- *
- * @param path
- * Path of the new node.
- */
- protected void registerName(String... path) {
- if (path.length == 1) {
- if (!path.equals(ROOT)) {
- getKeys().get(ROOT[0]).add(path[0]);
- }
- } else if (path.length % 2 != 0) {
- getKeys().get(path[path.length - 2]).add(path[path.length - 1]);
- }
- }
-
- /**
- * Resets a node.
- *
- * Works recursively.
- *
- * @param path
- * Path to the node.
- */
- public void reset(final String... path) {
- for (TmfStatisticsTreeNode node : getAllChildren(path)) {
- reset(node.getPath());
- List<String> nodePathList = Arrays.asList(node.getPath());
- fNodes.remove(nodePathList);
- }
- }
-
- /**
- * Reset the global value of a node.
- *
- * Works recursively.
- *
- * @param path
- * Path to the node.
- * @since 2.0
- */
- public void resetGlobalValue(final String... path) {
- for (TmfStatisticsTreeNode node : getChildren(path)) {
- node.resetGlobalValue();
- }
- }
-
- /**
- * Reset the time range value of a node.
- *
- * Works recursively.
- *
- * @param path
- * Path to the node.
- * @since 2.0
- */
- public void resetTimeRangeValue(final String... path) {
- for (TmfStatisticsTreeNode node : getChildren(path)) {
- node.resetTimeRangeValue();
- }
- }
-
/**
* Function to merge many string more efficiently.
*
}
return builder.toString();
}
-
- /**
- * 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;
- }
}
* root node is created for each tree. Using the tree node ID the statistics
* tree can be retrieved.
*
+ * @author Mathieu Denis
* @version 2.0
* @since 2.0
- * @author Mathieu Denis
*/
public class TmfStatisticsTreeManager {
if (tree == null) {
return null;
}
- return tree.getOrCreate(TmfStatisticsTree.ROOT);
+ return tree.getRootNode();
}
/**
return null;
}
fTreeInstances.put(traceUniqueId, statsData);
- // if called for the first time, create the root node
- return statsData.getOrCreate(TmfStatisticsTree.ROOT);
+ return statsData.getRootNode();
}
/**
* Yann N. Dauphin <dhaemon@gmail.com> - Implementation for stats
* Francois Godin <copelnug@gmail.com> - Re-design for new stats structure
* Mathieu Denis <mathieu.denis@polymtl.ca> - Re-design for new stats structure (2)
+ * Alexandre Montplaisir - Move the tree structure logic into the nodes
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
/**
* A tree where nodes can be accessed efficiently using paths.
* array of String. The elements of the array represent the path from the root
* to this node.
*
+ * @author Mathieu Denis
* @version 2.0
* @since 2.0
- * @author Mathieu Denis
*/
public class TmfStatisticsTreeNode {
- /**
- * Value of the node.
- */
- protected TmfStatisticsValues fValues;
+ /** Tree to which this node belongs */
+ private final TmfStatisticsTree fTree;
- /**
- * Path of the node.
- */
- protected String[] fPath;
+ /** Path of this node. The last element represents its basename. */
+ private final String[] fPath;
- /**
- * Corresponding StatisticsData.
- */
- protected TmfStatisticsTree fNodes;
+ /** Parent node */
+ private final TmfStatisticsTreeNode fParent;
+
+ /** Children of this node, indexed by their basename. */
+ private final Map<String, TmfStatisticsTreeNode> fChildren;
+
+ /** Statistics values associated to this node. */
+ private final TmfStatisticsValues fValues;
/**
* Constructor.
*
+ * @param tree
+ * Owner tree of this node
+ * @param parent
+ * Parent node of this one
* @param path
* Path to the node.
- * @param nodes
- * Corresponding StatisticsData.
*/
- public TmfStatisticsTreeNode(TmfStatisticsTree nodes, final String... path) {
+ public TmfStatisticsTreeNode(TmfStatisticsTree tree,
+ TmfStatisticsTreeNode parent, final String... path) {
+ /* The path must not contain any null element, or else we won't be
+ * able to walk the tree. */
+ for (String elem : path) {
+ if (elem == null) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ fTree = tree;
fPath = path;
- fNodes = nodes;
+ fParent = parent;
+ fChildren = new HashMap<String, TmfStatisticsTreeNode>();
fValues = new TmfStatisticsValues();
}
+ /**
+ * Get the name for this node. It's used as the key in the parent's node.
+ *
+ * @return Name of this node.
+ */
+ public String getName() {
+ if (fPath.length == 0) {
+ /* This means we are the root node, which has no path itself */
+ return "root"; //$NON-NLS-1$
+ }
+ return fPath[fPath.length - 1];
+ }
+
/**
* Test if a node contain the specified child.
*
- * @param key
+ * @param childName
* Name of the child.
* @return true: if child with given key is present, false: if no child
* exists with given key name
*/
- public boolean containsChild(String key) {
- if (TmfStatisticsTree.ROOT.equals(fPath)) {
- return fNodes.get(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);
+ public boolean containsChild(String childName) {
+ return fChildren.containsKey(childName);
}
/**
- * Get the children of this node.
+ * Retrieve the given child from this node.
*
- * @return Direct children of this node.
+ * @param childName
+ * The (base)name of the child you want
+ * @return The child object, or null if it doesn't exist
*/
- public Collection<TmfStatisticsTreeNode> getChildren() {
- return fNodes.getChildren(fPath);
+ public TmfStatisticsTreeNode getChild(String childName) {
+ return fChildren.get(childName);
}
/**
- * Gets every children of this node even if no event has been registered for a node.
+ * Get the children of this node.
*
* @return Direct children of this node.
*/
- public Collection<TmfStatisticsTreeNode> getAllChildren() {
- return fNodes.getAllChildren(fPath);
+ public Collection<TmfStatisticsTreeNode> getChildren() {
+ return fChildren.values();
}
/**
- * Get the key for this node.
+ * Add a child to this node.
*
- * @return Key associated with this node.
+ * @param childName
+ * Name of the child to add
+ * @return The newly-created child
*/
- public String getKey() {
- return fPath[fPath.length - 1];
+ public TmfStatisticsTreeNode addChild(String childName) {
+ TmfStatisticsTreeNode child;
+ String[] childPath = new String[fPath.length + 1];
+ System.arraycopy(fPath, 0, childPath, 0, fPath.length);
+ childPath[fPath.length] = childName;
+
+ child = new TmfStatisticsTreeNode(this.fTree, this, childPath);
+ fChildren.put(childName, child);
+ return child;
}
/**
* @return Number of direct children of this node.
*/
public int getNbChildren() {
- return fNodes.getChildren(fPath).size();
+ return fChildren.size();
}
/**
* @return Parent node.
*/
public TmfStatisticsTreeNode getParent() {
- return fNodes.getParent(fPath);
+ return fParent;
}
/**
* @return True if the node has children.
*/
public boolean hasChildren() {
- return !fNodes.getChildren(fPath).isEmpty();
+ return (fChildren.size() > 0);
}
/**
* no children.
*/
public void reset() {
- fValues = new TmfStatisticsValues();
- fNodes.reset(fPath);
+ fValues.resetTotalCount();
+ fValues.resetPartialCount();
+ fChildren.clear();
}
/**
* Resets the global number of events. It doesn't remove any node
- * and doesn't modify the partial event count.
- *
- * Works recursively.
+ * and doesn't modify the partial event count. Works recursively.
*
* @since 2.0
*/
public void resetGlobalValue() {
- getValues().resetTotalCount();
- fNodes.resetGlobalValue(fPath);
+ for (TmfStatisticsTreeNode child : fChildren.values()) {
+ child.resetGlobalValue();
+ }
+ fValues.resetTotalCount();
}
/**
* Resets the number of events in the time range. It doesn't remove any node
- * and doesn't modify the global event count.
- *
- * Works recursively.
+ * and doesn't modify the global event count. Works recursively.
*
* @since 2.0
*/
public void resetTimeRangeValue() {
- getValues().resetPartialCount();
- fNodes.resetTimeRangeValue(fPath);
+ for (TmfStatisticsTreeNode child : fChildren.values()) {
+ child.resetTimeRangeValue();
+ }
+ fValues.resetPartialCount();
+ }
+
+ @Override
+ public String toString() {
+ /* Used for debugging only */
+ return "Stats node, path = " + Arrays.toString(fPath) + //$NON-NLS-1$
+ ", values = " + fValues.toString(); //$NON-NLS-1$
}
}
public void resetPartialCount() {
fNbEventsInTimeRange = 0;
}
+
+ @Override
+ public String toString() {
+ return fNbEvents + ", " + fNbEventsInTimeRange; //$NON-NLS-1$
+ }
}