Class MapNode
- All Implemented Interfaces:
Cloneable
,ITreeNode<AbstractNode>
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 whose key is equal to the key of the new pair,
the value of the new pair will replace the old value in the map without affecting the order of the KV pairs.
A map node may be created with an initial collection of key–value pairs. A map node is mutable: KV pairs may be added to and removed from a map node after its creation.
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class encapsulates a key–value pair of a map node. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
The character that denotes the end of the string representation of a map node.static final char
The character that separates the key and value of a KV pair in the string representation of a map node.static final char
The character that separates adjacent KV pairs in the string representation of a map node.static final char
The character that denotes the start of the string representation of a map node.static final NodeType
The type of a map node. -
Constructor Summary
ConstructorsConstructorDescriptionMapNode()
Creates a new instance of a map node that has no parent and initially contains no key–value pairs.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.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.MapNode
(AbstractNode parent) Creates a new instance of a map node that has the specified parent and initially contains no key–value pairs.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.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.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.MapNode
(MapNode.Pair... pairs) Creates a new instance of a map node that has no parent and initially contains the specified key–value pairs. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(String key, AbstractNode value) Adds a key–value pair with the specified key and value to this map node.void
add
(MapNode.Pair pair) Adds the specified key–value pair to this map node.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.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.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.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.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.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.<T extends AbstractNode>
TaddIfAbsent
(String key, T value) Adds a key–value pair with the specified key and value to this map node if it does not already contain a KV pair with the specified key.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.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.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.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.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.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.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.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.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.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.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.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.void
addPairs
(Iterable<? extends MapNode.Pair> pairs) Adds the specified key–value pairs to the key–value pairs of this map node.void
addPairs
(Map<String, AbstractNode> pairs) Adds the specified pairs of keys and values to the key–value pairs of this map node.void
addPairs
(MapNode.Pair... pairs) Adds the specified key–value pairs to the key–value pairs of this map node.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.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.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.void
clear()
Removes all the key–value pairs of this map node.clone()
Creates and returns a deep copy of this map node that has no parent.boolean
Returnstrue
if the specified object is an instance ofMapNode
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.findKey
(AbstractNode value) Returns the key that is associated with the specified value in this map node.Returns the value of the key–value pair of this map node with the specified key.boolean
getBoolean
(String key) Returns the underlying value of the Boolean node that is associated with the specified key in this map node.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.getBooleanNode
(String key) Returns the Boolean node that is associated with the specified key in this map node.Returns a list of the values of the key–value pairs of this map node.double
Returns the underlying value of the 'double' node that is associated with the specified key in this map node.double
Returns the underlying value of the 'double' node that is associated with the specified key in this map node.getDoubleNode
(String key) Returns the 'double' node that is associated with the specified key in this map node.<E extends Enum<E>>
EgetEnumValue
(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.<E extends Enum<E>>
EgetEnumValue
(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.int
Returns the underlying value of the 'int' node that is associated with the specified key in this map node.int
Returns the underlying value of the 'int' node that is associated with the specified key in this map node.getIntNode
(String key) Returns the 'int' node that is associated with the specified key in this map node.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.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.getKeys()
Returns a list of the keys of the key–value pairs of this map node.getListNode
(String key) Returns the list node that is associated with the specified key in this map node.long
Returns the underlying value of the 'long' node that is associated with the specified key in this map node.long
Returns the underlying value of the 'long' node that is associated with the specified key in this map node.getLongNode
(String key) Returns the 'long' node that is associated with the specified key in this map node.getMapNode
(String key) Returns the map node that is associated with the specified key in this map node.getNullNode
(String key) Returns the null node that is associated with the specified key in this map node.int
Returns the number of key–value pairs that this map node contains.Returns an iterator over the key–value pairs of this map node.Returns a list of the key–value pairs of this map node.getPairs()
Returns an unmodifiable map of the key–value pairs of this map node.Returns the underlying value of the string node that is associated with the specified key in this map node.Returns the underlying value of the string node that is associated with the specified key in this map node.getStringNode
(String key) Returns the string node that is associated with the specified key in this map node.getType()
Returns the type of this node.boolean
hasBoolean
(String key) Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a Boolean node.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a 'double' node.int
hashCode()
Returns the hash code of this map node, which is the hash code of its key–value pairs.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is an 'int' node.boolean
hasIntOrLong
(String key) Returnstrue
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.boolean
Returnstrue
if this map node contains a key–value pair with the specified key.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a list node.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a 'long' node.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a map node.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a null node.boolean
Returnstrue
if this map node contains a key–value pair whose key is the specified key and whose value is a string node.boolean
Returnstrue
if this node can contain other nodes.boolean
isEmpty()
Returnstrue
if this map node contains no key–value pairs.static String
keyToString
(CharSequence key) Returns a string representation of the specified key for a map node.static String
keyToString
(CharSequence key, boolean printableAsciiOnly) Returns a string representation of the specified key for a map node.static MapNode.Pair
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.static MapNode.Pair
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.static MapNode.Pair
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.static MapNode.Pair
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.static MapNode.Pair
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.void
Removes the key–value pairs with the specified keys from this map node.void
Removes the key–value pairs with the specified keys from this map node.void
Removes from this map node the key–value pairs whose keys are accepted by the specified filter.void
Removes all key–value pairs from this map node except for those with the specified keys.void
retain
(Collection<String> keys) Removes all key–value pairs from this map node except for those with the specified keys.void
Removes all key–value pairs from this map node except for those whose keys are accepted by the specified filter.void
setPairs
(Map<String, AbstractNode> pairs) Sets the key–value pairs of this map node to the specified pairs of keys and values.void
sort()
Sorts the key–value pairs of this map node into ascending order of their keys by applying theString.compareTo(String)
method to the keys.void
sort
(Comparator<String> keyComparator) Sorts the key–value pairs of this map node by applying the specified comparator to their keys.toString()
Returns a string representation of this map node.toString
(boolean printableAsciiOnly) Returns a string representation of this node whose characters may optionally be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding.Methods inherited from class uk.blankaspect.common.basictree.AbstractNode
getListIndex, getMapKey, getParent, isRoot, setParent
-
Field Details
-
START_CHAR
public static final char START_CHARThe character that denotes the start of the string representation of a map node.- See Also:
-
END_CHAR
public static final char END_CHARThe 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_CHARThe 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_CHARThe character that separates adjacent KV pairs in the string representation of a map node.- See Also:
-
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
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
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
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
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
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
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
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
-
pair
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 isvalue
.
-
pair
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 isvalue
.
-
pair
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 isvalue
.
-
pair
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 isvalue
.
-
pair
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 isvalue
.
-
keyToString
Returns a string representation of the specified key for a map node.- Parameters:
key
- the key whose string representation is desired.- Returns:
- the string representation of
key
.
-
keyToString
Returns a string representation of the specified key for a map node.- Parameters:
key
- the key whose string representation is desired.printableAsciiOnly
- iftrue
, the characters ofkey
will be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).- Returns:
- the string representation of
key
.
-
getType
Description copied from class:AbstractNode
Returns the type of this node.- Specified by:
getType
in classAbstractNode
- Returns:
TYPE
.
-
isContainer
public boolean isContainer()Returnstrue
if this node can contain other nodes. For a map node, this method always returnstrue
.- Specified by:
isContainer
in classAbstractNode
- Returns:
true
.
-
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 interfaceITreeNode<AbstractNode>
- Overrides:
getChildren
in classAbstractNode
- Returns:
- a list of the values of the key–value pairs of this map node.
- See Also:
-
equals
Returnstrue
if the specified object is an instance ofMapNode
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 classObject
- Parameters:
obj
- the object with which this map node will be compared.- Returns:
true
ifobj
is an instance ofMapNode
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. -
clone
Creates and returns a deep copy of this map node that has no parent.- Overrides:
clone
in classAbstractNode
- Returns:
- a deep copy of this map node that has no parent.
-
toString
Returns a string representation of this map node. -
toString
Returns a string representation of this node whose characters may optionally be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding.- Overrides:
toString
in classAbstractNode
- Parameters:
printableAsciiOnly
- iftrue
, the characters of the string representation will be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).- Returns:
- a string representation of this node.
-
isEmpty
public boolean isEmpty()Returnstrue
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
Returnstrue
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 iskey
;false
otherwise.
-
hasNull
Returnstrue
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 iskey
and whose value is a null node;false
otherwise.
-
hasBoolean
Returnstrue
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 iskey
and whose value is a Boolean node;false
otherwise.
-
hasInt
Returnstrue
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 iskey
and whose value is an 'int' node;false
otherwise.
-
hasLong
Returnstrue
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 iskey
and whose value is a 'long' node;false
otherwise.
-
hasIntOrLong
Returnstrue
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 iskey
and whose value is either an 'int' node or a 'long' node;false
otherwise.
-
hasDouble
Returnstrue
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 iskey
and whose value is a 'double' node;false
otherwise.
-
hasString
Returnstrue
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 iskey
and whose value is a string node;false
otherwise.
-
hasList
Returnstrue
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 iskey
and whose value is a list node;false
otherwise.
-
hasMap
Returnstrue
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 iskey
and whose value is a map node;false
otherwise.
-
get
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 desired.- Returns:
- the value of the key–value pair of this map node whose key is
key
, ornull
if this map node does not contain a KV pair with such a key.
-
getNullNode
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 desired.- Returns:
- the null node that is associated with
key
in this map node, ornull
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 ofNullNode
.
-
getBooleanNode
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 desired.- Returns:
- the Boolean node that is associated with
key
in this map node, ornull
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 ofBooleanNode
.
-
getBoolean
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 desired.- 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 ofBooleanNode
.
-
getBoolean
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 desired.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, ordefaultValue
if there is no such node.
-
getIntNode
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 desired.- Returns:
- the 'int' node that is associated with
key
in this map node, ornull
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 ofIntNode
.
-
getInt
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 desired.- 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 ofIntNode
.
-
getInt
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 desired.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, ordefaultValue
if there is no such node.
-
getLongNode
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 desired.- Returns:
- the 'long' node that is associated with
key
in this map node, ornull
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 ofLongNode
.
-
getLong
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 desired.- 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 ofLongNode
.
-
getLong
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 desired.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, ordefaultValue
if there is no such node.
-
getIntOrLong
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 desired.- 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 ofIntNode
nor an instance ofLongNode
.
-
getIntOrLong
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 desired.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, ordefaultValue
if there is no such node.
-
getDoubleNode
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 desired.- Returns:
- the 'double' node that is associated with
key
in this map node, ornull
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 ofDoubleNode
.
-
getDouble
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 desired.- 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 ofDoubleNode
.
-
getDouble
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 desired.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, ordefaultValue
if there is no such node.
-
getStringNode
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 desired.- Returns:
- the string node that is associated with
key
in this map node, ornull
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 ofStringNode
.
-
getString
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 desired.- 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 ofStringNode
.
-
getString
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 desired.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, ordefaultValue
if there is no such node.
-
getListNode
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 desired.- Returns:
- the list node that is associated with
key
in this map node, ornull
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 ofListNode
.
-
getMapNode
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 desired.- Returns:
- the map node that is associated with
key
in this map node, ornull
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 ofMapNode
.
-
getEnumValue
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 ofcls
.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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 withkey
in this map node, ordefaultValue
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 ofcls
afterconverter
has been applied to it.converter
- the function that converts the enumeration constants ofcls
to strings.defaultValue
- the value that will be returned if this map node does not contain a key–value pair whose key iskey
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, afterconverter
has been applied to it, matches the the underlying value of the string node that is associated withkey
in this map node, ordefaultValue
if there is no such node or there is no matching enumeration constant.
-
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
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
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
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:
-
findKey
Returns the key that is associated with the specified value in this map node. Values are tested for identity, not for equality; that is, two values,v1
andv2
, match if and only ifv1 == v2
.- Parameters:
value
- the value whose associated key is desired.- Returns:
- the key that is associated with
value
in this map node, ornull
if there is no such key.
-
clear
public void clear()Removes all the key–value pairs of this map node. -
setPairs
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
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
- ifpair
isnull
.
-
add
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 KV pairs.- Parameters:
key
- the key of the key–value pair.value
- the value of the key–value pair.- Throws:
IllegalArgumentException
- ifkey
isnull
orvalue
isnull
.
-
addIfAbsent
Adds a key–value pair with the specified key and value to this map node if it does not already contain a KV pair with the specified key.
-
If this node already contains a KV pair with the specified key, a
ClassCastException
is thrown if the type of the existing value is different from the type of the specified value. If the types of the existing value and the specified value are the same, the existing value is returned. This node is not modified. - If this node does not contain a KV pair with the specified key, a new KV pair will be added to the end of the collection of KV pairs.
- Type Parameters:
T
- the type of the value that will be added to this map node if it does not already contain a key–value pair with the specified key.- Parameters:
key
- the key of the key–value pair.value
- the value of the key–value pair.- Returns:
- the value that is associated with
key
in this node's collection of KV pairs. - Throws:
IllegalArgumentException
- ifkey
isnull
orvalue
isnull
.ClassCastException
- if this map node already contains an entry forkey
but the type of the associated value is different from the type ofvalue
.
-
If this node already contains a KV pair with the specified key, a
-
addPairs
Adds the specified key–value pairs to the key–value pairs of this map node. For each of the new pairs, if this node already contains a KV pair with the key of the new pair, 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
Adds the specified key–value pairs to the key–value pairs of this map node. For each of the new pairs, if this node already contains a KV pair with the key of the new pair, 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
Adds the specified pairs of keys and values to the key–value pairs of this map node. For each of the new pairs, if this node already contains a KV pair with the key of the new pair, 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
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
.
-
addBoolean
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
.
-
addBooleans
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 iskey
.
-
addBooleans
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 iskey
.
-
addInt
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
.
-
addInts
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 iskey
.
-
addInts
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 iskey
.
-
addLong
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
.
-
addLongs
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 iskey
.
-
addLongs
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 iskey
.
-
addDouble
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
.
-
addDoubles
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 iskey
.
-
addDoubles
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 iskey
.
-
addString
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
.
-
addStrings
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 iskey
.
-
addStrings
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 iskey
.
-
addList
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 iskey
.
-
addList
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 iskey
.
-
addMap
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 iskey
.
-
addMap
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 iskey
.
-
addMap
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 iskey
.
-
remove
Removes the key–value pairs with the specified keys from this map node. For each of the specified keys, if the 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
Removes the key–value pairs with the specified keys from this map node. For each of the specified keys, if the 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
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
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
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
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 theString.compareTo(String)
method to the keys. -
sort
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 isnull
, the keys will be sorted by applying theString.compareTo(String)
method to them.
-