Class KeyPath
- All Implemented Interfaces:
Printable
- Direct Known Subclasses:
KeyPath.Immut,KeyPath.Mut
Example: "my.brave.world" is a key path consisting of three strings. The front of the key path would be "my" and the
back would be "enabled". A KeyPath stores the ordered sequence and can be expanded at the front or the
back, but it cannot be shrunk (this class does not support shrinking).
Printing and display
This class implements Printable for display purposes. The dot-separated form will be the displayed product:
KeyPath myBraveWorld = new KeyPath("my", "brave", "world"); // var-args constructor
assert "my.brave.world".equals(myBraveWorld.printString());
Mutability
Mutability of this class is not defined. Please use KeyPath.Mut or KeyPath.Immut if you need
mutable or immutable versions, or see the package javadoc for more information on the mutability model we use.
Key mapping
A key path stores strings without distinction and does not handle key mapping. For convenience, users can apply a
key mapper to edit existing path elements, via KeyPath.Mut.applyKeyMapper(KeyMapper).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA key path which is unmistakably immutable.static final classstatic enumSpecifies either the start or the end of the key path sequence.Nested classes/interfaces inherited from interface space.arim.dazzleconf.backend.Printable
Printable.Abstract -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull KeyPathempty()Returns an empty key path.final booleanvoidforEach(@NonNull Consumer<? super @NonNull CharSequence> action) Runs an action for each key part in the sequence, starting from the front@Nullable CharSequencegetLeading(@NonNull KeyPath.SequenceBoundary where) Regarding this key path as a sequence of strings, this function returns either the very first value (if usingSequenceBoundary.FRONT) or the very last value (ifSequenceBoundary.BACK).inthashCode()abstract @NonNull KeyPath.ImmutGets this key path as an immutable one.abstract @NonNull KeyPath.MutintoMut()Gets this key path as a mutable one.@NonNull CharSequence @NonNull []Turns into key path parts.@NonNull List<@NonNull CharSequence> Same asintoParts()but returns a list.booleanisEmpty()Whether this key path is emptyvoiditerateFrom(@NonNull KeyPath.SequenceBoundary from, Consumer<? super @NonNull CharSequence> action) Runs an action for each key part in the sequence.@NonNull StringGets the printed content as a stringvoidprintTo(@NonNull Appendable output) Prints to the given appendablevoidprintTo(@NonNull StringBuilder output) Prints to the given builderintsize()Gets the number of key parts in the sequence@NonNull StringtoString()Gets a string representation.
-
Method Details
-
empty
Returns an empty key path.This method is provided for convenience and readability. Mutability of the returned value is not specified.
- Returns:
- an empty key path
-
isEmpty
@Pure public boolean isEmpty()Whether this key path is empty- Returns:
- true if empty
-
size
@Pure public int size()Gets the number of key parts in the sequence- Returns:
- the number of parts in this key path
-
getLeading
Regarding this key path as a sequence of strings, this function returns either the very first value (if usingSequenceBoundary.FRONT) or the very last value (ifSequenceBoundary.BACK).- Parameters:
where- the front or the back- Returns:
- the leading value at that end, or
nullif this key path is empty
-
iterateFrom
public void iterateFrom(@NonNull KeyPath.SequenceBoundary from, Consumer<? super @NonNull CharSequence> action) Runs an action for each key part in the sequence.Lets the caller pick from which end of the sequence to start from, and move in the opposite direction.
- Parameters:
from- the edge to start from; this function will iterate from it toward the other endaction- the action on each part
-
forEach
Runs an action for each key part in the sequence, starting from the front- Parameters:
action- the action on each part
-
intoMut
Gets this key path as a mutable one.If not mutable, the data is copied to a new key path which is returned. This copying may be performed lazily, such as by deferring to the first mutative operation on the returned object.
- Returns:
- this key path if mutable, or a mutable copy if needed
-
intoImmut
Gets this key path as an immutable one.The data contained within this
KeyPathis moved to an immutable instance. The old instance may still be used, but the implementation of this method may be optimized for the case that it is not.If this instance is already
DataTree.Immut, then it may be returned without changes.- Returns:
- an immutable key path
-
intoParts
Turns into key path parts.The returned array may be modified freely and will not mutate this key path.
- Returns:
- the key path's parts
-
intoPartsList
Same asintoParts()but returns a list.The returned list may be modified freely and will not mutate this key path. However, there is no guarantee that the list has a non-fixed size, e.g. it might be
Arrays.asList- Returns:
- the key path parts
-
equals
-
hashCode
public int hashCode() -
toString
Description copied from interface:PrintableGets a string representation.Implementations are strongly encouraged (but not required) to return the same value as fo
Printable.printString() -
printString
Description copied from interface:PrintableGets the printed content as a string- Specified by:
printStringin interfacePrintable- Returns:
- printed string
-
printTo
Description copied from interface:PrintablePrints to the given appendable- Specified by:
printToin interfacePrintable- Parameters:
output- where to place the message- Throws:
IOException- if the output threw this error, it is propagated
-
printTo
Description copied from interface:PrintablePrints to the given builder
-