A set of classes and interfaces for generic tree traversal and manipulation.
Trees are a very common and useful kind of data structure. Typically trees are implemented in different ways however, so it is hard to write a set of utilities applicable to every kind of tree.
Most trees are implemented in terms of an interface for their nodes, which have some kind of parent/child relationship. One notable exception is the {@link javax.swing.tree.TreeModel TreeModel} approach used by Swing. Instead of requiring a special node interface, almost anything with an underlying tree structure can be converted into something useful be implementing a TreeModel for it.
This package is based on the interface {@link de.qfs.lib.tree.TreeAdapter TreeAdapter} which is similar to TreeModel, but doesn't require the TreeModelListener support and the valueForPathChanged method, which are Swing specific. Instead it supports different kinds of trees:
The class {@link de.qfs.lib.tree.TreeUtil TreeUtil} is a collection of useful methods for tree traversal and manipulation. Trees can be traversed in two ways: {@link de.qfs.lib.tree.TreeUtil#visitTree visitTree} calls {@link de.qfs.lib.util.Visitor#visit Visitor.visit} on each node with its visitor argument while {@link de.qfs.lib.tree.TreeUtil#traverse traverse} employs the {@link de.qfs.lib.tree.Traversal Traversal} and {@link de.qfs.lib.tree.TraversalCallback TraversalCallback} interfaces to notify the callback on entry and exit to every node. If a {@link de.qfs.lib.tree.MutableTreeAdapter MutableTreeAdapter} is used, the tree can be modified during traversal.
Building trees, e.g. by parsing a file, is supported through the {@link de.qfs.lib.tree.TreeBuilder TreeBuilder} class.
Future plans include multithreading support, adapters and builders for XML DOM and SAX.