tmf: Refactor TMF statistics
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 15 Oct 2012 21:51:31 +0000 (17:51 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 22 Oct 2012 22:28:52 +0000 (18:28 -0400)
Merge TmfBaseStatisticsTree into AbsTmfStatisticsTree. The abstract
version required both total and per-event-type statistics values
anyway, so there was no need to have a separate class that basically
implemented the required stuff.

Also renamed TmfStatisticsTreeNodeFactory to TmfStatisticsManager,
since it's more a manager for the complete stats trees.

Change-Id: If9942beb14ee0d978722d97e6bdfeafb693c9b66
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/8265
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
16 files changed:
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatistics.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/AllTests.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataProviderTest.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseColumnDataTest.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseStatisticsDataTest.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeManagerTest.java [new file with mode: 0755]
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeNodeTest.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java [deleted file]
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfTreeContentProviderTest.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/AbsTmfStatisticsTree.java [deleted file]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseStatisticsTree.java [deleted file]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTree.java [new file with mode: 0755]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeManager.java [new file with mode: 0755]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java [deleted file]

index edc7baec5f088bfe07e98aad775652ec2cfa6f7d..607a3239a1452eaa507dc8b88190c0f553a50442 100644 (file)
@@ -54,6 +54,10 @@ public class TmfStatistics  implements ITmfStatistics {
      */
     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;
     }
index 406204d7d4663e6e731209542af8c2e1bc8e9e73..4900f6617a5a69d773c8b8e64dd073f6bc233c7f 100644 (file)
@@ -31,7 +31,7 @@ public class AllTests {
         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$
index aafe246f24159f084857e70c9c1644fc4ea1a3d2..fd9f6d7bb330330a3f8e541d691a433a7d5409e5 100644 (file)
@@ -27,7 +27,7 @@ import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
 import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
 import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider;
 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;
 
 /**
@@ -76,7 +76,7 @@ public class TmfBaseColumnDataProviderTest extends TestCase {
     private final TmfEventField fContent2;
     private final TmfEventField fContent3;
 
-    private final TmfBaseStatisticsTree fStatsData;
+    private final TmfStatisticsTree fStatsData;
 
     // ------------------------------------------------------------------------
     // Housekeeping
@@ -100,7 +100,7 @@ public class TmfBaseColumnDataProviderTest extends TestCase {
         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);
 
index c154ecde9bbf963f1f02da79b66f6425a4a4fbcb..d0b7861ac7fc6186b7427769397bfea1d4f65c01 100755 (executable)
@@ -19,7 +19,7 @@ import org.eclipse.jface.viewers.Viewer;
 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;
@@ -91,7 +91,7 @@ public class TmfBaseColumnDataTest extends TestCase {
             }
         };
 
-        TmfBaseStatisticsTree baseData = new TmfBaseStatisticsTree();
+        TmfStatisticsTree baseData = new TmfStatisticsTree();
         fTraceName = "trace1";
         fTreeNode = new TmfStatisticsTreeNode(baseData, fTraceName);
 
index a25c70c0ca7eb11f2a6a738c3c3e974f833487ab..a65fc93024e8eb17912d1ff5b790a87c4eee6fd0 100755 (executable)
@@ -24,9 +24,8 @@ 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.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;
 
 /**
@@ -69,7 +68,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
     private final TmfEventField fContent2;
     private final TmfEventField fContent3;
 
-    private final TmfBaseStatisticsTree fStatsData;
+    private final TmfStatisticsTree fStatsData;
 
     // ------------------------------------------------------------------------
     // Housekeeping
@@ -93,7 +92,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
         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);
@@ -110,7 +109,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
      */
     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());
@@ -154,7 +153,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
      */
     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());
@@ -267,12 +266,12 @@ public class TmfBaseStatisticsDataTest extends TestCase {
      * 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);
@@ -281,7 +280,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
 
         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);
diff --git a/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeManagerTest.java b/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeManagerTest.java
new file mode 100755 (executable)
index 0000000..58225e1
--- /dev/null
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * 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));
+    }
+}
index aaeeebbde1d555dc1d1ac0a18e080e78c11eee9e..5ab6e83dc0007f0db10610a6d3bc874ce6844aad 100755 (executable)
@@ -24,9 +24,8 @@ 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.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;
 
 /**
@@ -69,7 +68,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
     private final TmfEventField fContent2;
     private final TmfEventField fContent3;
 
-    private final TmfBaseStatisticsTree fStatsData;
+    private final TmfStatisticsTree fStatsData;
 
     // ------------------------------------------------------------------------
     // Housekeeping
@@ -93,7 +92,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
         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);
@@ -115,7 +114,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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();
@@ -142,7 +141,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      */
     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());
@@ -185,7 +184,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      */
     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());
@@ -232,7 +231,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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());
@@ -251,7 +250,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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());
@@ -270,19 +269,19 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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();
@@ -310,12 +309,12 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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()));
@@ -329,12 +328,12 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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));
@@ -350,7 +349,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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());
@@ -377,7 +376,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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());
@@ -409,7 +408,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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());
@@ -443,7 +442,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
      * 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());
diff --git a/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java b/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java
deleted file mode 100755 (executable)
index fd191c0..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * 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));
-    }
-}
index 8febe76fcdb4b82e06752f1f766df648dc465b18..6296b5ff5239c86eafc9787f0b3a19ba60b0e24d 100755 (executable)
@@ -22,9 +22,8 @@ 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.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;
 
@@ -64,7 +63,7 @@ public class TmfTreeContentProviderTest extends TestCase {
     private final TmfEventField fContent1;
     private final TmfEventField fContent2;
 
-    private final TmfBaseStatisticsTree fStatsData;
+    private final TmfStatisticsTree fStatsData;
 
     private final TmfTreeContentProvider treeProvider;
 
@@ -87,7 +86,7 @@ public class TmfTreeContentProviderTest extends TestCase {
         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);
@@ -155,7 +154,7 @@ public class TmfTreeContentProviderTest extends TestCase {
         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));
     }
 
     // ------------------------------------------------------------------------
@@ -165,7 +164,7 @@ public class TmfTreeContentProviderTest extends TestCase {
      * 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));
@@ -186,7 +185,7 @@ public class TmfTreeContentProviderTest extends TestCase {
      * 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));
index a092edd4c31285f5d94dc1a5cdad9273a3b31507..031850df744d378d99787b95f360966dcb040279 100644 (file)
@@ -34,13 +34,12 @@ import org.eclipse.linuxtools.tmf.core.statistics.TmfStatistics;
 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;
@@ -92,7 +91,7 @@ public class TmfStatisticsViewer extends TmfViewer {
     /**
      * The statistics tree linked to this viewer
      */
-    protected AbsTmfStatisticsTree fStatisticsData;
+    protected TmfStatisticsTree fStatisticsData;
 
     /**
      * Update synchronization parameter (used for streaming): Update busy
@@ -225,7 +224,7 @@ public class TmfStatisticsViewer extends TmfViewer {
         }
 
         // Clean the model for this viewer
-        TmfStatisticsTreeRootFactory.removeStatTreeRoot(getTreeID());
+        TmfStatisticsTreeManager.removeStatTreeRoot(getTreeID());
     }
 
     /**
@@ -329,9 +328,9 @@ public class TmfStatisticsViewer extends TmfViewer {
      *
      * @return a TmfStatisticsData object.
      */
-    public AbsTmfStatisticsTree getStatisticData() {
+    public TmfStatisticsTree getStatisticData() {
         if (fStatisticsData == null) {
-            fStatisticsData = new TmfBaseStatisticsTree();
+            fStatisticsData = new TmfStatisticsTree();
         }
         return fStatisticsData;
     }
@@ -519,9 +518,9 @@ public class TmfStatisticsViewer extends TmfViewer {
     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();
@@ -559,7 +558,7 @@ public class TmfStatisticsViewer extends TmfViewer {
             }
         } else {
             // Creates a new tree
-            experimentTreeNode = TmfStatisticsTreeRootFactory.addStatsTreeRoot(treeID, getStatisticData());
+            experimentTreeNode = TmfStatisticsTreeManager.addStatsTreeRoot(treeID, getStatisticData());
         }
 
         // Sets the input to a clean data model
@@ -673,8 +672,8 @@ public class TmfStatisticsViewer extends TmfViewer {
      *            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;
         }
@@ -730,7 +729,7 @@ public class TmfStatisticsViewer extends TmfViewer {
      *            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();
 
@@ -779,7 +778,7 @@ public class TmfStatisticsViewer extends TmfViewer {
      * 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();
         }
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/AbsTmfStatisticsTree.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/AbsTmfStatisticsTree.java
deleted file mode 100755 (executable)
index 17ffaaa..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/*******************************************************************************
- * 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();
-        }
-    }
-}
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseStatisticsTree.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfBaseStatisticsTree.java
deleted file mode 100755 (executable)
index 8790c39..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-/*******************************************************************************
- * 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;
-    }
-}
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTree.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTree.java
new file mode 100755 (executable)
index 0000000..8153b9b
--- /dev/null
@@ -0,0 +1,396 @@
+/*******************************************************************************
+ * 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;
+    }
+}
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeManager.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeManager.java
new file mode 100755 (executable)
index 0000000..a85e600
--- /dev/null
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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();
+    }
+}
index 10616c32298a4d5c92e1e90a96bc58f64bf91c49..bbc57c52da1865ae03add9e9ec8f84a29fe19137 100755 (executable)
@@ -42,7 +42,7 @@ public class TmfStatisticsTreeNode {
     /**
      * Corresponding StatisticsData.
      */
-    protected AbsTmfStatisticsTree fNodes;
+    protected TmfStatisticsTree fNodes;
 
     /**
      * Constructor.
@@ -52,7 +52,7 @@ public class TmfStatisticsTreeNode {
      * @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();
@@ -67,7 +67,7 @@ public class TmfStatisticsTreeNode {
      *         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;
         }
 
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java
deleted file mode 100755 (executable)
index a904d1d..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*******************************************************************************
- * 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();
-    }
-}
This page took 0.050634 seconds and 5 git commands to generate.