tmf: Avoid HistoryTree to expose its internal HT_IO node.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / statesystem / backends / historytree / CoreNode.java
index f2e2cf0f20fff4071c99d2c88c111f0694b6e347..59f9aff29d8dd96cf2d3193324cecfd814f259e0 100644 (file)
@@ -1,13 +1,13 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
  * Copyright (c) 2010, 2011 École Polytechnique de Montréal
  * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
- * 
+ *
  * 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
- * 
+ *
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree;
@@ -16,31 +16,37 @@ import java.nio.ByteBuffer;
 
 /**
  * A Core node is a first-level node of a History Tree which is not a leaf node.
- * 
+ *
  * It extends HTNode by adding support for child nodes, and also extensions.
- * 
- * @author alexmont
- * 
+ *
+ * @author Alexandre Montplaisir
+ *
  */
 class CoreNode extends HTNode {
 
-    /* Nb. of children this node has */
+    /** Number of bytes in a int */
+    private static final int SIZE_INT = 4;
+
+    /** Number of bytes in a long */
+    private static final int SIZE_LONG = 8;
+
+    /** Nb. of children this node has */
     private int nbChildren;
 
-    /* Seq. numbers of the children nodes (size = MAX_NB_CHILDREN) */
+    /** Seq. numbers of the children nodes (size = MAX_NB_CHILDREN) */
     private int[] children;
 
-    /* Start times of each of the children (size = MAX_NB_CHILDREN) */
+    /** Start times of each of the children (size = MAX_NB_CHILDREN) */
     private long[] childStart;
 
-    /* Seq number of this node's extension. -1 if none */
+    /** Seq number of this node's extension. -1 if none */
     private int extension;
 
     /**
      * Initial constructor. Use this to initialize a new EMPTY node.
-     * 
-     * @param tree
-     *            The HistoryTree to which this node belongs
+     *
+     * @param config
+     *            Configuration of the History Tree
      * @param seqNumber
      *            The (unique) sequence number assigned to this particular node
      * @param parentSeqNumber
@@ -48,10 +54,11 @@ class CoreNode extends HTNode {
      * @param start
      *            The earliest timestamp stored in this node
      */
-    CoreNode(HistoryTree tree, int seqNumber, int parentSeqNumber,
+    CoreNode(HTConfig config, int seqNumber, int parentSeqNumber,
             long start) {
-        super(tree, seqNumber, parentSeqNumber, start);
+        super(config, seqNumber, parentSeqNumber, start);
         this.nbChildren = 0;
+        int size = config.getMaxChildren();
 
         /*
          * We instantiate the two following arrays at full size right away,
@@ -59,54 +66,54 @@ class CoreNode extends HTNode {
          * "this.nbChildren" will tell us how many relevant entries there are in
          * those tables.
          */
-        this.children = new int[ownerTree.config.maxChildren];
-        this.childStart = new long[ownerTree.config.maxChildren];
+        this.children = new int[size];
+        this.childStart = new long[size];
     }
 
     @Override
     protected void readSpecificHeader(ByteBuffer buffer) {
-        int i;
+        int size = getConfig().getMaxChildren();
 
         extension = buffer.getInt();
         nbChildren = buffer.getInt();
 
-        children = new int[ownerTree.config.maxChildren];
-        for (i = 0; i < nbChildren; i++) {
+        children = new int[size];
+        for (int i = 0; i < nbChildren; i++) {
             children[i] = buffer.getInt();
         }
-        for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+        for (int i = nbChildren; i < size; i++) {
             buffer.getInt();
         }
 
-        this.childStart = new long[ownerTree.config.maxChildren];
-        for (i = 0; i < nbChildren; i++) {
+        this.childStart = new long[size];
+        for (int i = 0; i < nbChildren; i++) {
             childStart[i] = buffer.getLong();
         }
-        for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+        for (int i = nbChildren; i < size; i++) {
             buffer.getLong();
         }
     }
 
     @Override
     protected void writeSpecificHeader(ByteBuffer buffer) {
-        int i;
+        int size = getConfig().getMaxChildren();
 
         buffer.putInt(extension);
         buffer.putInt(nbChildren);
 
         /* Write the "children's seq number" array */
-        for (i = 0; i < nbChildren; i++) {
+        for (int i = 0; i < nbChildren; i++) {
             buffer.putInt(children[i]);
         }
-        for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+        for (int i = nbChildren; i < size; i++) {
             buffer.putInt(0);
         }
 
         /* Write the "children's start times" array */
-        for (i = 0; i < nbChildren; i++) {
+        for (int i = 0; i < nbChildren; i++) {
             buffer.putLong(childStart[i]);
         }
-        for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+        for (int i = nbChildren; i < size; i++) {
             buffer.putLong(0);
         }
     }
@@ -137,12 +144,12 @@ class CoreNode extends HTNode {
 
     /**
      * Tell this node that it has a new child (Congrats!)
-     * 
+     *
      * @param childNode
      *            The SHTNode object of the new child
      */
     void linkNewChild(CoreNode childNode) {
-        assert (this.nbChildren < ownerTree.config.maxChildren);
+        assert (this.nbChildren < getConfig().getMaxChildren());
 
         this.children[nbChildren] = childNode.getSequenceNumber();
         this.childStart[nbChildren] = childNode.getNodeStart();
@@ -156,17 +163,18 @@ class CoreNode extends HTNode {
 
     @Override
     protected int getTotalHeaderSize() {
-        int specificSize;
-        specificSize = 4 /* 1x int (extension node) */
-                + 4 /* 1x int (nbChildren) */
+        int maxChildren = getConfig().getMaxChildren();
+        int specificSize =
+                  SIZE_INT /* 1x int (extension node) */
+                + SIZE_INT /* 1x int (nbChildren) */
 
                 /* MAX_NB * int ('children' table) */
-                + 4 * ownerTree.config.maxChildren
+                + SIZE_INT * maxChildren
 
                 /* MAX_NB * Timevalue ('childStart' table) */
-                + 8 * ownerTree.config.maxChildren;
+                + SIZE_LONG * maxChildren;
 
-        return getCommonHeaderSize() + specificSize;
+        return COMMON_HEADER_SIZE + specificSize;
     }
 
     @Override
This page took 0.027088 seconds and 5 git commands to generate.