Coverage Report - org.crosswire.jsword.book.sword.TreeNode
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeNode
0%
0/37
0%
0/6
1.059
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2005 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.book.sword;
 21  
 
 22  
 import java.io.Serializable;
 23  
 
 24  
 /**
 25  
  * A node that knows where the data is in the real file and where it is in
 26  
  * relationship to other nodes.
 27  
  * 
 28  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 29  
  * @author DM Smith
 30  
  */
 31  0
 class TreeNode implements Cloneable, Serializable {
 32  
     /**
 33  
      * TreeNode default ctor.
 34  
      */
 35  
     TreeNode() {
 36  0
         this(-1);
 37  0
     }
 38  
 
 39  
     /**
 40  
      * Setup with the positions of data in the file
 41  
      * 
 42  
      * @param theOffset
 43  
      */
 44  0
     TreeNode(int theOffset) {
 45  0
         offset = theOffset;
 46  0
         name = "";
 47  0
         parent = -1;
 48  0
         nextSibling = -1;
 49  0
         firstChild = -1;
 50  0
         userData = new byte[0];
 51  0
     }
 52  
 
 53  
     /**
 54  
      * @return the offset
 55  
      */
 56  
     public int getOffset() {
 57  0
         return offset;
 58  
     }
 59  
 
 60  
     /**
 61  
      * @param newOffset
 62  
      *            the offset to set
 63  
      */
 64  
     public void setOffset(int newOffset) {
 65  0
         offset = newOffset;
 66  0
     }
 67  
 
 68  
     /**
 69  
      * @return the name
 70  
      */
 71  
     public String getName() {
 72  0
         return name;
 73  
     }
 74  
 
 75  
     /**
 76  
      * @param newName
 77  
      *            the name to set
 78  
      */
 79  
     public void setName(String newName) {
 80  0
         name = newName;
 81  0
     }
 82  
 
 83  
     /**
 84  
      * @return the userData
 85  
      */
 86  
     public byte[] getUserData() {
 87  0
         return userData.clone();
 88  
     }
 89  
 
 90  
     /**
 91  
      * @param theUserData
 92  
      *            the userData to set
 93  
      */
 94  
     public void setUserData(byte[] theUserData) {
 95  0
         userData = theUserData.clone();
 96  0
     }
 97  
 
 98  
     /**
 99  
      * @return the firstChild
 100  
      */
 101  
     public int getFirstChild() {
 102  0
         return firstChild;
 103  
     }
 104  
 
 105  
     /**
 106  
      * @return whether there are children
 107  
      */
 108  
     public boolean hasChildren() {
 109  0
         return firstChild != -1;
 110  
     }
 111  
 
 112  
     /**
 113  
      * @param firstChild
 114  
      *            the firstChild to set
 115  
      */
 116  
     public void setFirstChild(int firstChild) {
 117  0
         this.firstChild = firstChild;
 118  0
     }
 119  
 
 120  
     /**
 121  
      * @return the nextSibling
 122  
      */
 123  
     public int getNextSibling() {
 124  0
         return nextSibling;
 125  
     }
 126  
 
 127  
     /**
 128  
      * @return if there are more siblings
 129  
      */
 130  
     public boolean hasNextSibling() {
 131  0
         return nextSibling != -1;
 132  
     }
 133  
 
 134  
     /**
 135  
      * @param nextSibling
 136  
      *            the nextSibling to set
 137  
      */
 138  
     public void setNextSibling(int nextSibling) {
 139  0
         this.nextSibling = nextSibling;
 140  0
     }
 141  
 
 142  
     /**
 143  
      * @return the parent
 144  
      */
 145  
     public int getParent() {
 146  0
         return parent;
 147  
     }
 148  
 
 149  
     /**
 150  
      * @param parent
 151  
      *            the parent to set
 152  
      */
 153  
     public void setParent(int parent) {
 154  0
         this.parent = parent;
 155  0
     }
 156  
 
 157  
     @Override
 158  
     public TreeNode clone() {
 159  0
         TreeNode clone = null;
 160  
         try {
 161  0
             clone = (TreeNode) super.clone();
 162  0
         } catch (CloneNotSupportedException e) {
 163  0
             assert false : e;
 164  0
         }
 165  0
         return clone;
 166  
     }
 167  
 
 168  
     /**
 169  
      * The offset of this TreeNode in the offset.
 170  
      */
 171  
     private int offset;
 172  
 
 173  
     /**
 174  
      * The name of this TreeNode. Note, this is not the path. To get the path,
 175  
      * one needs to traverse to the parent to construct the path.
 176  
      */
 177  
     private String name;
 178  
 
 179  
     /**
 180  
      * Optional, extra data associated with this TreeNode. For example, this is
 181  
      * used to store offset and length for a raw genbook.
 182  
      */
 183  
     private byte[] userData;
 184  
 
 185  
     /**
 186  
      * The offset of the parent record in the offset. Root nodes are indicated
 187  
      * with a value of -1. That is, this TreeNode does not have a parent.
 188  
      */
 189  
     private int parent;
 190  
 
 191  
     /**
 192  
      * The offset of the next sibling record in the offset. Final siblings are
 193  
      * indicated with a value of -1. That is, this TreeNode does not have a next
 194  
      * sibling.
 195  
      */
 196  
     private int nextSibling;
 197  
 
 198  
     /**
 199  
      * The offset of the first child record in the offset. Leaf nodes are
 200  
      * indicated with a value of -1. That is, this TreeNode does not have any
 201  
      * children.
 202  
      */
 203  
     private int firstChild;
 204  
 
 205  
     /**
 206  
      * Serialization ID
 207  
      */
 208  
     private static final long serialVersionUID = -2472601787934480762L;
 209  
 
 210  
 }