Class KeyPath
- All Implemented Interfaces:
Comparable<KeyPath>,Iterable<String>
Often, the source is the root. These are often taken as a parameter when searching for values. In essence, they simply wrap a list of string keys, but it provides convenience methods, sensible comparison, and better typing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumComparators for keys, i.e., strings in a pathstatic enumComparators for pathsstatic class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintbooleanintbooleanCreate a new path by appending the given list of keysCreate a new path by appending the given keysinthashCode()index()Get the final index of this pathindex(long index) Create a new path by appending the given element indexCreate a new path by appending the given element indexbooleanisAncestor(KeyPath successor) Check if this path is an ancestor of the given pathstatic booleanCheck if the given key is a bracketed indexstatic booleanCheck if the given key is an attribute name, i.e., not an indexbooleanisRoot()Assuming the source is the root, check if this path refers to that rootiterator()key()Get the final key of this pathkey(int i) Create a new path by appending the given keystatic StringmakeIndex(long i) Encode the given index in decimal, without bracketsstatic StringEncode the given index as a keystatic KeyPathCreate a path from the given keysstatic KeyPathCreate a path from the given list of keysstatic KeyPathparent()Create a new path by removing the final keyparent(int n) Create a new path by removing the finalnkeysstatic KeyPathParse a path from the given stringstatic StringparseIfIndex(String key) If an index, parse it, otherwise just return the keystatic StringparseIndex(String key) Parse an index value from a keyrelativize(KeyPath successor) Assuming this is an ancestor of the given successor, compute the relative path from here to thereintsize()streamMatchingAncestry(PathFilter filter) Stream, starting with the longer paths, paths that match the given predicatestoList()Get the (immutable) list of keys from source to destinationtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ROOT
-
-
Method Details
-
makeIndex
Encode the given index in decimal, without brackets- Parameters:
i- the numeric index- Returns:
- the encoded index
-
isIndex
Check if the given key is a bracketed index- Parameters:
key- the key to check- Returns:
- true if it is an index
-
isName
Check if the given key is an attribute name, i.e., not an index- Parameters:
key- the key to check- Returns:
- true if it is an attribute name
-
parseIndex
Parse an index value from a keyWhere key is the form
[index], this merely returnsindex.- Parameters:
key- the key- Returns:
- the index
- Throws:
IllegalArgumentException- if key is not of the required form
-
parseIfIndex
If an index, parse it, otherwise just return the key- Parameters:
key- the key- Returns:
- the index or key
-
makeKey
Encode the given index as a keyWhen indexing elements, no brackets are needed. The brackets become necessary when used as a key, e.g., when specifying an index within a path, or as keys in a map of all children.
- Parameters:
index- the index- Returns:
- the key, specifying an element.
-
of
Create a path from the given list of keys- Parameters:
keyList- the list of keys from source to destination- Returns:
- the path
-
of
-
of
Create a path from the given keys- Parameters:
keys- the keys from source to destination- Returns:
- the path
-
parse
Parse a path from the given string- Parameters:
path- the dot-separated keys from source to destination- Returns:
- the path
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<KeyPath>
-
equals
-
size
public int size() -
iterator
-
key
-
toList
Get the (immutable) list of keys from source to destination- Returns:
- the key list
-
containsWildcard
public boolean containsWildcard() -
countWildcards
public int countWildcards() -
isRoot
public boolean isRoot()Assuming the source is the root, check if this path refers to that root- Returns:
- true if the path is empty, false otherwise
-
key
Create a new path by appending the given keyFor example, if this path is "
Processes[2]" andnametakes the value "Threads", the result will be "Processes[2].Threads".- Parameters:
name- the new final key- Returns:
- the resulting path
-
key
Get the final key of this path- Returns:
- the final key
-
index
Create a new path by appending the given element indexFor example, if this path is "
Processes" andindextakes the value 2, the result will be "Processes[2]".- Parameters:
index- the new final index- Returns:
- the resulting path
-
index
Create a new path by appending the given element indexThis does the same as
key(String)but uses brackets instead. For example, if this path is "Processes[2].Threads[0].Registers" andindextakes the value "RAX", the result will be "Processes[2].Threads[0].Registers[RAX]".- Parameters:
index- the new final index- Returns:
- the resulting path
-
index
Get the final index of this path- Returns:
- the final index
- Throws:
IllegalArgumentException- if the final key is not an index, i.e., in brackets
-
toString
Gives the dot-joined path
-
parent
Create a new path by removing the final key- Returns:
- the resulting path, or null if this path is empty
-
parent
Create a new path by removing the finalnkeys- Parameters:
n- the number of keys to remove- Returns:
- the resulting path, or null if fewer than 0 keys would remain
-
extend
Create a new path by appending the given list of keysFor example, if this path is "
Processes[2]" andsubtakes the value "Threads[0]", the result will be "Processes[2].Threads[0]".- Parameters:
sub- the path to append- Returns:
- the resulting path
-
extend
Create a new path by appending the given keys- Parameters:
subKeys- the keys to append- Returns:
- the resulting path
- See Also:
-
streamMatchingAncestry
Stream, starting with the longer paths, paths that match the given predicates- Parameters:
filter- the predicates to filter the ancestor paths- Returns:
- the stream of matching paths, longest to shortest
-
isAncestor
Check if this path is an ancestor of the given pathEquivalently, check if the given path is a successor of this path. A path is considered an ancestor of itself. To check for a strict ancestor, use
this.isAncestor(that) && !this.equals(that).- Parameters:
successor- the supposed successor to this path- Returns:
- true if the given path is in fact a successor
-
relativize
Assuming this is an ancestor of the given successor, compute the relative path from here to there- Parameters:
successor- the successor- Returns:
- the relative path
-