ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.filespace
Class Tree

java.lang.Object
  extended byjavafe.filespace.Tree
Direct Known Subclasses:
HashTree, LeafTree

public abstract class Tree
extends java.lang.Object

A Tree is a n-ary tree with data at each node; the direct children of a node are unordered but distinguished via String labels on the edges to them.

All labels must be non-null.


Field Summary
 java.lang.Object data
          The data, if any, associated with this node:
private  java.lang.String label
          The label on the edge leading to us from our parent, or null if we have no parent.
private  Tree parent
          Our parent or null if we have no parent (aka, we are a root)
 
Constructor Summary
protected Tree(java.lang.Object data)
          Create a root node:
protected Tree(Tree parent, java.lang.String label, java.lang.Object data)
          Create a non-root node:
 
Method Summary
abstract  java.util.Enumeration children()
          An enumeration of this node's direct children.
 Tree getChild(java.lang.String label)
          Fetch our direct child along the edge labelled label.
 int getChildrenCount()
          Return a count of how many direct children we have:
 java.lang.String getLabel()
          Return the label on the edge to us from our parent or null if we have no parent.
 Tree getParent()
          Return our parent node or null if we have no parent
 Tree getQualifiedChild(java.lang.String name, char separator)
          Return the child with a given partially qualified name or null if no such node exists; if this node is X.Y and name is Z!
 java.lang.String getQualifiedName(java.lang.String separator)
          Return a fully qualified name for this node using a specified separator String.
 Tree getRootNode()
          Return the root node for the tree we belong to.
 java.lang.String getSimpleName()
          The same as getLabel, except that it returns "" instead of null for the top node.
 boolean isLeaf()
          Return true iff we have no direct children
 void print(java.lang.String prefix)
          Print out on System.out a human-readable representation of this tree.
 void printDetails(java.lang.String prefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

private Tree parent
Our parent or null if we have no parent (aka, we are a root)


label

private java.lang.String label
The label on the edge leading to us from our parent, or null if we have no parent.


data

public java.lang.Object data
The data, if any, associated with this node:

Constructor Detail

Tree

protected Tree(java.lang.Object data)
Create a root node:


Tree

protected Tree(Tree parent,
               java.lang.String label,
               java.lang.Object data)
Create a non-root node:

Method Detail

getParent

public final Tree getParent()
Return our parent node or null if we have no parent


getLabel

public final java.lang.String getLabel()
Return the label on the edge to us from our parent or null if we have no parent.


children

public abstract java.util.Enumeration children()
An enumeration of this node's direct children. Each child occurs exactly once in the enumeration. The order is unspecified and may differ from call to call.

Note: The Objects returned by the resulting enumeration's nextElement method are guaranteed to be of type Tree, non-null, and have non-null labels.


getChild

public Tree getChild(java.lang.String label)
Fetch our direct child along the edge labelled label. Iff there is no such child, return null.


isLeaf

public boolean isLeaf()
Return true iff we have no direct children


getChildrenCount

public int getChildrenCount()
Return a count of how many direct children we have:


getSimpleName

public final java.lang.String getSimpleName()
The same as getLabel, except that it returns "" instead of null for the top node.


getQualifiedName

public final java.lang.String getQualifiedName(java.lang.String separator)
Return a fully qualified name for this node using a specified separator String.

If the sequences of labels on the edges from the root of the tree this node belongs to til this node is X, Y, ... Z, then this routine returns the string X!Y! ... !Z, where ! is the separator. Normal usage is to use "." as the separator.

Root nodes are thus named "" and their direct children have names of the form X, where X is their label.

For the resulting name to be useful, labels should never contain the separator or be the empty string.


getRootNode

public final Tree getRootNode()
Return the root node for the tree we belong to.


getQualifiedChild

public final Tree getQualifiedChild(java.lang.String name,
                                    char separator)
Return the child with a given partially qualified name or null if no such node exists; if this node is X.Y and name is Z!W, where ! is the specified separator, then this routine attempts to find the child with fully qualified name X.Y.Z.W.

See getQualifiedName for more information on qualified names. Name must be non-null.


print

public void print(java.lang.String prefix)
Print out on System.out a human-readable representation of this tree.

Included is our fully qualified name, our data, and information about each of our children.


printDetails

public void printDetails(java.lang.String prefix)

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage