ss: Replace some asserts by IllegalStateExceptions
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / internal / statesystem / core / backend / historytree / HistoryTree.java
index be301016682fb5fceb477e411d636b7067a4e900..32fbeb6e182026087b17d4a9dd2cf9802e055170 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
     // ------------------------------------------------------------------------
@@ -462,7 +474,6 @@ public class HistoryTree {
              * No, this interval starts before the startTime of this node. We
              * need to check recursively in parents if it can fit.
              */
-            assert (indexOfNode >= 1);
             tryInsertAtNode(interval, indexOfNode - 1);
             return;
         }
@@ -565,7 +576,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 +585,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);
@@ -651,7 +662,9 @@ public class HistoryTree {
          * Once we exit this loop, we should have found a children to follow. If
          * we didn't, there's a problem.
          */
-        assert (potentialNextSeqNb != currentNode.getSequenceNumber());
+        if (potentialNextSeqNb == currentNode.getSequenceNumber()) {
+            throw new IllegalStateException("No next child node found"); //$NON-NLS-1$
+        }
 
         /*
          * Since this code path is quite performance-critical, avoid iterating
This page took 0.026341 seconds and 5 git commands to generate.