Class MapNode

java.lang.Object
uk.blankaspect.common.basictree.AbstractNode
uk.blankaspect.common.basictree.MapNode
All Implemented Interfaces:
Cloneable, ITreeNode<AbstractNode>

public class MapNode extends AbstractNode
This class implements a node that contains a collection of key–value pairs whose keys are strings and whose values are nodes. In the documentation of this class, key–value pair is sometimes abbreviated to KV pair or just pair.

A map node preserves the order of the key–value pairs that are added to it; that is, an iterator over the collection of KV pairs will traverse the pairs in the order in which their keys were added to the map node. (The same is true of iterators over the collections of keys (getKeys()) or values (getChildren()).) If a KV pair is added to a map node that already contains a KV pair with the key of the new pair, the value of the new pair will replace the old value without affecting the order of the KV pairs.

A map node may be created with an initial collection of key–value pairs, and KV pairs may be added to a map node after its creation, but KV pairs cannot be removed from a map node.

Some methods add a value to a map node with a key that is generated by a function that returns a string for a given map node. The default key generator returns the concatenation of a prefix and the decimal string representation of an index that is incremented for each key. The index applies to all map nodes; a separate auto-incrementing index for each of several map nodes can be implemented with the MapNode.AutoIndexMap class. The addStringAuto(String) method may be used to add comments ('junk' string nodes) to a map node.

The default string representation of a map node begins with a '{' (U+007B) and ends with a '}' (U+007D). The key of a KV pair is escaped and enclosed in quotation marks in the same way as the value of a string node. The key and value of a KV pair are separated with a ':' (U+003A). Adjacent KV pairs are separated with a ',' (U+002C).

  • Field Details

    • START_CHAR

      public static final char START_CHAR
      The character that denotes the start of the string representation of a map node.
      See Also:
    • END_CHAR

      public static final char END_CHAR
      The character that denotes the end of the string representation of a map node.
      See Also:
    • KEY_VALUE_SEPARATOR_CHAR

      public static final char KEY_VALUE_SEPARATOR_CHAR
      The character that separates the key and value of a KV pair in the string representation of a map node.
      See Also:
    • PAIR_SEPARATOR_CHAR

      public static final char PAIR_SEPARATOR_CHAR
      The character that separates adjacent KV pairs in the string representation of a map node.
      See Also:
    • DEFAULT_GENERATED_KEY_PREFIX

      public static final String DEFAULT_GENERATED_KEY_PREFIX
      The prefix of a key that is generated by the default key-generator function.
      See Also:
    • TYPE

      public static final NodeType TYPE
      The type of a map node.
  • Constructor Details

    • MapNode

      public MapNode()
      Creates a new instance of a map node that has no parent and initially contains no key–value pairs.
    • MapNode

      public MapNode(AbstractNode parent)
      Creates a new instance of a map node that has the specified parent and initially contains no key–value pairs.
      Parameters:
      parent - the parent of the map node.
    • MapNode

      public MapNode(MapNode.Pair... pairs)
      Creates a new instance of a map node that has no parent and initially contains the specified key–value pairs.
      Parameters:
      pairs - the initial key–value pairs of the map node.
    • MapNode

      public MapNode(Iterable<? extends MapNode.Pair> pairs)
      Creates a new instance of a map node that has no parent and initially contains the specified key–value pairs.
      Parameters:
      pairs - the initial key–value pairs of the map node.
    • MapNode

      public MapNode(Map<String,AbstractNode> pairs)
      Creates a new instance of a map node that has no parent and initially contains the specified key–value pairs.
      Parameters:
      pairs - the initial key–value pairs of the map node.
    • MapNode

      public MapNode(AbstractNode parent, MapNode.Pair... pairs)
      Creates a new instance of a map node that has the specified parent and initially contains the specified key–value pairs.
      Parameters:
      parent - the parent of the map node.
      pairs - the initial key–value pairs of the map node.
    • MapNode

      public MapNode(AbstractNode parent, Iterable<? extends MapNode.Pair> pairs)
      Creates a new instance of a map node that has the specified parent and initially contains the specified key–value pairs.
      Parameters:
      parent - the parent of the map node.
      pairs - the initial key–value pairs of the map node.
    • MapNode

      public MapNode(AbstractNode parent, Map<String,AbstractNode> pairs)
      Creates a new instance of a map node that has the specified parent and initially contains the specified key–value pairs.
      Parameters:
      parent - the parent of the map node.
      pairs - the initial key–value pairs of the map node.
  • Method Details

    • setKeyGenerator

      public static void setKeyGenerator(Function<MapNode,String> generator)
      Sets the function that generates a key for a given map node to the specified value. If the specified function is null, the default key generator will be set. The default function returns the concatenation of a prefix and the decimal string representation of an auto-incrementing index.
      Parameters:
      generator - the function that generates a key for a given map node, or null to set the default key generator.
    • setGeneratedKeyPrefix

      public static void setGeneratedKeyPrefix(String prefix)
      Sets the prefix of the keys that are generated by the default key-generator function to the specified value.
      Parameters:
      prefix - the prefix of the keys that are generated by the default key-generator function.
    • resetGeneratedKeyIndex

      public static void resetGeneratedKeyIndex()
      Resets the index that is used by the default key-generator function.
    • pair

      public static MapNode.Pair pair(String key, boolean value)
      Creates a Boolean node for the specified value, creates a key–value pair whose key is the specified key and whose value is the Boolean node, and returns the KV pair.
      Parameters:
      key - the key of the key–value pair.
      value - the value of the Boolean node.
      Returns:
      a key–value pair whose key is key and whose value is a new Boolean node whose value is value.
    • pair

      public static MapNode.Pair pair(String key, int value)
      Creates an 'int' node for the specified value, creates a key–value pair whose key is the specified key and whose value is the 'int' node, and returns the KV pair.
      Parameters:
      key - the key of the key–value pair.
      value - the value of the 'int' node.
      Returns:
      a key–value pair whose key is key and whose value is a new 'int' node whose value is value.
    • pair

      public static MapNode.Pair pair(String key, long value)
      Creates a 'long' node for the specified value, creates a key–value pair whose key is the specified key and whose value is the 'long' node, and returns the KV pair.
      Parameters:
      key - the key of the key–value pair.
      value - the value of the 'long' node.
      Returns:
      a key–value pair whose key is key and whose value is a new 'long' node whose value is value.
    • pair

      public static MapNode.Pair pair(String key, double value)
      Creates a 'double' node for the specified value, creates a key–value pair whose key is the specified key and whose value is the 'double' node, and returns the KV pair.
      Parameters:
      key - the key of the key–value pair.
      value - the value of the 'double' node.
      Returns:
      a key–value pair whose key is key and whose value is a new 'double' node whose value is value.
    • pair

      public static MapNode.Pair pair(String key, String value)
      Creates a string node for the specified value, creates a key–value pair whose key is the specified key and whose value is the string node, and returns the KV pair.
      Parameters:
      key - the key of the key–value pair.
      value - the value of the string node.
      Returns:
      a key–value pair whose key is key and whose value is a new string node whose value is value.
    • getType

      public NodeType getType()
      Description copied from class: AbstractNode
      Returns the type of this node.
      Specified by:
      getType in class AbstractNode
      Returns:
      TYPE.
    • isContainer

      public boolean isContainer()
      Returns true if this node can contain other nodes. For a map node, this method always returns true.
      Specified by:
      isContainer in class AbstractNode
      Returns:
      true.
    • getChildren

      public List<AbstractNode> getChildren()
      Returns a list of the values of the key–value pairs of this map node. The list may be modified without affecting this map node, but modifying the elements of the list (for example, changing the parent of a node) will affect this map node.
      Specified by:
      getChildren in interface ITreeNode<AbstractNode>
      Overrides:
      getChildren in class AbstractNode
      Returns:
      a list of the values of the key–value pairs of this map node.
      See Also:
    • equals

      public boolean equals(Object obj)
      Returns true if the specified object is an instance of MapNode and this map node contains the same number of key–value pairs as the other map node and for each KV pair in this map node, kv1, there is a KV pair in the other map node, kv2, for which the keys of kv1 and kv2 are equal and the values of kv1 and kv2 are equal.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object with which this map node will be compared.
      Returns:
      true if obj is an instance of MapNode and this map node contains the same number of key–value pairs as the other map node and for each KV pair in this map node, kv1, there is a KV pair in the other map node, kv2, for which the keys of kv1 and kv2 are equal and the values of kv1 and kv2 are equal; false otherwise.
    • hashCode

      public int hashCode()
      Returns the hash code of this map node, which is the hash code of its key–value pairs.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this map node.
    • clone

      public MapNode clone()
      Creates and returns a deep copy of this map node that has no parent.
      Overrides:
      clone in class AbstractNode
      Returns:
      a deep copy of this map node that has no parent.
    • toString

      public String toString()
      Returns a string representation of this map node.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this map node.
    • isEmpty

      public boolean isEmpty()
      Returns true if this map node contains no key–value pairs.
      Returns:
      true if this map node contains no key–value pairs; false otherwise.
    • getNumPairs

      public int getNumPairs()
      Returns the number of key–value pairs that this map node contains.
      Returns:
      the number of key–value pairs that this map node contains.
    • hasKey

      public boolean hasKey(String key)
      Returns true if this map node contains a key–value pair with the specified key.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key; false otherwise.
    • hasNull

      public boolean hasNull(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a null node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a null node; false otherwise.
    • hasBoolean

      public boolean hasBoolean(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a Boolean node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a Boolean node; false otherwise.
    • hasInt

      public boolean hasInt(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is an 'int' node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is an 'int' node; false otherwise.
    • hasLong

      public boolean hasLong(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a 'long' node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a 'long' node; false otherwise.
    • hasIntOrLong

      public boolean hasIntOrLong(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is either an 'int' node or a 'long' node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is either an 'int' node or a 'long' node; false otherwise.
    • hasDouble

      public boolean hasDouble(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a 'double' node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a 'double' node; false otherwise.
    • hasString

      public boolean hasString(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a string node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a string node; false otherwise.
    • hasList

      public boolean hasList(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a list node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a list node; false otherwise.
    • hasMap

      public boolean hasMap(String key)
      Returns true if this map node contains a key–value pair whose key is the specified key and whose value is a map node.
      Parameters:
      key - the key of the key–value pair of interest.
      Returns:
      true if this map node contains a key–value pair whose key is key and whose value is a map node; false otherwise.
    • get

      public AbstractNode get(String key)
      Returns the value of the key–value pair of this map node with the specified key.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the value of the key–value pair of this map node whose key is key, or null if this map node does not contain a KV pair with such a key.
    • getNullNode

      public NullNode getNullNode(String key)
      Returns the null node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the null node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of NullNode.
    • getBooleanNode

      public BooleanNode getBooleanNode(String key)
      Returns the Boolean node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the Boolean node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of BooleanNode.
    • getBoolean

      public boolean getBoolean(String key)
      Returns the underlying value of the Boolean node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      Returns:
      the underlying value of the Boolean node that is associated with key in this map node.
      Throws:
      NullPointerException - if this map node does not contain a KV pair with the specified key.
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of BooleanNode.
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Returns the underlying value of the Boolean node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not a Boolean node, the specified default value is returned instead.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not a Boolean node.
      Returns:
      the underlying value of the Boolean node that is associated with key in this map node, or defaultValue if there is no such node.
    • getIntNode

      public IntNode getIntNode(String key)
      Returns the 'int' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the 'int' node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of IntNode.
    • getInt

      public int getInt(String key)
      Returns the underlying value of the 'int' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      Returns:
      the underlying value of the 'int' node that is associated with key in this map node.
      Throws:
      NullPointerException - if this map node does not contain a KV pair with the specified key.
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of IntNode.
    • getInt

      public int getInt(String key, int defaultValue)
      Returns the underlying value of the 'int' node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not an 'int' node, the specified default value is returned instead.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not an 'int' node.
      Returns:
      the underlying value of the 'int' node that is associated with key in this map node, or defaultValue if there is no such node.
    • getLongNode

      public LongNode getLongNode(String key)
      Returns the 'long' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the 'long' node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of LongNode.
    • getLong

      public long getLong(String key)
      Returns the underlying value of the 'long' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      Returns:
      the underlying value of the 'long' node that is associated with key in this map node.
      Throws:
      NullPointerException - if this map node does not contain a KV pair with the specified key.
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of LongNode.
    • getLong

      public long getLong(String key, long defaultValue)
      Returns the underlying value of the 'long' node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not a 'long' node, the specified default value is returned instead.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not a 'long' node.
      Returns:
      the underlying value of the 'long' node that is associated with key in this map node, or defaultValue if there is no such node.
    • getIntOrLong

      public long getIntOrLong(String key)
      Returns the underlying value of the 'int' node or 'long' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      Returns:
      the underlying value of the 'int' node or 'long' node that is associated with key in this map node.
      Throws:
      NullPointerException - if this map node does not contain a KV pair with the specified key.
      NodeTypeException - if this map node contains a KV pair with the specified key and its value is neither an instance of IntNode nor an instance of LongNode.
    • getIntOrLong

      public long getIntOrLong(String key, long defaultValue)
      Returns the underlying value of the 'int' node or 'long' node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is neither an 'int' node nor a 'long' node, the specified default value is returned instead.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is neither an 'int' node nor a 'long' node.
      Returns:
      the underlying value of the 'int' node or 'long' node that is associated with key in this map node, or defaultValue if there is no such node.
    • getDoubleNode

      public DoubleNode getDoubleNode(String key)
      Returns the 'double' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the 'double' node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of DoubleNode.
    • getDouble

      public double getDouble(String key)
      Returns the underlying value of the 'double' node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      Returns:
      the underlying value of the 'double' node that is associated with key in this map node.
      Throws:
      NullPointerException - if this map node does not contain a KV pair with the specified key.
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of DoubleNode.
    • getDouble

      public double getDouble(String key, double defaultValue)
      Returns the underlying value of the 'double' node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not a 'double' node, the specified default value is returned instead.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not a 'double' node.
      Returns:
      the underlying value of the 'double' node that is associated with key in this map node, or defaultValue if there is no such node.
    • getStringNode

      public StringNode getStringNode(String key)
      Returns the string node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the string node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of StringNode.
    • getString

      public String getString(String key)
      Returns the underlying value of the string node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      Returns:
      the underlying value of the string node that is associated with key in this map node.
      Throws:
      NullPointerException - if this map node does not contain a KV pair with the specified key.
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of StringNode.
    • getString

      public String getString(String key, String defaultValue)
      Returns the underlying value of the string node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not a string node, the specified default value is returned instead.
      Parameters:
      key - the key of the key–value pair whose underlying value is required.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not a string node.
      Returns:
      the underlying value of the string node that is associated with key in this map node, or defaultValue if there is no such node.
    • getListNode

      public ListNode getListNode(String key)
      Returns the list node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the list node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of ListNode.
    • getMapNode

      public MapNode getMapNode(String key)
      Returns the map node that is associated with the specified key in this map node.
      Parameters:
      key - the key of the key–value pair whose value is required.
      Returns:
      the map node that is associated with key in this map node, or null if this map node does not contain a KV pair with such a key.
      Throws:
      ClassCastException - if this map node contains a KV pair with the specified key and its value is not an instance of MapNode.
    • getEnumValue

      public <E extends Enum<E>> E getEnumValue(Class<E> cls, String key, E defaultValue)
      Returns the constant of the specified enumeration type whose name matches the underlying value of the string node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not a string node, or if the value of the string node does not match the name of any of the enumeration constants, the specified default value is returned instead.
      Type Parameters:
      E - the enumeration type.
      Parameters:
      cls - the class of the enumeration type.
      key - the key of the key–value pair whose underlying value is required to match the name of an enumeration constant of cls.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not a string node or the value of the string node does not match the name of any of the enumeration constants.
      Returns:
      the enumeration constant of cls whose name matches the the underlying value of the string node that is associated with key in this map node, or defaultValue if there is no such node or there is no matching enumeration constant.
    • getEnumValue

      public <E extends Enum<E>> E getEnumValue(Class<E> cls, String key, Function<E,String> converter, E defaultValue)
      Returns the constant of the specified enumeration type that, after the specified converter has been applied to it, matches the underlying value of the string node that is associated with the specified key in this map node. If this map node does not contain a key–value pair with such a key, or if the associated value is not a string node, or if the value of the string node does not match any of the converted enumeration constants, the specified default value is returned instead.
      Type Parameters:
      E - the enumeration type.
      Parameters:
      cls - the class of the enumeration type.
      key - the key of the key–value pair whose underlying value is required to match an enumeration constant of cls after converter has been applied to it.
      converter - the function that converts the enumeration constants of cls to strings.
      defaultValue - the value that will be returned if this map node does not contain a key–value pair whose key is key or the value of the pair is not a string node or the value of the string node does not match any of the converted enumeration constants.
      Returns:
      the enumeration constant of cls that, after converter has been applied to it, matches the the underlying value of the string node that is associated with key in this map node, or defaultValue if there is no such node or there is no matching enumeration constant.
    • getKeys

      public List<String> getKeys()
      Returns a list of the keys of the key–value pairs of this map node. The keys are in the order in which their associated KV pairs were added to this map node. The list is independent of this map node, so it may be modified without affecting this node.
      Returns:
      a list of the keys of the key–value pairs of this map node.
      See Also:
    • getPairs

      public Map<String,AbstractNode> getPairs()
      Returns an unmodifiable map of the key–value pairs of this map node. Iterating over the entries of the map will traverse the KV pairs in the order in which they were added to this map node. Although the returned map cannot be modified, the values of its KV pairs can be modified, and doing so (for example, changing the parent of a node) will affect this map node.
      Returns:
      an unmodifiable map of the key–value pairs of this map node.
      See Also:
    • getPairIterator

      public Iterator<Map.Entry<String,AbstractNode>> getPairIterator()
      Returns an iterator over the key–value pairs of this map node.
      Returns:
      an iterator over the key–value pairs of this map node.
    • getPairList

      public List<MapNode.Pair> getPairList()
      Returns a list of the key–value pairs of this map node. Iterating over the list will traverse the KV pairs in the order in which they were added to this map node. Modifying the value of a KV pair (for example, changing the parent of a node) will affect this map node.
      Returns:
      a list of the key–value pairs of this map node.
      See Also:
    • clear

      public void clear()
      Removes all the key–value pairs of this map node.
    • setPairs

      public void setPairs(Map<String,AbstractNode> pairs)
      Sets the key–value pairs of this map node to the specified pairs of keys and values.
      Parameters:
      pairs - the pairs of keys and values to which the key–value pairs of this map node will be set.
    • add

      public void add(MapNode.Pair pair)
      Adds the specified key–value pair to this map node. If this map node already contains a KV pair with the key of the new pair, the new pair will replace the existing pair without affecting the order of the pairs; otherwise, the specified pair will be added to the end of the collection of pairs.
      Parameters:
      pair - the key–value pair that will be added to this map node.
      Throws:
      IllegalArgumentException - if pair is null.
    • add

      public void add(String key, AbstractNode value)
      Adds a key–value pair with the specified key and value to this map node. If this map node already contains a KV pair with the specified key, the specified value will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key of the key–value pair.
      value - the value of the key–value pair.
      Throws:
      IllegalArgumentException - if value is null.
    • addAuto

      public void addAuto(AbstractNode value)
      Adds to this map node a key–value pair with the specified value and a key that is generated by the key-generator function. If this map node already contains a KV pair with the generated key, the specified value will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      value - the value of the key–value pair.
    • addPairs

      public void addPairs(MapNode.Pair... pairs)
      Adds the specified key–value pairs to the key–value pairs of this map node. If this map node already contains a KV pair with the key of one of the new pairs, the value of the new pair will replace the value of the existing pair without affecting the order of the pairs; otherwise, the new KV pair will be added to the end of the collection of pairs. The KV pairs are added in the order in which they are traversed by their iterator.
      Parameters:
      pairs - the key–value pairs that will be added to the key–value pairs of this map node.
    • addPairs

      public void addPairs(Iterable<? extends MapNode.Pair> pairs)
      Adds the specified key–value pairs to the key–value pairs of this map node. If this map node already contains a KV pair with the key of one of the new pairs, the value of the new pair will replace the value of the existing pair without affecting the order of the pairs; otherwise, the new KV pair will be added to the end of the collection of pairs. The KV pairs are added in the order in which they are traversed by their iterator.
      Parameters:
      pairs - the key–value pairs that will be added to the key–value pairs of this map node.
    • addPairs

      public void addPairs(Map<String,AbstractNode> pairs)
      Adds the specified pairs of keys and values to the key–value pairs of this map node. If this map node already contains a KV pair with the key of one of the new pairs, the value of the new pair will replace the value of the existing pair without affecting the order of the pairs; otherwise, the new KV pair will be added to the end of the collection of pairs. The KV pairs are added in the order in which they are traversed by the iterator over the entries of the input map.
      Parameters:
      pairs - the pairs of keys and values that will be added to the key–value pairs of this map node.
    • addNull

      public NullNode addNull(String key)
      Creates a new instance of a null node, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new null node will be associated.
      Returns:
      the null node that was created and added to this map node as a key–value pair whose key is key.
    • addNullAuto

      public NullNode addNullAuto()
      Creates a new instance of a null node, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Returns:
      the null node that was created and added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addBoolean

      public BooleanNode addBoolean(String key, boolean value)
      Creates a new instance of a Boolean node, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new Boolean node will be associated.
      value - the value of the new Boolean node.
      Returns:
      the Boolean node that was created and added to this map node as a key–value pair whose key is key.
    • addBooleanAuto

      public BooleanNode addBooleanAuto(boolean value)
      Creates a new instance of a Boolean node, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      value - the value of the new Boolean node.
      Returns:
      the Boolean node that was created and added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addBooleans

      public ListNode addBooleans(String key, boolean... values)
      Creates a new instance of a list node whose elements are new instances of Boolean nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing Boolean nodes will be created.
      Returns:
      the new list node that contains the Boolean nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addBooleans

      public ListNode addBooleans(String key, Iterable<Boolean> values)
      Creates a new instance of a list node whose elements are new instances of Boolean nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing Boolean nodes will be created.
      Returns:
      the new list node that contains the Boolean nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addInt

      public IntNode addInt(String key, int value)
      Creates a new instance of an 'int' node, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new 'int' node will be associated.
      value - the value of the new 'int' node.
      Returns:
      the 'int' node that was created and added to this map node as a key–value pair whose key is key.
    • addIntAuto

      public IntNode addIntAuto(int value)
      Creates a new instance of an 'int' node, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      value - the value of the new 'int' node.
      Returns:
      the 'int' node that was created and added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addInts

      public ListNode addInts(String key, int... values)
      Creates a new instance of a list node whose elements are new instances of 'int' nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing 'int' nodes will be created.
      Returns:
      the new list node that contains the 'int' nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addInts

      public ListNode addInts(String key, Iterable<Integer> values)
      Creates a new instance of a list node whose elements are new instances of 'int' nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing 'int' nodes will be created.
      Returns:
      the new list node that contains the 'int' nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addLong

      public LongNode addLong(String key, long value)
      Creates a new instance of a 'long' node, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new 'long' node will be associated.
      value - the value of the new 'long' node.
      Returns:
      the 'long' node that was created and added to this map node as a key–value pair whose key is key.
    • addLongAuto

      public LongNode addLongAuto(long value)
      Creates a new instance of a 'long' node, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      value - the value of the new 'long' node.
      Returns:
      the 'long' node that was created and added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addLongs

      public ListNode addLongs(String key, long... values)
      Creates a new instance of a list node whose elements are new instances of 'long' nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing 'long' nodes will be created.
      Returns:
      the new list node that contains the 'long' nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addLongs

      public ListNode addLongs(String key, Iterable<Long> values)
      Creates a new instance of a list node whose elements are new instances of 'long' nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing 'long' nodes will be created.
      Returns:
      the new list node that contains the 'long' nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addDouble

      public DoubleNode addDouble(String key, double value)
      Creates a new instance of a 'double' node, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new 'double' node will be associated.
      value - the value of the new 'double' node.
      Returns:
      the 'double' node that was created and added to this map node as a key–value pair whose key is key.
    • addDoubleAuto

      public DoubleNode addDoubleAuto(double value)
      Creates a new instance of a 'double' node, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      value - the value of the new 'double' node.
      Returns:
      the 'double' node that was created and added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addDoubles

      public ListNode addDoubles(String key, double... values)
      Creates a new instance of a list node whose elements are new instances of 'double' nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing 'double' nodes will be created.
      Returns:
      the new list node that contains the 'double' nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addDoubles

      public ListNode addDoubles(String key, Iterable<Double> values)
      Creates a new instance of a list node whose elements are new instances of 'double' nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing 'double' nodes will be created.
      Returns:
      the new list node that contains the 'double' nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addString

      public StringNode addString(String key, String value)
      Creates a new instance of a string node, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new string node will be associated.
      value - the value of the new string node.
      Returns:
      the string node that was created and added to this map node as a key–value pair whose key is key.
    • addStringAuto

      public StringNode addStringAuto(String value)
      Creates a new instance of a string node, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      value - the value of the new string node.
      Returns:
      the string node that was created and added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addStrings

      public ListNode addStrings(String key, String... values)
      Creates a new instance of a list node whose elements are new instances of string nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing string nodes will be created.
      Returns:
      the new list node that contains the string nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addStrings

      public ListNode addStrings(String key, Iterable<String> values)
      Creates a new instance of a list node whose elements are new instances of string nodes with the specified values, adds the list node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      values - the values for which a list node containing string nodes will be created.
      Returns:
      the new list node that contains the string nodes that were created from values and that was added to this map node as a key–value pair whose key is key.
    • addList

      public ListNode addList(String key, AbstractNode... elements)
      Creates a new instance of a list node that contains the specified elements, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      elements - the elements of the new list node.
      Returns:
      the new list node that contains elements and that was added to this map node as a key–value pair whose key is key.
    • addList

      public ListNode addList(String key, Iterable<? extends AbstractNode> elements)
      Creates a new instance of a list node that contains the specified elements, adds it to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new list node will be associated.
      elements - the elements of the new list node.
      Returns:
      the new list node that contains elements and that was added to this map node as a key–value pair whose key is key.
    • addListAuto

      public ListNode addListAuto(AbstractNode... elements)
      Creates a new instance of a list node that contains the specified elements, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      elements - the elements of the new list node.
      Returns:
      the new list node that contains elements and that was added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addListAuto

      public ListNode addListAuto(Iterable<? extends AbstractNode> elements)
      Creates a new instance of a list node that contains the specified elements, adds it to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the generated key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      elements - the elements of the new list node.
      Returns:
      the new list node that contains elements and that was added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addMap

      public MapNode addMap(String key, MapNode.Pair... pairs)
      Creates a new instance of a map node that contains the specified pairs of keys and values, adds the new map node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new map node will be associated.
      pairs - the key–value pairs of the new map node.
      Returns:
      the new map node that contains pairs and that was added to this map node as a key–value pair whose key is key.
    • addMap

      public MapNode addMap(String key, Iterable<? extends MapNode.Pair> pairs)
      Creates a new instance of a map node that contains the specified pairs of keys and values, adds the new map node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new map node will be associated.
      pairs - the key–value pairs of the new map node.
      Returns:
      the new map node that contains pairs and that was added to this map node as a key–value pair whose key is key.
    • addMap

      public MapNode addMap(String key, Map<String,AbstractNode> pairs)
      Creates a new instance of a map node that contains the specified pairs of keys and values, adds the new map node to this map node as a key–value pair with the specified key and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      key - the key with which the new map node will be associated.
      pairs - the key–value pairs of the new map node.
      Returns:
      the new map node that contains pairs and that was added to this map node as a key–value pair whose key is key.
    • addMapAuto

      public MapNode addMapAuto(MapNode.Pair... pairs)
      Creates a new instance of a map node that contains the specified pairs of keys and values, adds the new map node to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      pairs - the key–value pairs of the new map node.
      Returns:
      the new map node that contains pairs and that was added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addMapAuto

      public MapNode addMapAuto(Iterable<? extends MapNode.Pair> pairs)
      Creates a new instance of a map node that contains the specified pairs of keys and values, adds the new map node to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      pairs - the key–value pairs of the new map node.
      Returns:
      the new map node that contains pairs and that was added to this map node as a key–value pair whose key was generated by the key-generator function.
    • addMapAuto

      public MapNode addMapAuto(Map<String,AbstractNode> pairs)
      Creates a new instance of a map node that contains the specified pairs of keys and values, adds the new map node to this map node as a key–value pair with a key that is generated by the key-generator function and returns it. If this map node already contains a KV pair with the specified key, the new node will replace the value of the existing pair without affecting the order of the pairs; otherwise, a new KV pair will be added to the end of the collection of pairs.
      Parameters:
      pairs - the key–value pairs of the new map node.
      Returns:
      the new map node that contains pairs and that was added to this map node as a key–value pair whose key was generated by the key-generator function.
    • remove

      public void remove(String... keys)
      Removes the key–value pairs with the specified keys from this map node. If a specified key is not associated with a KV pair of this map node, it is ignored.
      Parameters:
      keys - the keys of the key–value pairs that will be removed from this map node.
    • remove

      public void remove(Iterable<String> keys)
      Removes the key–value pairs with the specified keys from this map node. If a specified key is not associated with a KV pair of this map node, it is ignored.
      Parameters:
      keys - the keys of the key–value pairs that will be removed from this map node.
    • remove

      public void remove(Predicate<String> keyFilter)
      Removes from this map node the key–value pairs whose keys are accepted by the specified filter.
      Parameters:
      keyFilter - the function that selects the keys of the key–value pairs that will be removed from this map node.
    • retain

      public void retain(String... keys)
      Removes all key–value pairs from this map node except for those with the specified keys.
      Parameters:
      keys - the keys of the key–value pairs that will be retained by this map node.
    • retain

      public void retain(Collection<String> keys)
      Removes all key–value pairs from this map node except for those with the specified keys.
      Parameters:
      keys - the keys of the key–value pairs that will be retained by this map node.
    • retain

      public void retain(Predicate<String> keyFilter)
      Removes all key–value pairs from this map node except for those whose keys are accepted by the specified filter.
      Parameters:
      keyFilter - the function that selects the keys of the key–value pairs that will be retained by this map node.
    • sort

      public void sort()
      Sorts the key–value pairs of this map node into ascending order of their keys by applying the String.compareTo(String) method to the keys.
    • sort

      public void sort(Comparator<String> keyComparator)
      Sorts the key–value pairs of this map node by applying the specified comparator to their keys.
      Parameters:
      keyComparator - the comparator that will be applied to the keys of this map node to determine the order of the key–value pairs. If it is null, the keys will be sorted by applying the String.compareTo(String) method to them.
    • keyToString

      public String keyToString(CharSequence key)
      Returns a string representation of the specified key for a map node.
      Parameters:
      key - the key whose string representation is required.
      Returns:
      the string representation of key.