dk.netarkivet.common.utils
Interface StringTree<T>

Type Parameters:
T - The leaf type
All Known Implementing Classes:
XmlTree

public interface StringTree<T>

An interface defining a structure with nodes, subnodes and leaves. This is a recursively defined datastructure, so each instance can be a tree or a leaf. Each is node is named with a String, and each leaf can contain a value of type T. Each non-leaf tree can have any number of subnodes, each identified by a String.


Method Summary
 java.util.Map<java.lang.String,StringTree<T>> getChildMap()
          Get a map of all direct subtrees, assuming that all subtrees are uniquely named.
 java.util.Map<java.lang.String,java.util.List<StringTree<T>>> getChildMultimap()
          Get a map of all direct children of this node.
 java.util.Map<java.lang.String,T> getLeafMap()
          Get a map of the names and values of all subtrees, assuming that all subtrees are leafs and are uniquely named.
 java.util.Map<java.lang.String,java.util.List<T>> getLeafMultimap()
          Get a multimap of the names and values of all direct subtrees, assuming that all subtrees are leafs.
 StringTree<T> getSubTree(java.lang.String name)
          Get the only subtree with the given name.
 java.util.List<StringTree<T>> getSubTrees(java.lang.String name)
          Get the named subtrees.
 T getValue()
          Get the value of a leaf.
 T getValue(java.lang.String name)
          Get the value of a named sub-leaf.
 boolean isLeaf()
          Returns true if this object is a leaf, and thus if getValue is legal.
 

Method Detail

isLeaf

boolean isLeaf()
Returns true if this object is a leaf, and thus if getValue is legal.

Returns:
True if the implementing object is a leaf, false otherwise.

getValue

T getValue(java.lang.String name)
Get the value of a named sub-leaf.

Parameters:
name - Name of the sub-leaf to get the value of. These are strings, and as a shorthand may specify subtrees of subtrees by separating each level with '.', i.e. getSubtrees("subtree.subsubtree").
Returns:
The value of the named leaf of this Tree, if it exists.
Throws:
IllegalState - if this StringTree does not have exactly one leaf sub-node with the given name.
ArgumentNotValid - if argument is null or empty.

getValue

T getValue()
Get the value of a leaf.

Returns:
The value of this Tree, if it is a leaf.
Throws:
IllegalState - if this StringTree is a node.

getSubTree

StringTree<T> getSubTree(java.lang.String name)
Get the only subtree with the given name.

Parameters:
name - The name of the subtree. These are strings, and as a shorthand may specify subtrees of subtrees by separating each level with '.', i.e. getSubtrees("subtree.subsubtree").
Returns:
The single subtree with the given name.
Throws:
IllegalState - if this object is a leaf or if there is not exactly one subtree with the given name.
ArgumentNotValid - if argument is null or empty.

getSubTrees

java.util.List<StringTree<T>> getSubTrees(java.lang.String name)
Get the named subtrees.

Parameters:
name - The name of the subtrees. These are strings, and as a shorthand may specify subtrees of subtrees by separating each level with '.', i.e. getSubtrees("subtree.subsubtree").
Returns:
All subtrees with the given name, or an empty list for none.
Throws:
IllegalState - if this object is a leaf.
ArgumentNotValid - if argument is null or empty.

getChildMultimap

java.util.Map<java.lang.String,java.util.List<StringTree<T>>> getChildMultimap()
Get a map of all direct children of this node.

Returns:
Map of children of this node, or an empty map for none.
Throws:
IllegalState - if this object is a leaf.

getChildMap

java.util.Map<java.lang.String,StringTree<T>> getChildMap()
Get a map of all direct subtrees, assuming that all subtrees are uniquely named.

Returns:
Map of all subtrees.
Throws:
IllegalState - if this object is a leaf or if there is more than one subtree with the same name.

getLeafMultimap

java.util.Map<java.lang.String,java.util.List<T>> getLeafMultimap()
Get a multimap of the names and values of all direct subtrees, assuming that all subtrees are leafs.

Returns:
Multimap from subtree names to values of their leaves.
Throws:
IllegalState - if this object is a leaf or if any of its children are not leaves.

getLeafMap

java.util.Map<java.lang.String,T> getLeafMap()
Get a map of the names and values of all subtrees, assuming that all subtrees are leafs and are uniquely named.

Returns:
Map from subtree names to values of their leaves.
Throws:
IllegalState - if this object is a leaf or if the subtrees are not uniquely named, or if any of its children are not leaves.