Class XmlTree<T>

  • Type Parameters:
    T - The type of XmlTree
    All Implemented Interfaces:
    StringTree<T>

    public class XmlTree<T>
    extends Object
    implements StringTree<T>
    A class that implements the StringTree interface by backing it with XML. The name of each XML node corresponds to the identifier of a node in the tree.
    • Method Detail

      • getStringTree

        public static StringTree<String> getStringTree​(org.dom4j.Node n)
        Returns a StringTree<String> view of the given XML node.
        Parameters:
        n - A part of an XML document structure
        Returns:
        A StringTree<String> backed by the given XML part.
        Throws:
        ArgumentNotValid - on null argument.
      • isLeaf

        public boolean isLeaf()
        Returns true if this object is a leaf, and thus if getValue is legal.
        Specified by:
        isLeaf in interface StringTree<T>
        Returns:
        True if the implementing object is a leaf, false otherwise.
      • getValue

        public T getValue​(String name)
        Get the value of a named sub-leaf.
        Specified by:
        getValue in interface StringTree<T>
        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

        public T getValue()
        Get the value of a leaf.
        Specified by:
        getValue in interface StringTree<T>
        Returns:
        The value of this Tree, if it is a leaf.
        Throws:
        IllegalState - if this Tree is a node.
      • getSubTree

        public StringTree<T> getSubTree​(String name)
        Get the only subtree with the given name.
        Specified by:
        getSubTree in interface StringTree<T>
        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 there is not exactly one subtree with the given name.
        ArgumentNotValid - if argument is null or empty.
      • getSubTrees

        public List<StringTree<T>> getSubTrees​(String name)
        Get the named subtrees.
        Specified by:
        getSubTrees in interface StringTree<T>
        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.
      • getChildMap

        public Map<String,​StringTree<T>> getChildMap()
        Get a map of all direct subtrees, assuming that all subtrees are uniquely named.
        Specified by:
        getChildMap in interface StringTree<T>
        Returns:
        Map of all subtrees.
        Throws:
        IllegalState - if this object is a leaf, or if the subtrees are not uniquely named.
      • getLeafMultimap

        public Map<String,​List<T>> getLeafMultimap()
        Get a multimap of the names and values of all subtrees, assuming that all subtrees are leafs.
        Specified by:
        getLeafMultimap in interface StringTree<T>
        Returns:
        Multimap from subtree names to values of their leaves.
        Throws:
        ArgumentNotValid - if this object is not a node, or if any of its children are not leaves.
      • getLeafMap

        public Map<String,​T> getLeafMap()
        Get a map of the names and values of all subtrees, assuming that all subtrees are leafs and are uniquely named.
        Specified by:
        getLeafMap in interface StringTree<T>
        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.