com.partnersoft.data
Class PathedTree<T>

java.lang.Object
  extended by com.partnersoft.data.PathedTree<T>
All Implemented Interfaces:
java.lang.Iterable<PathedTree<T>>

public class PathedTree<T>
extends java.lang.Object
implements java.lang.Iterable<PathedTree<T>>

A Path-based tree structure that can contain data. There is no container; nodes are trees and the head of a tree is a node without a parent.

Copyright 2009 Partner Software, Inc.

Version:
$Id$
Author:
Paul Reavis

Constructor Summary
PathedTree()
           
PathedTree(PathedTree<T> parent, java.lang.String name, T data)
           
 
Method Summary
 PathedTree<T> childNamed(java.lang.String name)
          Returns the child node with the given name.
 java.util.List<PathedTree<T>> getChildren()
          Return an immutable list of the children of this node.
 T getData()
          Returns the data associated with this node.
 java.lang.String getName()
          Returns the name of this node.
 PathedTree<T> getParent()
          Return the parent of this node, or null if this is a root node with no parent.
 Path getPath()
          Returns the path to this node from the root.
 boolean hasData()
          Returns true if this node has data.
 boolean isLeaf()
          Returns true if this node has no children.
 boolean isRoot()
          Returns true if this node has no parent.
 java.util.Iterator<PathedTree<T>> iterator()
           
 java.util.List<PathedTree<T>> listAncestors()
          Returns a freshly-created, mutable list of all ancestors of this node.
 java.util.List<PathedTree<T>> listChildren()
          Returns a freshly-created, mutable list of the children of this node.
 java.util.List<PathedTree<T>> listDescendents()
          Returns a freshly-created, mutable list of all descendents of this node.
 Naming<PathedTree<T>> nameChildren()
          Returns a freshly-created Naming of the children of this node.
 PathedTree<T> nodeFor(Path path)
          Returns the node corresponding to the given relative or absolute path.
 PathedTree<T> nodeFor(java.lang.String pathString)
          Returns the node corresponding to the given relative or absolute path string.
 PathedTree<T> removeChildNamed(java.lang.String name)
           
 void setData(T newData)
          Sets the data associated with this node.
 void setName(java.lang.String newName)
          Sets the name of this node.
 void setParent(PathedTree<T> newParent)
          Sets the parent of this node, while symmetrically setting this as a child of the parent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathedTree

public PathedTree(PathedTree<T> parent,
                  java.lang.String name,
                  T data)

PathedTree

public PathedTree()
Method Detail

getParent

public PathedTree<T> getParent()
Return the parent of this node, or null if this is a root node with no parent.

Returns:
parent node or null

setParent

public void setParent(PathedTree<T> newParent)
Sets the parent of this node, while symmetrically setting this as a child of the parent. Overwrites any other child of the same name! Also removes this node from its current parent, if any.


getChildren

public java.util.List<PathedTree<T>> getChildren()
Return an immutable list of the children of this node.

Returns:
immutable list of children

isRoot

public boolean isRoot()
Returns true if this node has no parent.


isLeaf

public boolean isLeaf()
Returns true if this node has no children.


hasData

public boolean hasData()
Returns true if this node has data.


listChildren

public java.util.List<PathedTree<T>> listChildren()
Returns a freshly-created, mutable list of the children of this node.

Returns:
mutable copy of child list

nameChildren

public Naming<PathedTree<T>> nameChildren()
Returns a freshly-created Naming of the children of this node.


listAncestors

public java.util.List<PathedTree<T>> listAncestors()
Returns a freshly-created, mutable list of all ancestors of this node. The list is in reverse order, from this node's parent first to the root last.


listDescendents

public java.util.List<PathedTree<T>> listDescendents()
Returns a freshly-created, mutable list of all descendents of this node.


getName

public java.lang.String getName()
Returns the name of this node.


setName

public void setName(java.lang.String newName)
Sets the name of this node. Note that this also changes the nodes' path, and will overwrite any other node with the same name.


getData

public T getData()
Returns the data associated with this node.


setData

public void setData(T newData)
Sets the data associated with this node.


getPath

public Path getPath()
Returns the path to this node from the root.


nodeFor

public PathedTree<T> nodeFor(Path path)
Returns the node corresponding to the given relative or absolute path.


nodeFor

public PathedTree<T> nodeFor(java.lang.String pathString)
Returns the node corresponding to the given relative or absolute path string.


childNamed

public PathedTree<T> childNamed(java.lang.String name)
Returns the child node with the given name. Does not construct a Path object.


removeChildNamed

public PathedTree<T> removeChildNamed(java.lang.String name)

iterator

public java.util.Iterator<PathedTree<T>> iterator()
Specified by:
iterator in interface java.lang.Iterable<PathedTree<T>>