Class NodeTree


  • public final class NodeTree
    extends Object
    An immutable tree structure for determining node data.

    Any changes will create new copies of the necessary tree objects.

    Keys are case-insensitive.

    Segments of nodes are split by the '.' character

    Since:
    2.0.0
    • Method Detail

      • of

        public static NodeTree of​(Map<String,​Integer> values)
        Create a new node tree with the given values, and a default value of UNDEFINED.
        Parameters:
        values - The values to set
        Returns:
        The new node tree
        Since:
        2.0.0
      • of

        public static NodeTree of​(Map<String,​Integer> values,
                                  int defaultValue)
        Create a new node tree with the given values, and the specified root fallback value.
        Parameters:
        values - The values to be contained in this node tree
        defaultValue - The fallback value for any completely undefined nodes
        Returns:
        The newly created node tree
        Since:
        2.0.0
      • get

        public int get​(String node)
        Returns the value assigned to a specific node, or the nearest parent value in the tree if the node itself is undefined.
        Parameters:
        node - The path to get the node value at
        Returns:
        The int value for the given node
        Since:
        2.0.0
      • anyInPrefixMatching

        public boolean anyInPrefixMatching​(String prefix,
                                           IntPredicate test)
        Return whether the node prefix or any of its children match the predicate test.
        Parameters:
        prefix - the prefix to test
        test - the test function
        Returns:
        if any values return true
      • asMap

        public Map<String,​IntegerasMap()
        Convert this node tree into a map of the defined nodes in this tree.
        Returns:
        An immutable map representation of the nodes defined in this tree
        Since:
        2.0.0
      • withValue

        public NodeTree withValue​(String node,
                                  int value)
        Return a new NodeTree instance with a single changed value.
        Parameters:
        node - The node path to change the value of
        value - The value to change, or UNDEFINED to remove
        Returns:
        The new, modified node tree
        Since:
        2.0.0
      • withAll

        public NodeTree withAll​(Map<String,​Integer> values)
        Return a modified new node tree with the specified values set.
        Parameters:
        values - The values to set
        Returns:
        The new node tree
        Since:
        2.0.0