- All Superinterfaces:
OptionalSupplier<T>,Supplier<T>
OptionalSupplier that supplies an
environmental object, and can load others.
Note: Loader implementations are
expected to be immutable with respect to the methods exposed by
this interface. All methods in this interface that have a Loader-typed return type require their implementations to return a
new Loader.
The presence of the @OverridingDiscouraged annotation on a
method means that undefined behavior may result if an
implementation of this interface provides an alternate
implementation of the method in question.
- Author:
- Laird Nelson
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.microbean.invoke.OptionalSupplier
OptionalSupplier.Determinism -
Method Summary
Modifier and TypeMethodDescriptiondefault @Experimental Path<? extends Type>Experimental; do not use.default <P> @Experimental Path<P>absolutePath(Path<P> path) default <L extends Loader<?>>
LCasts thisLoaderappropriately and returns it, usually so that an implementation's implementation-specific methods can be accessed.default booleanisRoot()Returnstrueif and only if thisLoaderis the rootLoader, which occurs only when the return value ofthis.parent() == this.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.<U> Loader<U>default <U> Loader<U>load(Qualifiers<? extends String, ?> qualifiers, Class<U> type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>load(Qualifiers<? extends String, ?> qualifiers, Type type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>load(Qualifiers<? extends String, ?> qualifiers, org.microbean.type.JavaType.Token<U> type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>load(org.microbean.type.JavaType.Token<U> type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.default <U> Loader<U>Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.static Loader<?>loader()Bootstraps and returns aLoader.default Loader<?>Returns an ancestralLoader, derived from and possibly identical to thisLoader, that is suitable for a transliterated and absolute version of the suppliedpath, particularly for cases where, during the execution of theload(Path)method, aLoadermust be supplied to some other class.Loader<?>parent()path()default Loader<?>root()transliterate(Path<U> path) Transliterates the supplied absolutePathinto some otherPath, whose meaning is the same, but whose representation may be different, that will be used instead.Methods inherited from interface org.microbean.invoke.OptionalSupplier
determinism, exceptionally, get, handle, ifPresent, ifPresentOrElse, optional, optional, optional, orElse, orElseGet, orElseThrow, orElseThrow, stream
-
Method Details
-
parent
Returns theLoaderthat is the parent of thisLoader.The root
Loaderis defined to be the only one whoseparent()method returns itself. It follows that in general aLoaderimplementation should not returnthis. SeeisRoot()for details.- Returns:
- the
Loaderthat is the parent of thisLoader; notthisin almost all circumstances - See Also:
- Idempotency:
- Implementations of this method must be idempotent and deterministic.
- Nullability:
- Implementations of this method must not return
null. - Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
path
Returns thePathwith which thisLoaderwas created.The
Paththat is returned by an implementation of this method is not guaranteed to be absolute.The
Paththat is returned by an implementation of this method must be equal to a transliterated version of thePaththat was supplied to theload(Path)method of thisLoader's parent that resulted in thisLoader's creation.- Returns:
- the non-
nullPathwith which thisLoaderwas created - See Also:
- Idempotency:
- Implementations of this method must be idempotent and deterministic.
- Nullability:
- Implementations of this method must not return
null. - Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
absolutePath
Experimental; do not use.- Returns:
- an absolute
Path - Throws:
NullPointerException- ifpath()orparent()is implemented incorrectly- See Also:
- Idempotency:
- This method is, and its overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its overrides must not,
return
null. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
absolutePath
- Type Parameters:
P- the type of the path- Parameters:
path- aPath; must not benull- Returns:
- an absolute
Path - Throws:
NullPointerException- ifpathisnullor if #parent()} is implemented incorrectly- Idempotency:
- This method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Uses the addressing information encoded in the suppliedPathto load and return theLoaderlogically found at that location, following additional contractual requirements defined below.Any
Loaderreturned by an implementation of this method:- must not be
null - must implement its
get()method and itsdeterminism()method to indicate the transitory or permanent presence or absence of any value it might supply
The default implementations of all other methods in this interface named
loadcall this method.- Type Parameters:
U- the type of the environmental object the returnedLoadercan supply- Parameters:
path- thePath(perhaps only partially) identifying theLoaderto load; must not benull; may be absolute or relative (in which case it will be appended to thisLoader'sPath)- Returns:
- a
Loaderfor the suppliedPath; must not benull, but may implement itsget()method and itsdeterminism()method to indicate the transitory or permanent presence or absence of any value it might supply - Throws:
NullPointerException- ifpathisnullClassCastException- if the implementation is implemented improperly- See Also:
- must not be
-
load
@OverridingDiscouraged default <U> Loader<U> load(Qualifiers<? extends String, ?> qualifiers, Type type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
qualifiers- the path'sQualifiers; must not benulltype- the path'sType; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- the path'sType; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- the path'sType; must not benullname- the name of the lastPath.Elementin thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- the path'sType; must not benullnames- the sequence of names forming thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- the path'sType; must not benullnames- the sequence of names forming thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(Qualifiers<? extends String, ?> qualifiers, org.microbean.type.JavaType.Token<U> type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
qualifiers- the path'sQualifiers; must not benulltype- aJavaType.Tokenrepresenting the path'sType; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aJavaType.Tokenrepresenting the path'sType; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(org.microbean.type.JavaType.Token<U> type, String name) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aJavaType.Tokenrepresenting the path'sType; must not benullname- the name of the lastPath.Elementin thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(org.microbean.type.JavaType.Token<U> type, String... names) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aJavaType.Tokenrepresenting the path'sType; must not benullnames- the sequence of names forming thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(org.microbean.type.JavaType.Token<U> type, List<? extends String> names) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aJavaType.Tokenrepresenting the path'sType; must not benullnames- the sequence of names forming thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(Qualifiers<? extends String, ?> qualifiers, Class<U> type) Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
qualifiers- the path'sQualifiers; must not benulltype- aClassserving as the path'sType; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aClassserving as the path'sType; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aClassserving as the path'sType; must not benullname- the name of the lastPath.Elementin thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aClassserving as the path'sType; must not benullnames- the sequence of names forming thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPathfrom the supplied arguments, calls theload(Path)method and returns its result.- Type Parameters:
U- the type of environmental objects the returnedLoaderwill supply- Parameters:
type- aClassserving as the path'sType; must not benullnames- the sequence of names forming thePath; must not benull- Returns:
- a
Loader - Throws:
NullPointerException- if any argument isnull- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
loaderFor
Returns an ancestralLoader, derived from and possibly identical to thisLoader, that is suitable for a transliterated and absolute version of the suppliedpath, particularly for cases where, during the execution of theload(Path)method, aLoadermust be supplied to some other class.The returned
Loadermust be one whosepath()method returns the longestPaththat is a parent of an absolute version of the (transliterated) suppliedpath. In many casesthiswill be returned.Typically only classes implementing this interface will need to call this method. Most users will have no need to call this method directly.
Overriding of this method is very strongly discouraged.
- Parameters:
path- thePathin question; must not benull- Returns:
- an ancestral
Loader, derived from and possibly identical to thisLoader, that is suitable for a transliterated and absolute version of the suppliedpath, particularly for cases where, during the execution of theload(Path)method, aLoadermust be supplied to some other class; nevernull - Throws:
NullPointerException- ifpathisnull- See Also:
- Idempotency:
- The default implementation of this method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- The default implementation of this method does not,
and its (discouraged) overrides must not, return
null. - Thread Safety:
- The default implementation of this method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
transliterate
Transliterates the supplied absolutePathinto some otherPath, whose meaning is the same, but whose representation may be different, that will be used instead.The
Paththat is returned may be thePaththat was supplied. This may happen, for example, if the path has already been transliterated, or if the path identifies a transliteration request.Path transliteration is needed because the
name()components ofPath.Elements may unintentionally clash when two components are combined into a single application.Path transliteration must occur during the execution of any implementation of the
load(Path)method, such that thePathsupplied to that method, once it has been verified to be absolute, is supplied to an implementation of this method. ThePathreturned by an implementation of this method must then be used during the rest of the invocation of theload(Path)method, as if it had been supplied in the first place.Behavior resulting from any other usage of an implementation of this method is undefined.
The default implementation of this method uses the configuration system itself to find a transliterated
Pathcorresponding to the suppliedPath, returning the suppliedpathitself if no transliteration can take place. Infinite loops are avoided except as noted below.Overrides of this method must not call
loaderFor(Path)or an infinite loop may result.Overrides of this method must not call
load(Path)with the suppliedpathor an infinite loop may result.An implementation of
Loaderwill findPath.transliterate(java.util.function.BiFunction)particularly useful in implementing this method.Most users will have no need to call this method directly.
- Type Parameters:
U- the type of the supplied and returnedPaths- Parameters:
path- an absolutePath; must not be null- Returns:
- the transliterated
Path; nevernull; possibly the suppliedpathitself - Throws:
NullPointerException- ifpathisnullIllegalArgumentException- ifpathreturnsfalsefrom itsabsolute()method- See Also:
- Idempotency:
- The default implementation of this method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- The default implementation of this method does not,
and its (discouraged) overrides must not, return
null. - Thread Safety:
- The default implementation of this method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
isRoot
Returnstrueif and only if thisLoaderis the rootLoader, which occurs only when the return value ofthis.parent() == this.Overrides of this method are strongly discouraged.
Most users will have no need to call this method directly.
-
root
Returns the rootLoader, which is theLoaderwhoseparent()method returns iteself.Overrides of this method are strongly discouraged.
Most users will have no need to call this method directly.
- Returns:
- the root
Loader - See Also:
- Idempotency:
- This method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
as
Casts thisLoaderappropriately and returns it, usually so that an implementation's implementation-specific methods can be accessed.- Type Parameters:
L- theLoadersubclass- Parameters:
loaderSubclass- aClassrepresenting a subclass ofLoader; must not benull- Returns:
- this
Loader - Throws:
NullPointerException- ifloaderSubclassisnullClassCastException- if the cast could not be performed- Idempotency:
- This method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
loader
Bootstraps and returns aLoader.If this method has been called before, its prior result is returned.
Otherwise, first, the root
Loaderis located using Java's built-inServiceLoader. The first of theLoaderinstances it discovers is used and all others are ignored. Note that theServiceLoaderdiscovery process is non-deterministic. Normally there is only one suchLoaderprovided by an implementation of this API.The root
Loaderthat is loaded via this mechanism is subject to the following restrictions:- It must return a
Pathfrom itspath()implementation that is equal toPath.root(). - It must return a
Pathfrom itsabsolutePath()implementation that is equal toPath.root(). - It must return itself (
this) from itsparent()implementation. - It must return
truefrom itsisRoot()implementation. - It must return itself (
this) from itsroot()method. - It must return
OptionalSupplier.Determinism.PRESENTfrom itsdeterminism()method. - It must return itself (
this) from itsget()method.
Next, this root
Loaderis used to find theLoaderof record, which in most cases is simply itself.The
Loaderof record is subject to the following restrictions (which are compatible with the overwhelmingly common case of its also being the rootLoader):- It must return a
Pathfrom itspath()implementation that is equal toPath.root()(same as above). - It must return a
Pathfrom itsabsolutePath()implementation that is equal toPath.root()(same as above). - It must return
OptionalSupplier.Determinism.PRESENTfrom itsdeterminism()method (same as above). - It must return the root
Loaderfrom itsparent()implementation (which may be itself (this)). - It must return a
Loaderimplementation, often itself (this), from itsget()method.
An
IllegalStateExceptionwill be thrown if an implementation of theLoaderinterface does not honor the requirements above.This method is the primary entry point for end users of this framework.
- Returns:
- a non-
nullLoaderthat can be used to acquire environmental objects that abides by the requirements and restrictions above - Throws:
IllegalStateException- if any of the requirements and restrictions above is violatedServiceConfigurationError- if the rootLoadercould not be loaded for any reasonNoClassDefFoundError- if the rootLoadercould not be loaded for any reason
- It must return a
-