|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--simkin.TreeNode
This class encapsulates a single node in a tree
Each TreeNode consists of:
A label is a piece of text containing letters, numbers and underscores, but no whitespace.
The value can be any kind of text.
A treenode can be read and written to a text stream, and is represented as follows:
Label [textual data] { ChildLabel }
A TreeNode file contains an outermost set of braces:
{ Label [data] }
Field Summary | |
static char |
g_FileMagic
|
static int |
g_FileVersion
|
Constructor Summary | |
TreeNode()
default constructor - blank label, data and an empty list of children |
|
TreeNode(java.lang.String label)
Constructor - passing a label |
|
TreeNode(java.lang.String label,
boolean bool)
Constructor - passing a label and data, which is converted to String |
|
TreeNode(java.lang.String label,
int data)
Constructor - passing a label and data, which is converted to String |
|
TreeNode(java.lang.String label,
java.lang.String data)
Constructor - passing a label and data |
Method Summary | |
void |
addChild(TreeNode child)
Adds a node to the list of this node's children |
boolean |
boolData()
Returns this node's data as a boolean |
java.lang.Object |
clone()
this method returns a cloned version of this node - it performs a deep copy |
void |
copyItems(TreeNode node)
this function performs a deep copy from the children of another node into this one |
java.lang.String |
data()
Returns this node's data |
void |
data(java.lang.String s)
sets this node's data |
TreeNode |
findChild(java.lang.String s)
finds the first child with the given label - returns null if none found |
TreeNode |
findChild(java.lang.String label,
java.lang.String data)
finds the first child with the given label and data - returns null if none found |
boolean |
findChildBoolData(java.lang.String s)
returns the data of the first child with the given label as a boolean |
boolean |
findChildBoolData(java.lang.String label,
boolean def)
returns the data of the first child with the given label as a boolean |
java.lang.String |
findChildData(java.lang.String s)
returns the data of the first child with the given label |
java.lang.String |
findChildData(java.lang.String label,
java.lang.String def)
returns the data of the first child with the given label |
int |
findChildIntData(java.lang.String s)
returns the data of the first child with the given label as an integer |
int |
findChildIntData(java.lang.String s,
int def)
returns the data of the first child with the given label as a boolean |
java.util.Vector |
getItems()
this function returns the list of children of this node |
TreeNodeIterator |
getIterator()
This method returns an iterator that can be used to iterate over the children of this node |
int |
intData()
Returns this node's data as an integer |
java.lang.String |
label()
Returns this node's label |
void |
label(java.lang.String s)
Changes this node's label |
void |
moveItemsFrom(TreeNode node)
this function moves the children from the given node into this node |
TreeNode |
nthChild(int index)
This method returns the nth child at this node |
java.lang.String |
nthChildData(int index)
this method returns the data of the nth child |
int |
nthChildIntData(int index,
int defaultData)
this method returns the data of the nth child as an integer |
int |
numChildren()
This method returns the number of children in the list at this node |
static TreeNode |
read(java.io.InputStream in)
This function attempts to read a TreeNode from the given stream. |
void |
removeChild(TreeNode node)
This function removes the given node from the list of children |
void |
setChild(TreeNode node)
replaces the first child with a matching label with the contents of the given node. |
void |
write(java.io.OutputStream out,
boolean compiled)
This method writes the current node out to an output stream. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final char g_FileMagic
public static final int g_FileVersion
Constructor Detail |
public TreeNode()
public TreeNode(java.lang.String label, java.lang.String data)
public TreeNode(java.lang.String label, int data)
public TreeNode(java.lang.String label, boolean bool)
public TreeNode(java.lang.String label)
Method Detail |
public void addChild(TreeNode child)
public void label(java.lang.String s)
public java.lang.String label()
public java.lang.String data()
public int intData()
public void data(java.lang.String s)
public TreeNode findChild(java.lang.String s)
public TreeNode findChild(java.lang.String label, java.lang.String data)
public java.lang.String findChildData(java.lang.String label, java.lang.String def)
label
- - the label to search fordef
- - a value to return if no child is foundpublic java.lang.String findChildData(java.lang.String s)
label
- - the label to search forpublic int findChildIntData(java.lang.String s)
label
- - the label to search forpublic boolean boolData()
public boolean findChildBoolData(java.lang.String s)
label
- - the label to search forpublic void setChild(TreeNode node)
public boolean findChildBoolData(java.lang.String label, boolean def)
label
- - the label to search fordef
- - the default value if the child is not foundpublic int findChildIntData(java.lang.String s, int def)
label
- - the label to search fordef
- - the default value if the child is not foundpublic static TreeNode read(java.io.InputStream in) throws java.io.IOException
public void write(java.io.OutputStream out, boolean compiled) throws java.io.IOException
out
- - the stream to write tocompiled
- - if set to false, the output is textual, otherwise it is a compressed binary formatpublic java.util.Vector getItems()
public int numChildren()
public TreeNode nthChild(int index)
public int nthChildIntData(int index, int defaultData)
index
- - the index of the childdefaultData
- - the value to return if there are no childrenpublic java.lang.String nthChildData(int index)
index
- - the index of the childdefaultData
- - the value to return if there are no childrenpublic void removeChild(TreeNode node)
public TreeNodeIterator getIterator()
public java.lang.Object clone()
public void moveItemsFrom(TreeNode node)
public void copyItems(TreeNode node)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |