- Type Parameters:
T- the type of thePath; most notably not necessarily the type of the thing thePath"points to"; more like an additional qualifier
A Path can be used like a javax.naming.Name, or like a java.nio.file.Path, or like a java.net.URI.
It differs from these other objects in that it combines some of
their concepts together.
- Author:
- Laird Nelson
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn element normally within aPath, consisting of aQualifiers, a name, and an optional thing that it designates or points to.Nested classes/interfaces inherited from interface org.microbean.qualifier.Qualified
Qualified.Record<K extends Comparable<? super K>,V extends Object, T extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionPath(Path.Element<? extends T> lastElement) Creates a newPath.Path(Qualifiers<? extends String, ?> qualifiers, List<? extends Path.Element<?>> elements, Path.Element<? extends T> lastElement) Creates a newPath.Path(Qualifiers<? extends String, ?> qualifiers, Path.Element<? extends T> lastElement) Creates a newPath. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanabsolute()Returnstrueif and only if thisPathis absolute, which means that its firstPath.Elementis a rootPath.Element.final Optional<? extends ConstantDesc>Returns anOptionalcontaining aConstantDescrepresenting thisPath, or an emptyOptionalif thisPathcannot be represented as aConstantDesc.final booleanfinal booleanendsWith(Path<?> other, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) final booleanfinal Path.Element<?>get(int index) Returns thePath.Elementfound at the supplied zero-based index.final inthashCode()Returns a hashcode for thisPath.final intfinal intindexOf(Path<?> path, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) final booleanisRoot()final Iterator<Path.Element<?>>iterator()final Path.Element<T>Returns the lastPath.Elementin thisPath.final intlastIndexOf(Path<?> other) final intlastIndexOf(Path<?> path, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) static final <T> Path<T>of(Path.Element<? extends T> lastElement) Returns a (usually new)Pathformed from the suppliedlastElement.static final <T> Path<T>of(Qualifiers<? extends String, ?> pathQualifiers, List<? extends Path.Element<?>> elements, Path.Element<? extends T> lastElement) Return a (usually new)Pathformed from the supplied arguments and returns it.static final <T> Path<T>of(Qualifiers<? extends String, ?> pathQualifiers, Path.Element<? extends T> lastElement) Return a (usually new)Pathformed from the supplied arguments and returns it.static final <T> Path<T>of(T qualified) Returns a (usually new)Pathformed from aPath.Elementformed from the suppliedqualifiedand an empty name.static final <T> Path<T>Returns a (usually new)Pathformed from aPath.Elementformed from the suppliedqualifiedand the supplied name.static final <T> Path<T>Returns a (usually new)Pathformed fromPath.Elements formed from the suppliedqualifiedand the supplied array of names.static final <T> Path<T>Returns a (usually new)Pathformed fromPath.Elements formed from the suppliedqualifiedand the suppliedListof names.final Stream<Path.Element<?>>final <U> Path<U>plus(Collection<? extends Path.Element<?>> elements, Path.Element<? extends U> lastElement) Returns a newPathconsisting of thisPath's qualifiers, thisPath's elements, the suppliedelements, and the suppliedlastElement.final <U> Path<U>plus(Path.Element<? extends U> element) final <U> Path<U>Returns a newPathconsisting of thisPath's qualifiers combined with a prefixed version of the suppliedPath's qualifiers, thisPath's elements, the suppliedPath's elements, and the suppliedPath's last element.final TCalls thePath.Element.qualified()method on the last element in thisPathand returns the result.final Qualifiers<String,Object> Returns theQualifiersthat qualifies thisPath.static final Path<?>root()Returns aPaththat is a root path.final intsize()final Spliterator<Path.Element<?>>final booleanstartsWith(Path<?> other) final booleanstartsWith(Path<?> other, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) final Stream<Path.Element<?>>stream()final StringtoString()Transliterates thisPathinto another, semantically equivalentPathby producing aPaththat is otherwise equal to thisPathbut that will returntruefrom itstransliterated()method.final @Experimental Path<T>transliterate(BiFunction<? super String, ? super Path.Element<?>, ? extends Path.Element<?>> f) Transliterates thisPathinto another, semantically equivalentPathby applying the suppliedBiFunction, and returns the transliteratedPath.final boolean
-
Constructor Details
-
Path
Creates a newPath.- Parameters:
lastElement- the last element of thisPath; must not benull- Throws:
NullPointerException- if any parameter isnull- See Also:
-
Path
Creates a newPath.- Parameters:
qualifiers- thePath's qualifiers; must not benulllastElement- the last element of thisPath; must not benull- Throws:
NullPointerException- if any parameter isnull- See Also:
-
Path
public Path(Qualifiers<? extends String, ?> qualifiers, List<? extends Path.Element<?>> elements, Path.Element<? extends T> lastElement) Creates a newPath.- Parameters:
qualifiers- thePath's qualifiers; must not benullelements- the elements of thisPath; must not benull; may be emptylastElement- the last element of thisPath; must not benull- Throws:
NullPointerException- if any parameter isnull
-
-
Method Details
-
transliterated
- Returns:
trueif thisPathis transliterated;falseotherwise
-
transliterate
Transliterates thisPathinto another, semantically equivalentPathby producing aPaththat is otherwise equal to thisPathbut that will returntruefrom itstransliterated()method.Transliteration can be needed when a
Pathis defined by a Java class and used by an application containing that Java class—because another Java class may have used the same element names to refer to different things.If this
Pathis already transliterated then it is returned.This method calls
transliterate(BiFunction)withnullas its sole argument. -
transliterate
@Experimental public final @Experimental Path<T> transliterate(BiFunction<? super String, ? super Path.Element<?>, ? extends Path.Element<?>> f) Transliterates thisPathinto another, semantically equivalentPathby applying the suppliedBiFunction, and returns the transliteratedPath.The supplied
BiFunctionaccepts a Java package name as its first argument, which will be the first package name encountered in the current thread's stack that identifies a caller whose package name is not equal toPath.class.getPackageName(). Its second argument is aElementfrom thisPath. It must return aPath.Elementrepresenting the transliteration of its second argument (which may be the second argument itself).Transliteration can be needed when a
Pathis defined by a Java class and used by an application containing that Java class—because another Java class may have used the same element names to refer to different things.If this
Pathis already transliterated then it is returned.- Parameters:
f- aBiFunctionresponsible for the transliteration, element by element; may benull- Returns:
- the transliterated
Path, which may be thisPath; nevernull - See Also:
- Idempotency:
- This method is idempotent and deterministic, but the
supplied
BiFunctionmay not be. - Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple
threads, but the supplied
BiFunctionmay not be.
-
describeConstable
Returns anOptionalcontaining aConstantDescrepresenting thisPath, or an emptyOptionalif thisPathcannot be represented as aConstantDesc.A
Pathinstance may be represented by aConstantDesconly when the return value of an invocation of thePath.Element.describeConstable()method on its last element returns a non-emptyOptional.- Specified by:
describeConstablein interfaceConstable- Specified by:
describeConstablein interfaceQualified<String,Object, T> - Returns:
- an
Optionalcontaining aConstantDescrepresenting thisPath; nevernull; possibly empty - See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
qualifiers
Returns theQualifiersthat qualifies thisPath.- Specified by:
qualifiersin interfaceQualified<String,Object, T> - Returns:
- the
Qualifiersthat qualifies thisPath - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
get
Returns thePath.Elementfound at the supplied zero-based index.- Parameters:
index- the index of thePath.Elementto return; must be0or greater and less than thisPath's size- Returns:
- the
Path.Elementfound at the supplied zero-based index - Throws:
IndexOutOfBoundsException- ifindexdoes not meet the requirements described above- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
iterator
- Specified by:
iteratorin interfaceIterable<T>- Returns:
- an
Iteratorthat iterates over the elements of thisPath, including the last element - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
spliterator
- Specified by:
spliteratorin interfaceIterable<T>- Returns:
- a
Spliteratorfor the elements of thisPath, including the last element - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
stream
- Returns:
- a possibly parallel
Streamof thisPath'sPath.Elements - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
parallelStream
- Returns:
- a possibly parallel
Streamof thisPath'sPath.Elements - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
size
- Returns:
- the number of
Path.Elements in thisPath - Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
indexOf
Returns the zero-based index identifying the position of the first occurrence of aPathequal to the suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath.- Parameters:
other- the otherPath; must not benull- Returns:
- the zero-based index identifying the position of the
first occurrence of a
Pathequal to suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath - Throws:
NullPointerException- ifotherisnull- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
indexOf
public final int indexOf(Path<?> path, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) Returns the zero-based index identifying the position of the first occurrence of aPathequal to suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath.The supplied
BiPredicateis used to test eachPath.Elementof the suppliedPathagainstPath.Elements from thisPath. The first argument is aPath.Elementdrawn from thisPath. The second argument is anPath.Elementdrawn from the suppliedPath. TheBiPredicatereturnstrueif its arguments are deemed to match. The suppliedBiPredicate'sBiPredicate.test(Object, Object)method must be idempotent and deterministic.- Parameters:
path- the otherPath; must not benullp- theBiPredicateused to testPath.Elements; must not benull- Returns:
- the zero-based index identifying the position of the
first occurrence of a
Pathequal to suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath - Throws:
NullPointerException- if eitherpathorpisnull- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
startsWith
Returnstrueif thisPathstarts with aPaththat is equal to the suppliedPath.This method returns
trueif and only if:otheris identical to thisPath, or- An invocation of the
indexOf(Path)method withotheras its sole argument returns0
- Parameters:
other- the otherPath; must not benull- Returns:
trueif thisPathstarts with aPaththat is equal to the suppliedPath;falseotherwise- Throws:
NullPointerException- ifotherisnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
lastElement
Returns the lastPath.Elementin thisPath.- Returns:
- the last
Path.Elementin thisPath - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
lastIndexOf
Returns the zero-based index identifying the position of the last occurrence of aPathequal to the suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath.- Parameters:
other- the otherPath; must not benull- Returns:
- the zero-based index identifying the position of the
last occurrence of a
Pathequal to suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath - Throws:
NullPointerException- ifotherisnull- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
lastIndexOf
public final int lastIndexOf(Path<?> path, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) Returns the zero-based index identifying the position of the last occurrence of aPathequal to suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath.The supplied
BiPredicateis used to test eachPath.Elementof the suppliedPathagainstPath.Elements from thisPath. The first argument is aPath.Elementdrawn from thisPath. The second argument is anPath.Elementdrawn from the suppliedPath. TheBiPredicatereturnstrueif its arguments are deemed to match. The suppliedBiPredicate'sBiPredicate.test(Object, Object)method must be idempotent and deterministic.- Parameters:
path- the otherPath; must not benullp- theBiPredicateused to testPath.Elements; must not benull- Returns:
- the zero-based index identifying the position of the
last occurrence of a
Pathequal to suppliedPathwithin thisPath, or a negative value if the suppliedPathdoes not occur within thisPath - Throws:
NullPointerException- if eitherpathorpisnull- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
startsWith
public final boolean startsWith(Path<?> other, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) Returnstrueif thisPathstarts with aPaththat is equal to the suppliedPath.The supplied
BiPredicateis used to test eachPath.Elementof the suppliedPathagainstPath.Elements from thisPath. The first argument is aPath.Elementdrawn from thisPath. The second argument is aPath.Elementdrawn from the suppliedPath. TheBiPredicatereturnstrueif its arguments are deemed to match. The suppliedBiPredicate'sBiPredicate.test(Object, Object)method must be idempotent and deterministic.This method returns
trueif and only if:otheris identical to thisPath, or- An invocation of the
indexOf(Path, BiPredicate)method withotherandpas its arguments returns0
- Parameters:
other- the otherPath; must not benullp- theBiPredicateused to testPath.Elements; must not benull- Returns:
trueif thisPathstarts with aPaththat is equal to the suppliedPath;falseotherwise- Throws:
NullPointerException- ifotherisnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
endsWith
Returnstrueif thisPathends with aPaththat is equal to the suppliedPath.This method returns
trueif and only if:- Parameters:
other- the otherPath; must not benull- Returns:
trueif thisPathends with aPaththat is equal to the suppliedPath;falseotherwise- Throws:
NullPointerException- ifotherisnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
endsWith
public final boolean endsWith(Path<?> other, BiPredicate<? super Path.Element<?>, ? super Path.Element<?>> p) Returnstrueif thisPathends with aPaththat is equal to the suppliedPath.The supplied
BiPredicateis used to test eachPath.Elementof the suppliedPathagainstPath.Elements from thisPath. The first argument is aPath.Elementdrawn from thisPath. The second argument is aPath.Elementdrawn from the suppliedPath. TheBiPredicatereturnstrueif its arguments are deemed to match. The suppliedBiPredicate'sBiPredicate.test(Object, Object)method must be idempotent and deterministic.This method returns
trueif and only if:- Parameters:
other- the otherPath; must not benullp- theBiPredicateused to testPath.Elements; must not benull- Returns:
trueif thisPathends with aPaththat is equal to the suppliedPath;falseotherwise- Throws:
NullPointerException- ifotherisnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
qualified
Calls thePath.Element.qualified()method on the last element in thisPathand returns the result.- Specified by:
qualifiedin interfaceQualified<String,Object, T> - Returns:
- the result of invoking the
Path.Element.qualified()method on the last element in thisPath - Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method may return
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
isRoot
Returnstrueif thisPathis a root path, which is true when it has only one element and that element is root.- Returns:
trueif thisPathis a root path;falseotherwise- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
absolute
Returnstrueif and only if thisPathis absolute, which means that its firstPath.Elementis a rootPath.Element.- Returns:
trueif and only if thisPathis absolute
-
hashCode
Returns a hashcode for thisPath. -
equals
- Overrides:
equalsin classObject- Parameters:
other- theObjectto test; may benullin which casefalsewill be returned- Returns:
trueif and only if the suppliedObjectis equal to thisPath- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
plus
- Type Parameters:
U- the type of the newPath- Parameters:
element- the newPath's last element; must not benull- Returns:
- a new
Pathconsisting of thisPath's qualifiers and elments plus the supplied element - Throws:
NullPointerException- ifelementisnull- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
plus
public final <U> Path<U> plus(Collection<? extends Path.Element<?>> elements, Path.Element<? extends U> lastElement) Returns a newPathconsisting of thisPath's qualifiers, thisPath's elements, the suppliedelements, and the suppliedlastElement.- Type Parameters:
U- the type of the newPath- Parameters:
elements- additional elements; must not benulllastElement- the newPath's last element; must not benull- Returns:
- a new
Pathconsisting of thisPath's qualifiers, thisPath's elements, the suppliedelements, and the suppliedlastElement - Throws:
NullPointerException- ifelementisnull- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
plus
Returns a newPathconsisting of thisPath's qualifiers combined with a prefixed version of the suppliedPath's qualifiers, thisPath's elements, the suppliedPath's elements, and the suppliedPath's last element.The new
Path's qualifiers are those of thisPathplus those of the suppliedPath, where each qualifier in the suppliedPath's qualifiers has been prefixed with aStringformed from the names of all the elements in thisPath.- Type Parameters:
U- the type of the newPath- Parameters:
path- thePathto logically append; must not benull- Returns:
- a new
Pathconsisting of thisPath's qualifiers combined with a prefixed version of the suppliedPath's qualifiers, thisPath's elements, the suppliedPath's elements, and the suppliedPath's last element - Throws:
NullPointerException- ifpathisnull- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
toString
-
root
Returns aPaththat is a root path.- Returns:
- a
Paththat is a root path - See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
Returns a (usually new)Pathformed from aPath.Elementformed from the suppliedqualifiedand an empty name.- Type Parameters:
T- the type of thePath- Parameters:
qualified- the qualified item of what will be the lastPath.Element- Returns:
- a
Path - Throws:
NullPointerException- ifqualifiedisnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
Returns a (usually new)Pathformed from aPath.Elementformed from the suppliedqualifiedand the supplied name.- Type Parameters:
T- the type of thePath- Parameters:
qualified- the qualified item of what will be the lastPath.Elementname- the name of what will be the lastPath.Element- Returns:
- a
Path - Throws:
NullPointerException- ifnameisnullIllegalArgumentException- ifqualifiedisnulland name isnullor an emptyString}- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
Returns a (usually new)Pathformed fromPath.Elements formed from the suppliedqualifiedand the supplied array of names.- Type Parameters:
T- the type of thePath- Parameters:
qualified- the qualified item of what will be the lastPath.Elementnames- an array of names from whichPath.Elements will be synthesized; must not benull- Returns:
- a
Path - Throws:
NullPointerException- ifnamesisnullIllegalArgumentException- ifqualifiedisnulland the last element ofnamesis an emptyString- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
Returns a (usually new)Pathformed from the suppliedlastElement.- Type Parameters:
T- the type of thePath- Parameters:
lastElement- the lastPath.Element; must not benull- Returns:
- a
Path - Throws:
NullPointerException- iflastElementisnull- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
Returns a (usually new)Pathformed fromPath.Elements formed from the suppliedqualifiedand the suppliedListof names.- Type Parameters:
T- the type of thePath- Parameters:
qualified- the qualified item of what will be the lastPath.Elementnames- aListof names from whichPath.Elements will be synthesized; must not benull- Returns:
- a
Path - Throws:
NullPointerException- ifnamesisnullIllegalArgumentException- ifqualifiedisnulland the last element ofnamesis an emptyString- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
public static final <T> Path<T> of(Qualifiers<? extends String, ?> pathQualifiers, Path.Element<? extends T> lastElement) Return a (usually new)Pathformed from the supplied arguments and returns it.- Type Parameters:
T- the type of thePath- Parameters:
pathQualifiers- thePath's qualifiers; must not benulllastElement- the lastElementof thePath; must not benull- Returns:
- a (usually new)
Path - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
of
public static final <T> Path<T> of(Qualifiers<? extends String, ?> pathQualifiers, List<? extends Path.Element<?>> elements, Path.Element<? extends T> lastElement) Return a (usually new)Pathformed from the supplied arguments and returns it.- Type Parameters:
T- the type of the newPath- Parameters:
pathQualifiers- thePath's qualifiers; must not benullelements- the interiorPath.Elements of thePath; must not benulllastElement- the lastElementof thePath; must not benull- Returns:
- a (usually new)
Path - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-