*/
private final ITmfStateSystem stats;
+ /**
+ * Empty constructor. The resulting TmfStatistics object will not be usable,
+ * but it might be needed for sub-classes.
+ */
public TmfStatistics() {
stats = null;
}
suite.addTestSuite(TmfBaseColumnDataTest.class);
suite.addTestSuite(TmfBaseStatisticsDataTest.class);
suite.addTestSuite(TmfStatisticsTreeNodeTest.class);
- suite.addTestSuite(TmfStatisticsTreeRootFactoryTest.class);
+ suite.addTestSuite(TmfStatisticsTreeManagerTest.class);
suite.addTestSuite(TmfTreeContentProviderTest.class);
suite.addTestSuite(TmfStatisticsTest.class);
// $JUnit-END$
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.TmfBaseColumnDataProvider;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
/**
private final TmfEventField fContent2;
private final TmfEventField fContent3;
- private final TmfBaseStatisticsTree fStatsData;
+ private final TmfStatisticsTree fStatsData;
// ------------------------------------------------------------------------
// Housekeeping
fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType3, fContent3, fReference);
- fStatsData = new TmfBaseStatisticsTree();
+ fStatsData = new TmfStatisticsTree();
fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes);
import org.eclipse.jface.viewers.ViewerComparator;
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;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
}
};
- TmfBaseStatisticsTree baseData = new TmfBaseStatisticsTree();
+ TmfStatisticsTree baseData = new TmfStatisticsTree();
fTraceName = "trace1";
fTreeNode = new TmfStatisticsTreeNode(baseData, fTraceName);
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.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
/**
private final TmfEventField fContent2;
private final TmfEventField fContent3;
- private final TmfBaseStatisticsTree fStatsData;
+ private final TmfStatisticsTree fStatsData;
// ------------------------------------------------------------------------
// Housekeeping
fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType3, fContent3, fReference);
- fStatsData = new TmfBaseStatisticsTree();
+ fStatsData = new TmfStatisticsTree();
fStatsData.setTotal(fTestName, true, 3);
fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), true, 1);
*/
public void testGetChildren() {
// Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(AbsTmfStatisticsTree.ROOT);
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(TmfStatisticsTree.ROOT);
assertEquals("getChildren", 1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", fTestName, treeNode.getKey());
*/
public void testGetAllChildren() {
// Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getAllChildren(AbsTmfStatisticsTree.ROOT);
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getAllChildren(TmfStatisticsTree.ROOT);
assertEquals("getChildren", 1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", fTestName, treeNode.getKey());
* Test getting of parent node.
*/
public void testGetParent() {
- TmfStatisticsTreeNode parentNode = fStatsData.getParent(AbsTmfStatisticsTree.ROOT);
+ 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(AbsTmfStatisticsTree.ROOT).getKey().toString()));
+ assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(TmfStatisticsTree.ROOT).getKey().toString()));
parentNode = fStatsData.getParent("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist");
assertNull("getParent", parentNode);
parentNode = fStatsData.getParent(fTestName);
assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(AbsTmfStatisticsTree.ROOT.toString()));
+ assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(TmfStatisticsTree.ROOT.toString()));
parentNode = fStatsData.getParent(fTestName, Messages.TmfStatisticsData_EventTypes);
assertNotNull("getParent", parentNode);
--- /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
+ * Bernd Hufmann - Fixed warnings
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.tests.statistics;
+
+import junit.framework.TestCase;
+
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
+
+/**
+ * TmfStatisticsTreeRootFactory Test Case.
+ */
+@SuppressWarnings("nls")
+public class TmfStatisticsTreeManagerTest extends TestCase {
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
+
+ TmfStatisticsTree fStatisticsData1;
+ TmfStatisticsTree fStatisticsData2;
+ TmfStatisticsTree fStatisticsData3;
+ String fDataKey1 = "key1";
+ String fDataKey2 = "key2";
+ String fDataKey3 = "key3";
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ addStatsTreeRoot();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Adding of statistics tree root.
+ */
+ public void addStatsTreeRoot() {
+ fStatisticsData1 = new TmfStatisticsTree();
+ fStatisticsData2 = new TmfStatisticsTree();
+ fStatisticsData3 = new TmfStatisticsTree();
+ TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey1, fStatisticsData1);
+ TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey2, fStatisticsData2);
+ TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey2, fStatisticsData3);
+ }
+
+ /**
+ * Clean the statistics tree
+ */
+ public void removeStatsTreeRoot() {
+ TmfStatisticsTreeManager.removeAll();
+ }
+
+ /**
+ * Test adding of statistics tree root. It should not throw exceptions
+ */
+ public void testaddStatsTreeRoot() {
+ removeStatsTreeRoot();
+
+ try {
+ assertNull(TmfStatisticsTreeManager.addStatsTreeRoot(null, null));
+ assertNull(TmfStatisticsTreeManager.addStatsTreeRoot(null, fStatisticsData1));
+ assertNull(TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey1, null));
+ assertNull(TmfStatisticsTreeManager.getStatTreeRoot(fDataKey1));
+
+ TmfStatisticsTreeNode returnRootNode = TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey1, fStatisticsData1);
+ assertSame(fStatisticsData1, TmfStatisticsTreeManager.getStatTree(fDataKey1));
+ assertSame(fStatisticsData1.get(TmfStatisticsTree.ROOT), returnRootNode);
+
+ // Overwriting the value
+ returnRootNode = TmfStatisticsTreeManager.addStatsTreeRoot(fDataKey1, fStatisticsData2);
+ assertSame(fStatisticsData2, TmfStatisticsTreeManager.getStatTree(fDataKey1));
+ assertSame(fStatisticsData2.get(TmfStatisticsTree.ROOT), returnRootNode);
+
+ // Success
+ } catch(Exception e) {
+ fail("AddStatsTreeRoot");
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // get
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test getting of statistics tree root.
+ */
+ public void testGetStatTreeRoot() {
+ TmfStatisticsTreeNode value1 = TmfStatisticsTreeManager.getStatTreeRoot(fDataKey1);
+ TmfStatisticsTreeNode value2 = TmfStatisticsTreeManager.getStatTreeRoot(fDataKey2);
+ TmfStatisticsTreeNode value3 = TmfStatisticsTreeManager.getStatTreeRoot(fDataKey1);
+ assertNotSame("getStatTreeRoot", value1, value2);
+ assertNotSame("getStatTreeRoot", value2, value3);
+ assertSame("getStatTreeRoot", value1, value3);
+ assertNull("getStatTreeRoot", TmfStatisticsTreeManager.getStatTreeRoot(null));
+ }
+
+ /**
+ * Test getting statistics tree.
+ */
+ public void testGetStatTree() {
+ TmfStatisticsTree value1 = TmfStatisticsTreeManager.getStatTree(fDataKey1);
+ TmfStatisticsTree value2 = TmfStatisticsTreeManager.getStatTree(fDataKey2);
+ TmfStatisticsTree value3 = TmfStatisticsTreeManager.getStatTree(fDataKey1);
+ assertNotSame("getStatTree", value1, value2);
+ assertNotSame("getStatTree", value2, value3);
+ assertSame("getStatTree", value1, value3);
+ assertNull("getStatTreeRoot", TmfStatisticsTreeManager.getStatTree(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // contains
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test checking for tree root existence.
+ */
+ public void testContainsTreeRoot() {
+ assertTrue("containsTreeRoot", TmfStatisticsTreeManager.containsTreeRoot(fDataKey1));
+ assertTrue("containsTreeRoot", TmfStatisticsTreeManager.containsTreeRoot(fDataKey2));
+ assertFalse("containsTreeRoot", TmfStatisticsTreeManager.containsTreeRoot(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // remove
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test removal of statistics tree node.
+ */
+ public void testRemoveStatTreeRoot() {
+ TmfStatisticsTreeManager.removeStatTreeRoot(fDataKey1);
+ assertNull("removeStatTreeRoot", TmfStatisticsTreeManager.getStatTree(fDataKey1));
+
+ try {
+ // Trying to remove the same branch from the tree.
+ TmfStatisticsTreeManager.removeStatTreeRoot(fDataKey1);
+
+ TmfStatisticsTreeManager.removeStatTreeRoot(null);
+ // Success
+ } catch (Exception e) {
+ fail("removeStatTreeRoot");
+ }
+ }
+
+ /**
+ * Test removal of all root nodes.
+ */
+ public void testRemoveAll() {
+ TmfStatisticsTreeManager.removeAll();
+ assertNull("removeAll", TmfStatisticsTreeManager.getStatTreeRoot(fDataKey2));
+ assertNull("removeAll", TmfStatisticsTreeManager.getStatTreeRoot(fDataKey3));
+ }
+}
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.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
/**
private final TmfEventField fContent2;
private final TmfEventField fContent3;
- private final TmfBaseStatisticsTree fStatsData;
+ private final TmfStatisticsTree fStatsData;
// ------------------------------------------------------------------------
// Housekeeping
fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType2, fContent3, fReference);
- fStatsData = new TmfBaseStatisticsTree();
+ fStatsData = new TmfStatisticsTree();
fStatsData.setTotal(fTestName, true, 9);
fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), true, 2);
* Test checking for child.
*/
public void testContainsChild() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
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[0]).getChildren();
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(TmfStatisticsTree.ROOT[0]).getChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", fTestName, treeNode.getKey());
*/
public void testGetAllChildren() {
// Getting children of the ROOT
- Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(AbsTmfStatisticsTree.ROOT).getAllChildren();
+ Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(TmfStatisticsTree.ROOT).getAllChildren();
assertEquals("getChildren", 1, childrenTreeNode.size());
TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
assertEquals("getChildren", fTestName, treeNode.getKey());
* Test getting of number of children.
*/
public void testGetNbChildren() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
* Test checking for children.
*/
public void testHasChildren() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
* Test getting of parent.
*/
public void testGetParent() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ TmfStatisticsTreeNode rootNode = fStatsData.get(TmfStatisticsTree.ROOT);
TmfStatisticsTreeNode parentNode = rootNode.getParent();
assertNull("getParent", parentNode);
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()));
+ assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(TmfStatisticsTree.ROOT).getKey().toString()));
TmfStatisticsTreeNode traceNode = fStatsData.get(fTestName);
parentNode = traceNode.getParent();
assertNotNull("getParent", parentNode);
- assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(AbsTmfStatisticsTree.ROOT.toString()));
+ assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(TmfStatisticsTree.ROOT.toString()));
TmfStatisticsTreeNode newNode = new TmfStatisticsTreeNode(fStatsData, "TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist");
parentNode = newNode.getParent();
* Test getting of key.
*/
public void testGetKey() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
- assertEquals("getKey", 0, rootNode.getKey().compareTo(AbsTmfStatisticsTree.ROOT[0]));
+ 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()));
* Test getting of path to node.
*/
public void testGetPath() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
- assertTrue("getPath", arraysEqual(rootNode.getPath(), AbsTmfStatisticsTree.ROOT));
+ assertTrue("getPath", arraysEqual(rootNode.getPath(), TmfStatisticsTree.ROOT));
assertTrue("getPath", arraysEqual(traceNode.getPath(), fTestName));
assertTrue("getPath", arraysEqual(catNode.getPath(),
fTestName, Messages.TmfStatisticsData_EventTypes));
* Test getting statistic value.
*/
public void testGetValue() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
* Test reset of tree.
*/
public void testReset() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
* the global value without removing any node from the tree.
*/
public void testResetGlobalValue() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
* the time range value without removing any node from the tree.
*/
public void testResetTimeRangeValue() {
- TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ 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());
+++ /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
- * Bernd Hufmann - Fixed warnings
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.ui.tests.statistics;
-
-import junit.framework.TestCase;
-
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeRootFactory;
-
-/**
- * TmfStatisticsTreeRootFactory Test Case.
- */
-@SuppressWarnings("nls")
-public class TmfStatisticsTreeRootFactoryTest extends TestCase {
-
- // ------------------------------------------------------------------------
- // Fields
- // ------------------------------------------------------------------------
-
- AbsTmfStatisticsTree fStatisticsData1;
- AbsTmfStatisticsTree fStatisticsData2;
- AbsTmfStatisticsTree fStatisticsData3;
- String fDataKey1 = "key1";
- String fDataKey2 = "key2";
- String fDataKey3 = "key3";
-
- // ------------------------------------------------------------------------
- // Housekeeping
- // ------------------------------------------------------------------------
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- addStatsTreeRoot();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Adding of statistics tree root.
- */
- public void addStatsTreeRoot() {
- fStatisticsData1 = new TmfBaseStatisticsTree();
- fStatisticsData2 = new TmfBaseStatisticsTree();
- fStatisticsData3 = new TmfBaseStatisticsTree();
- TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, fStatisticsData1);
- TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey2, fStatisticsData2);
- TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey2, fStatisticsData3);
- }
-
- /**
- * Clean the statistics tree
- */
- public void removeStatsTreeRoot() {
- TmfStatisticsTreeRootFactory.removeAll();
- }
-
- /**
- * Test adding of statistics tree root. It should not throw exceptions
- */
- public void testaddStatsTreeRoot() {
- removeStatsTreeRoot();
-
- try {
- assertNull(TmfStatisticsTreeRootFactory.addStatsTreeRoot(null, null));
- assertNull(TmfStatisticsTreeRootFactory.addStatsTreeRoot(null, fStatisticsData1));
- assertNull(TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, null));
- assertNull(TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey1));
-
- TmfStatisticsTreeNode returnRootNode = TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, fStatisticsData1);
- assertSame(fStatisticsData1, TmfStatisticsTreeRootFactory.getStatTree(fDataKey1));
- assertSame(fStatisticsData1.get(AbsTmfStatisticsTree.ROOT), returnRootNode);
-
- // Overwriting the value
- returnRootNode = TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, fStatisticsData2);
- assertSame(fStatisticsData2, TmfStatisticsTreeRootFactory.getStatTree(fDataKey1));
- assertSame(fStatisticsData2.get(AbsTmfStatisticsTree.ROOT), returnRootNode);
-
- // Success
- } catch(Exception e) {
- fail("AddStatsTreeRoot");
- }
- }
-
- // ------------------------------------------------------------------------
- // get
- // ------------------------------------------------------------------------
-
- /**
- * Test getting of statistics tree root.
- */
- public void testGetStatTreeRoot() {
- TmfStatisticsTreeNode value1 = TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey1);
- TmfStatisticsTreeNode value2 = TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey2);
- TmfStatisticsTreeNode value3 = TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey1);
- assertNotSame("getStatTreeRoot", value1, value2);
- assertNotSame("getStatTreeRoot", value2, value3);
- assertSame("getStatTreeRoot", value1, value3);
- assertNull("getStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTreeRoot(null));
- }
-
- /**
- * Test getting statistics tree.
- */
- public void testGetStatTree() {
- AbsTmfStatisticsTree value1 = TmfStatisticsTreeRootFactory.getStatTree(fDataKey1);
- AbsTmfStatisticsTree value2 = TmfStatisticsTreeRootFactory.getStatTree(fDataKey2);
- AbsTmfStatisticsTree value3 = TmfStatisticsTreeRootFactory.getStatTree(fDataKey1);
- assertNotSame("getStatTree", value1, value2);
- assertNotSame("getStatTree", value2, value3);
- assertSame("getStatTree", value1, value3);
- assertNull("getStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTree(null));
- }
-
- // ------------------------------------------------------------------------
- // contains
- // ------------------------------------------------------------------------
-
- /**
- * Test checking for tree root existence.
- */
- public void testContainsTreeRoot() {
- assertTrue("containsTreeRoot", TmfStatisticsTreeRootFactory.containsTreeRoot(fDataKey1));
- assertTrue("containsTreeRoot", TmfStatisticsTreeRootFactory.containsTreeRoot(fDataKey2));
- assertFalse("containsTreeRoot", TmfStatisticsTreeRootFactory.containsTreeRoot(null));
- }
-
- // ------------------------------------------------------------------------
- // remove
- // ------------------------------------------------------------------------
-
- /**
- * Test removal of statistics tree node.
- */
- public void testRemoveStatTreeRoot() {
- TmfStatisticsTreeRootFactory.removeStatTreeRoot(fDataKey1);
- assertNull("removeStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTree(fDataKey1));
-
- try {
- // Trying to remove the same branch from the tree.
- TmfStatisticsTreeRootFactory.removeStatTreeRoot(fDataKey1);
-
- TmfStatisticsTreeRootFactory.removeStatTreeRoot(null);
- // Success
- } catch (Exception e) {
- fail("removeStatTreeRoot");
- }
- }
-
- /**
- * Test removal of all root nodes.
- */
- public void testRemoveAll() {
- TmfStatisticsTreeRootFactory.removeAll();
- assertNull("removeAll", TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey2));
- assertNull("removeAll", TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey3));
- }
-}
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.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
private final TmfEventField fContent1;
private final TmfEventField fContent2;
- private final TmfBaseStatisticsTree fStatsData;
+ private final TmfStatisticsTree fStatsData;
private final TmfTreeContentProvider treeProvider;
fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other content");
fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType2, fContent2, fReference);
- fStatsData = new TmfBaseStatisticsTree();
+ fStatsData = new TmfStatisticsTree();
fStatsData.setTotal(fTestName, true, 2);
fStatsData.setTypeCount(fTestName, fEvent1.getType().getName(), true, 1);
TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.get(fTestName));
assertNotNull("getParent", parent);
- assertTrue("getParent", parent.getPath().equals(AbsTmfStatisticsTree.ROOT));
+ assertTrue("getParent", parent.getPath().equals(TmfStatisticsTree.ROOT));
}
// ------------------------------------------------------------------------
* Test checking for children.
*/
public void testHasChildren() {
- Boolean hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(AbsTmfStatisticsTree.ROOT));
+ Boolean hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(TmfStatisticsTree.ROOT));
assertTrue("hasChildren", hasChildren);
hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName));
* Test getting of elements.
*/
public void testGetElements() {
- Object[] objectElements = treeProvider.getElements(fStatsData.get(AbsTmfStatisticsTree.ROOT));
+ Object[] objectElements = treeProvider.getElements(fStatsData.get(TmfStatisticsTree.ROOT));
TmfStatisticsTreeNode[] nodeElements = Arrays.asList(objectElements).toArray(new TmfStatisticsTreeNode[0]);
assertEquals("getElements", 1, nodeElements.length);
assertTrue("getElements", nodeElements[0].getPath()[0].equals(fTestName));
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewer;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.ITmfColumnDataProvider;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
-import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeRootFactory;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
/**
* The statistics tree linked to this viewer
*/
- protected AbsTmfStatisticsTree fStatisticsData;
+ protected TmfStatisticsTree fStatisticsData;
/**
* Update synchronization parameter (used for streaming): Update busy
}
// Clean the model for this viewer
- TmfStatisticsTreeRootFactory.removeStatTreeRoot(getTreeID());
+ TmfStatisticsTreeManager.removeStatTreeRoot(getTreeID());
}
/**
*
* @return a TmfStatisticsData object.
*/
- public AbsTmfStatisticsTree getStatisticData() {
+ public TmfStatisticsTree getStatisticData() {
if (fStatisticsData == null) {
- fStatisticsData = new TmfBaseStatisticsTree();
+ fStatisticsData = new TmfStatisticsTree();
}
return fStatisticsData;
}
protected void initInput() {
String treeID = getTreeID();
TmfStatisticsTreeNode experimentTreeNode;
- if (TmfStatisticsTreeRootFactory.containsTreeRoot(treeID)) {
+ if (TmfStatisticsTreeManager.containsTreeRoot(treeID)) {
// The experiment root is already present
- experimentTreeNode = TmfStatisticsTreeRootFactory.getStatTreeRoot(treeID);
+ experimentTreeNode = TmfStatisticsTreeManager.getStatTreeRoot(treeID);
// Checks if the trace is already in the statistics tree.
int numNodeTraces = experimentTreeNode.getNbChildren();
}
} else {
// Creates a new tree
- experimentTreeNode = TmfStatisticsTreeRootFactory.addStatsTreeRoot(treeID, getStatisticData());
+ experimentTreeNode = TmfStatisticsTreeManager.addStatsTreeRoot(treeID, getStatisticData());
}
// Sets the input to a clean data model
* partial one.
*/
private void buildStatisticsTree(final TmfExperiment experiment, TmfTimeRange timeRange, boolean isGlobal) {
- final TmfStatisticsTreeNode statTree = TmfStatisticsTreeRootFactory.getStatTreeRoot(getTreeID());
- final AbsTmfStatisticsTree statsData = TmfStatisticsTreeRootFactory.getStatTree(getTreeID());
+ final TmfStatisticsTreeNode statTree = TmfStatisticsTreeManager.getStatTreeRoot(getTreeID());
+ final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID());
if (statsData == null) {
return;
}
* Are we updating the Global data (for the complete time range
* of the trace), or the selected time range data?
*/
- protected void updateValues(AbsTmfStatisticsTree statsData, ITmfTrace trace,
+ protected void updateValues(TmfStatisticsTree statsData, ITmfTrace trace,
TmfTimeRange timeRange, boolean isGlobal) {
ITmfStatistics stats = trace.getStatistics();
* Resets the number of events within the time range
*/
protected void resetTimeRangeValue() {
- TmfStatisticsTreeNode treeModelRoot = TmfStatisticsTreeRootFactory.getStatTreeRoot(getTreeID());
+ TmfStatisticsTreeNode treeModelRoot = TmfStatisticsTreeManager.getStatTreeRoot(getTreeID());
if (treeModelRoot != null && treeModelRoot.hasChildren()) {
treeModelRoot.resetTimeRangeValue();
}
+++ /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:
- * Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
- *
- *******************************************************************************/
-
-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;
-
-/**
- * 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
- * node at a given place.
- *
- * @version 2.0
- * @author Mathieu Denis
- * @since 2.0
- */
-public abstract class AbsTmfStatisticsTree {
-
- /**
- * String builder used to merge string more efficiently.
- */
- protected static final StringBuilder fBuilder = new StringBuilder();
-
- /**
- * Identification of the root.
- */
- public static final String[] ROOT = new String[] { "root" }; //$NON-NLS-1$
-
- /**
- * Function to merge many string more efficiently.
- *
- * @param strings
- * Strings to merge.
- * @return A new string containing all the strings.
- */
- public synchronized static String mergeString(String... strings) {
- fBuilder.setLength(0);
- for (String s : strings) {
- fBuilder.append(s);
- }
- return fBuilder.toString();
- }
-
- /**
- * 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;
-
- /**
- * Constructor.
- */
- public AbsTmfStatisticsTree() {
- fNodes = new HashMap<List<String>, TmfStatisticsTreeNode>();
- fKeys = new HashMap<String, Set<String>>();
- }
-
- /**
- * 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);
- }
-
- /**
- * Get the children of a node.
- *
- * @param path
- * Path to the node.
- * @return Collection containing the children.
- */
- public abstract Collection<TmfStatisticsTreeNode> getChildren(final String... path);
-
- /**
- * Get every children of a node, even if it doesn't have any registered
- * events, as opposed to getChildren
- *
- * @param path
- * Path to the node.
- * @return Collection containing all the children.
- */
- public abstract Collection<TmfStatisticsTreeNode> getAllChildren(final String... path);
-
- /**
- * Get the map of existing elements of path classified by parent.
- *
- * @return The map.
- */
- public Map<String, Set<String>> getKeys() {
- return fKeys;
- }
-
- /**
- * Get or create a node.
- *
- * @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 get(ROOT);
- }
-
- String[] parentPath = new String[path.length - 1];
- System.arraycopy(path, 0, parentPath, 0, parentPath.length);
- return get(parentPath);
- }
-
- /**
- * Set the value to display in the "total" cells. This means the row
- * indicating the total count of events for a trace.
- *
- * @param traceName
- * The name of the trace (will be used as a sub-tree in the view)
- * @param isGlobal
- * Is this a for a global or a time range request? Determines if
- * this goes in the Global column or the Selected Time Range one.
- * @param qty
- * The value to display
- */
- public abstract void setTotal(String traceName, boolean isGlobal, long qty);
-
- /**
- * Set the value to display in the "Type count" cells. These are the counts
- * for each event types.
- *
- * @param traceName
- * The name of the trace (will be used as a sub-tree in the view)
- * @param type
- * The event type
- * @param isGlobal
- * Is this a for a global or a time range request? Determines if
- * this goes in the Global column or the Selected Time Range one.
- * @param qty
- * The value to display
- */
- public abstract void setTypeCount(String traceName, String type,
- boolean isGlobal, long qty);
-
- /**
- * 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 abstract void registerName(final String... path);
-
- /**
- * 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();
- }
- }
-}
+++ /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:
- * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and Implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Store information about base statistics data.
- *
- * This class provides a way to represent statistics data that is compatible
- * with every type of trace.
- *
- * @version 2.0
- * @author Mathieu Denis
- * @since 2.0
- */
-public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
-
- /**
- * 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);
-
- /**
- * Default constructor. Creates base statistics tree for counting total
- * number of events and number of events per event type.
- */
- public TmfBaseStatisticsTree() {
- super();
- 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);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getChildren
- * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
- */
- @Override
- 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;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getAllChildren
- * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
- */
- @Override
- public Collection<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 result;
- }
-
- @Override
- public void setTotal(String traceName, boolean isGlobal, long qty) {
- 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) {
- String[][] paths = getTypePaths(traceName, type);
- for (String[] path : paths) {
- getOrCreate(path).getValues().setValue(isGlobal, qty);
- }
- }
-
- /**
- * Get the event types paths.
- *
- * @param event
- * Event to get the path for.
- * @param extraInfo
- * Extra information to pass along with the event
- * @return Array of FixedArray representing the paths.
- */
- protected String[][] getTypePaths(String traceName, String type) {
- String[][] paths = { new String[] {traceName, HEADER_EVENT_TYPES, type } };
- return paths;
- }
-
- /**
- * Get the standard paths for an event.
- *
- * @param event
- * Event to get the path for.
- * @param extraInfo
- * Extra information to pass along with the event
- * @return Array of FixedArray representing the paths.
- */
- protected String[][] getNormalPaths(String traceName) {
- String[][] paths = { new String[] { traceName } };
- return paths;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerName
- * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
- */
- @Override
- 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]);
- }
- }
-
- /**
- * 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;
- }
-}
--- /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:
+ * Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
+ *
+ *******************************************************************************/
+
+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
+ * while avoiding the need to run through the tree each time you need to add a
+ * node at a given place.
+ *
+ * @author Mathieu Denis
+ * @version 2.0
+ * @since 2.0
+ */
+public class TmfStatisticsTree {
+
+ /**
+ * Identification of the root.
+ */
+ public static final String[] ROOT = new String[] { "root" }; //$NON-NLS-1$
+
+ /**
+ * 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;
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Get the children of a node.
+ *
+ * @param path
+ * Path to the node.
+ * @return Collection containing the children.
+ */
+ 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;
+ }
+
+ /**
+ * Get every children of a node, even if it doesn't have any registered
+ * events, as opposed to getChildren
+ *
+ * @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 result;
+ }
+
+ /**
+ * Get the map of existing elements of path classified by parent.
+ *
+ * @return The map.
+ */
+ public Map<String, Set<String>> getKeys() {
+ return fKeys;
+ }
+
+ /**
+ * Get or create a node.
+ *
+ * @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 get(ROOT);
+ }
+
+ String[] parentPath = new String[path.length - 1];
+ System.arraycopy(path, 0, parentPath, 0, parentPath.length);
+ return get(parentPath);
+ }
+
+ /**
+ * Set the value to display in the "total" cells. This means the row
+ * indicating the total count of events for a trace.
+ *
+ * @param traceName
+ * The name of the trace (will be used as a sub-tree in the view)
+ * @param isGlobal
+ * Is this a for a global or a time range request? Determines if
+ * this goes in the Global column or the Selected Time Range one.
+ * @param qty
+ * The value to display
+ */
+ public void setTotal(String traceName, boolean isGlobal, long qty) {
+ String[][] paths = getNormalPaths(traceName);
+ for (String path[] : paths) {
+ getOrCreate(path).getValues().setValue(isGlobal, qty);
+ }
+ }
+
+ /**
+ * Set the value to display in the "Type count" cells. These are the counts
+ * for each event types.
+ *
+ * @param traceName
+ * The name of the trace (will be used as a sub-tree in the view)
+ * @param type
+ * The event type
+ * @param isGlobal
+ * Is this a for a global or a time range request? Determines if
+ * this goes in the Global column or the Selected Time Range one.
+ * @param qty
+ * The value to display
+ */
+ 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);
+ }
+ }
+
+ /**
+ * Get the event types paths.
+ *
+ * @param event
+ * Event to get the path for.
+ * @param extraInfo
+ * Extra information to pass along with the event
+ * @return Array of FixedArray representing the paths.
+ */
+ protected String[][] getTypePaths(String traceName, String type) {
+ String[][] paths = { new String[] {traceName, HEADER_EVENT_TYPES, type } };
+ return paths;
+ }
+
+ /**
+ * Get the standard paths for an event.
+ *
+ * @param event
+ * Event to get the path for.
+ * @param extraInfo
+ * Extra information to pass along with the event
+ * @return Array of FixedArray representing the paths.
+ */
+ protected String[][] getNormalPaths(String traceName) {
+ String[][] paths = { new String[] { traceName } };
+ 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.
+ *
+ * @param strings
+ * Strings to merge.
+ * @return A new string containing all the strings.
+ */
+ protected static String mergeString(String... strings) {
+ StringBuilder builder = new StringBuilder();
+ for (String s : strings) {
+ builder.append(s);
+ }
+ 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;
+ }
+}
--- /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 API
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Factory class to create and store TMF statistic trees.
+ *
+ * Based on a given tree node ID a TMF statistic tree is stored internally. A
+ * root node is created for each tree. Using the tree node ID the statistics
+ * tree can be retrieved.
+ *
+ * @version 2.0
+ * @since 2.0
+ * @author Mathieu Denis
+ */
+public class TmfStatisticsTreeManager {
+
+ /**
+ * Contains the experiment name as the key and the traces data
+ */
+ private static final Map<String, TmfStatisticsTree> fTreeInstances = new HashMap<String, TmfStatisticsTree>();
+
+ /**
+ * Provide a statisticsTree instance per trace
+ *
+ * @param traceUniqueId
+ * Unique ID for the trace
+ * @return The root node of the corresponding trace statistics tree
+ */
+ public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) {
+
+ TmfStatisticsTree tree = getStatTree(traceUniqueId);
+ if (tree == null) {
+ return null;
+ }
+ return tree.getOrCreate(TmfStatisticsTree.ROOT);
+ }
+
+ /**
+ * Get the tree that's being used for statistics
+ *
+ * @param traceUniqueId
+ * Unique ID for the trace
+ * @return the corresponding trace statistics tree
+ */
+ public static TmfStatisticsTree getStatTree(String traceUniqueId) {
+ if (traceUniqueId == null) {
+ return null;
+ }
+
+ TmfStatisticsTree tree = fTreeInstances.get(traceUniqueId);
+ return tree;
+ }
+
+ /**
+ * Add the new trace statistics data in the tree. Can be used later on if
+ * the same traces is selected back.
+ *
+ * @param traceUniqueId
+ * The name of the trace which will be used as a key to store the
+ * data. Must be different for each traces, otherwise the traces
+ * might be overwritten which would trigger a reload of the same
+ * trace.
+ * @param statsData
+ * The information about the trace
+ * @return The newly created root node of the trace statistics tree, or null if something went wrong
+ */
+ public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, TmfStatisticsTree statsData) {
+ if (traceUniqueId == null || statsData == null) {
+ return null;
+ }
+ fTreeInstances.put(traceUniqueId, statsData);
+ // if called for the first time, create the root node
+ return statsData.getOrCreate(TmfStatisticsTree.ROOT);
+ }
+
+ /**
+ * Return if the given trace is currently known by the statistics manager.
+ *
+ * @param traceUniqueId
+ * The unique ID of the trace
+ * @return true if the trace id is known
+ */
+ public static boolean containsTreeRoot(String traceUniqueId) {
+ return fTreeInstances.containsKey(traceUniqueId);
+ }
+
+ /**
+ * Remove previously registered statistics tree.
+ *
+ * @param traceUniqueId
+ * The unique ID of the trace
+ */
+ public static void removeStatTreeRoot(String traceUniqueId) {
+ if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) {
+ fTreeInstances.remove(traceUniqueId);
+ }
+ }
+
+ /**
+ * Remove all tree and root instances
+ */
+ public static void removeAll() {
+ fTreeInstances.clear();
+ }
+}
/**
* Corresponding StatisticsData.
*/
- protected AbsTmfStatisticsTree fNodes;
+ protected TmfStatisticsTree fNodes;
/**
* Constructor.
* @param nodes
* Corresponding StatisticsData.
*/
- public TmfStatisticsTreeNode(AbsTmfStatisticsTree nodes, final String... path) {
+ public TmfStatisticsTreeNode(TmfStatisticsTree nodes, final String... path) {
fPath = path;
fNodes = nodes;
fValues = new TmfStatisticsValues();
* exists with given key name
*/
public boolean containsChild(String key) {
- if (AbsTmfStatisticsTree.ROOT.equals(fPath)) {
+ if (TmfStatisticsTree.ROOT.equals(fPath)) {
return fNodes.get(key) != null;
}
+++ /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 API
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Factory class to create and store TMF statistic trees.
- *
- * Based on a given tree node ID a TMF statistic tree is stored internally. A
- * root node is created for each tree. Using the tree node ID the statistics
- * tree can be retrieved.
- *
- * @version 2.0
- * @since 2.0
- * @author Mathieu Denis
- */
-public class TmfStatisticsTreeRootFactory {
-
- /**
- * Contains the experiment name as the key and the traces data
- */
- private static final Map<String, AbsTmfStatisticsTree> fTreeInstances = new HashMap<String, AbsTmfStatisticsTree>();
-
- /**
- * Provide a statisticsTree instance per trace
- *
- * @param traceUniqueId
- * Unique ID for the trace
- * @return The root node of the corresponding trace statistics tree
- */
- public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) {
-
- AbsTmfStatisticsTree tree = getStatTree(traceUniqueId);
- if (tree == null) {
- return null;
- }
- return tree.getOrCreate(AbsTmfStatisticsTree.ROOT);
- }
-
- /**
- * Get the tree that's being used for statistics
- *
- * @param traceUniqueId
- * Unique ID for the trace
- * @return the corresponding trace statistics tree
- */
- public static AbsTmfStatisticsTree getStatTree(String traceUniqueId) {
- if (traceUniqueId == null) {
- return null;
- }
-
- AbsTmfStatisticsTree tree = fTreeInstances.get(traceUniqueId);
- return tree;
- }
-
- /**
- * Add the new trace statistics data in the tree. Can be used later on if
- * the same traces is selected back.
- *
- * @param traceUniqueId
- * The name of the trace which will be used as a key to store the
- * data. Must be different for each traces, otherwise the traces
- * might be overwritten which would trigger a reload of the same
- * trace.
- * @param statsData
- * The information about the trace
- * @return The newly created root node of the trace statistics tree, or null if something went wrong
- */
- public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) {
- if (traceUniqueId == null || statsData == null) {
- return null;
- }
- fTreeInstances.put(traceUniqueId, statsData);
- // if called for the first time, create the root node
- return statsData.getOrCreate(AbsTmfStatisticsTree.ROOT);
- }
-
- /**
- * Return if the given trace is currently known by the statistics manager.
- *
- * @param traceUniqueId
- * The unique ID of the trace
- * @return true if the trace id is known
- */
- public static boolean containsTreeRoot(String traceUniqueId) {
- return fTreeInstances.containsKey(traceUniqueId);
- }
-
- /**
- * Remove previously registered statistics tree.
- *
- * @param traceUniqueId
- * The unique ID of the trace
- */
- public static void removeStatTreeRoot(String traceUniqueId) {
- if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) {
- fTreeInstances.remove(traceUniqueId);
- }
- }
-
- /**
- * Remove all tree and root instances
- */
- public static void removeAll() {
- fTreeInstances.clear();
- }
-}