|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | 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 java.lang.String |
g_false
|
static char |
g_FileMagic
|
static int |
g_FileVersion
|
static java.lang.String |
g_true
|
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,
float data)
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 |
void |
clear()
this deletes any children of this node |
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 |
TreeNodeEnumerator |
enumerate()
This method returns an object which can iterate over all the immediate child node of this node |
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 |
float |
findChildFloatData(java.lang.String s)
returns the data of the first child with the given label as a float |
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 |
float |
floatData()
Returns this node's data as an float |
void |
floatData(float i)
sets this node's float data |
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 |
void |
intData(boolean bool)
sets this node's boolean data |
void |
intData(int i)
sets this node's integer data |
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 |
float |
nthChildFloatData(int index,
float defaultData)
this method returns the data of the nth child as a float |
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. |
static TreeNode |
read(java.io.Reader in)
This function attempts to read a TreeNode from the given reader. |
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,
boolean include_tabs)
This method writes the current node out to an output stream. |
void |
write(java.io.Writer out,
boolean include_tabs)
This method writes the current node out to a writer |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final char g_FileMagic
public static final int g_FileVersion
public static final java.lang.String g_true
public static final java.lang.String g_false
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, float 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 float floatData()
public void data(java.lang.String s)
public void intData(int i)
public void floatData(float i)
public void intData(boolean bool)
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)
public int findChildIntData(java.lang.String s)
public float findChildFloatData(java.lang.String s)
public boolean boolData()
public boolean findChildBoolData(java.lang.String s)
public 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)
def
- - the default value if the child is not foundpublic static TreeNode read(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static TreeNode read(java.io.Reader in) throws java.io.IOException
java.io.IOException
public void write(java.io.Writer out, boolean include_tabs) throws java.io.IOException
out
- - the writer to write toinclude_tabs
- - include tabs in a non-compiled output to make appearance more attractive
java.io.IOException
public void write(java.io.OutputStream out, boolean compiled, boolean include_tabs) throws java.io.IOException
out
- - the stream to write tocompiled
- - if set to false, the output is textual, otherwise it is a compressed binary formatinclude_tabs
- - include tabs in a non-compiled output to make appearance more attractive
java.io.IOException
public 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 float nthChildFloatData(int index, float 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 childpublic void clear()
public void removeChild(TreeNode node)
public TreeNodeIterator getIterator()
public java.lang.Object clone()
clone
in class java.lang.Object
public void moveItemsFrom(TreeNode node)
public void copyItems(TreeNode node)
public TreeNodeEnumerator enumerate()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |