ss: History trees can define their own node types
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / internal / statesystem / core / backend / historytree / HTNode.java
index 651120bb7da9e5e3506946ff63d5af08b316ff74..9cada2d4f4e989f8ea981490187fd168b34ba40e 100644 (file)
@@ -104,7 +104,10 @@ public abstract class HTNode {
      *  1 - byte (done or not)
      * </pre>
      */
-    private static final int COMMON_HEADER_SIZE = 34;
+    private static final int COMMON_HEADER_SIZE = Byte.BYTES
+            + 2 * Long.BYTES
+            + 4 * Integer.BYTES
+            + Byte.BYTES;
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -165,11 +168,13 @@ public abstract class HTNode {
      * @param fc
      *            FileChannel to the history file, ALREADY SEEKED at the start
      *            of the node.
+     * @param nodeFactory
+     *            The factory to create the nodes for this tree
      * @return The node object
      * @throws IOException
      *             If there was an error reading from the file channel
      */
-    public static final @NonNull HTNode readNode(HTConfig config, FileChannel fc)
+    public static final @NonNull HTNode readNode(HTConfig config, FileChannel fc, IHistoryTree.IHTNodeFactory nodeFactory)
             throws IOException {
         HTNode newNode = null;
         int res, i;
@@ -195,13 +200,13 @@ public abstract class HTNode {
         switch (type) {
         case CORE:
             /* Core nodes */
-            newNode = new CoreNode(config, seqNb, parentSeqNb, start);
+            newNode = nodeFactory.createCoreNode(config, seqNb, parentSeqNb, start);
             newNode.readSpecificHeader(buffer);
             break;
 
         case LEAF:
             /* Leaf nodes */
-            newNode = new LeafNode(config, seqNb, parentSeqNb, start);
+            newNode = nodeFactory.createLeafNode(config, seqNb, parentSeqNb, start);
             newNode.readSpecificHeader(buffer);
             break;
 
@@ -445,7 +450,7 @@ public abstract class HTNode {
                  * null anyway).
                  */
                 ITmfStateInterval interval = fIntervals.get(i);
-                if (interval.getStartTime() <= t &&
+                if (t >= interval.getStartTime() &&
                         interval.getAttribute() < stateInfo.size()) {
                     stateInfo.set(interval.getAttribute(), interval);
                 }
@@ -607,8 +612,8 @@ public abstract class HTNode {
         writer.println("Intervals for node #" + fSequenceNumber + ":");
 
         /* Array of children */
-        if (getNodeType() == NodeType.CORE) { /* Only Core Nodes can have children */
-            CoreNode thisNode = (CoreNode) this;
+        if (getNodeType() != NodeType.LEAF) { /* Only Core Nodes can have children */
+            ParentNode thisNode = (ParentNode) this;
             writer.print("  " + thisNode.getNbChildren() + " children");
             if (thisNode.getNbChildren() >= 1) {
                 writer.print(": [ " + thisNode.getChild(0));
This page took 0.029766 seconds and 5 git commands to generate.