ss: Fix a bug where depth of history tree increases at each new node
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / internal / statesystem / core / backend / historytree / HistoryTree.java
index be301016682fb5fceb477e411d636b7067a4e900..ebf47650658821efb14e865b0db9354b36721db3 100644 (file)
@@ -30,6 +30,8 @@ import org.eclipse.tracecompass.internal.statesystem.core.Activator;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Meta-container for the History Tree. This structure contains all the
  * high-level data relevant to the tree.
@@ -335,6 +337,16 @@ public class HistoryTree {
         return fLatestBranch.get(0);
     }
 
+    /**
+     * Return the latest branch of the tree. That branch is immutable. Used for
+     * unit testing and debugging.
+     *
+     * @return The immutable latest branch
+     */
+    protected List<HTNode> getLatestBranch() {
+        return ImmutableList.copyOf(fLatestBranch);
+    }
+
     // ------------------------------------------------------------------------
     // HT_IO interface
     // ------------------------------------------------------------------------
@@ -565,7 +577,7 @@ public class HistoryTree {
         fLatestBranch.add(newRootNode);
 
         // Create new coreNode
-        for (int i = 1; i < depth + 1; i++) {
+        for (int i = 1; i < depth; i++) {
             CoreNode prevNode = (CoreNode) fLatestBranch.get(i - 1);
             CoreNode newNode = initNewCoreNode(prevNode.getParentSequenceNumber(),
                     splitTime + 1);
@@ -574,7 +586,7 @@ public class HistoryTree {
         }
 
         // Create the new leafNode
-        CoreNode prevNode = (CoreNode) fLatestBranch.get(depth);
+        CoreNode prevNode = (CoreNode) fLatestBranch.get(depth - 1);
         LeafNode newNode = initNewLeafNode(prevNode.getParentSequenceNumber(), splitTime + 1);
         prevNode.linkNewChild(newNode);
         fLatestBranch.add(newNode);
This page took 0.026694 seconds and 5 git commands to generate.