Loader
seeks configured objects
by way of various Provider
s.- Author:
- Laird Nelson
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
compatible
(Path.Element<?> e1, Path.Element<?> e2) Returnstrue
if and only if the secondPath.Element
is compatible with respect to the firstPath.Element
.default <U> Value<U>
disambiguate
(Loader<?> requestor, Path<? extends Type> absolutePath, Provider p0, Value<U> v0, Provider p1, Value<U> v1) default void
providerRejected
(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider) Called to notify thisAmbiguityHandler
that aProvider
was discarded during the search for a configured object.default @org.microbean.development.annotation.Experimental int
Returns a score indicating the relative specificity ofvaluePath
with respect toabsoluteReferencePath
, orInteger.MIN_VALUE
ifvaluePath
is wholly unsuitable for further consideration or processing.default int
score
(Qualifiers<? extends String, ?> referenceQualifiers, Qualifiers<? extends String, ?> valueQualifiers) Returns a score indicating the relative specificity ofvalueQualifiers
with respect toreferenceQualifiers
, orInteger.MIN_VALUE
ifvalueQualifiers
is wholly unsuitable for further consideration or processing.default void
valueRejected
(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider, Value<?> value) Called to notify thisAmbiguityHandler
that aValue
provided by aProvider
was discarded during the search for a configured object.
-
Method Details
-
providerRejected
default void providerRejected(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider) Called to notify thisAmbiguityHandler
that aProvider
was discarded during the search for a configured object.The default implementation of this method does nothing.
- Parameters:
rejector
- theLoader
that rejected theProvider
; must not benull
absolutePath
- the absolutePath
for which a configured object is being sought; must not benull
provider
- the rejectedProvider
, which may benull
- Throws:
NullPointerException
- if eitherrejector
orabsolutePath
isnull
-
valueRejected
default void valueRejected(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider, Value<?> value) Called to notify thisAmbiguityHandler
that aValue
provided by aProvider
was discarded during the search for a configured object.The default implementation of this method does nothing.
- Parameters:
rejector
- theLoader
that rejected theProvider
; must not benull
absolutePath
- the absolutePath
for which a configured object is being sought; must not benull
provider
- theProvider
providing the rejected value; must not benull
value
- the rejectedValue
; must not benull
- Throws:
NullPointerException
- if any argument isnull
-
score
default int score(Qualifiers<? extends String, ?> referenceQualifiers, Qualifiers<? extends String, ?> valueQualifiers) Returns a score indicating the relative specificity ofvalueQualifiers
with respect toreferenceQualifiers
, orInteger.MIN_VALUE
ifvalueQualifiers
is wholly unsuitable for further consideration or processing.This is not a comparison method.
- Parameters:
referenceQualifiers
- theQualifiers
against which to score the suppliedvalueQualifiers
; must not benull
valueQualifiers
- theQualifiers
to score against the suppliedreferenceQualifiers
; must not benull
- Returns:
- a relative score for
valueQualifiers
with respect toreferenceQualifiers
; meaningless on its own unless it isInteger.MIN_VALUE
in which case the suppliedvalueQualifiers
will be treated as wholly unsuitable for further consideration or processing - Throws:
NullPointerException
- if either parameter isnull
- See Also:
- Idempotency:
- The default implementation of this method is, and its overrides must be, idempotent and deterministic. Specifically, the same score is and must be returned whenever this method is invoked with the same arguments.
- Thread Safety:
- The default implementation of this method is, and its overrides must be, safe for concurrent use by multiple threads.
-
score
@Experimental default @org.microbean.development.annotation.Experimental int score(Path<? extends Type> absoluteReferencePath, Path<? extends Type> valuePath) Returns a score indicating the relative specificity ofvaluePath
with respect toabsoluteReferencePath
, orInteger.MIN_VALUE
ifvaluePath
is wholly unsuitable for further consideration or processing.This is not a comparison method.
The following preconditions must hold or undefined behavior will result:
- Neither parameter's value may be
null
. absoluteReferencePath
must be absolutevaluePath
must be selectable with respect toabsoluteReferencePath
, where the definition of selectability is described below
For
valuePath
to "be selectable" with respect toabsoluteReferencePath
for the purposes of this method and for no other purpose,true
must be returned by a hypothetical invocation of code whose behavior is that of the following:absoluteReferencePath.endsWith(valuePath,
AmbiguityHandler::compatible
);If, during scoring,
valuePath
is found to be wholly unsuitable for further consideration or processing,Integer.MIN_VALUE
will be returned to indicate this. Overrides must follow suit or undefined behavior elsewhere in this framework will result.In the normal course of events, this method will be called after a call to
score(Qualifiers, Qualifiers)
, and so there is normally no need for an implementation of this method to consult aPath
's affiliatedQualifiers
.- Parameters:
absoluteReferencePath
- thePath
against which to score the suppliedvaluePath
; must not benull
; must adhere to the preconditions abovevaluePath
- thePath
to score against the suppliedabsoluteReferencePath
; must not benull
; must adhere to the preconditions above- Returns:
- a relative score for
valuePath
with respect toabsoluteReferencePath
; meaningless on its own unless it isInteger.MIN_VALUE
in which case the suppliedvaluePath
will be treated as wholly unsuitable for further consideration or processing - Throws:
NullPointerException
- if either parameter isnull
IllegalArgumentException
- if certain preconditions have been violated- See Also:
- Idempotency:
- The default implementation of this method is, and
its overrides must be, idempotent and deterministic.
Specifically, the same score is and must be returned whenever
this method is invoked with the same
Path
s. - Thread Safety:
- The default implementation of this method is, and its overrides must be, safe for concurrent use by multiple threads.
- Neither parameter's value may be
-
disambiguate
default <U> Value<U> disambiguate(Loader<?> requestor, Path<? extends Type> absolutePath, Provider p0, Value<U> v0, Provider p1, Value<U> v1) Given twoValue
s and some contextual objects, chooses one over the other and returns it, or synthesizes a newValue
and returns that, or indicates that disambiguation is impossible by returningnull
.- Type Parameters:
U
- the type of objects theValue
s in question can supply- Parameters:
requestor
- theLoader
currently seeking aValue
; must not benull
absolutePath
- an absolutePath
for which a value is being sought; must not benull
p0
- theProvider
that supplied the firstValue
; must not benull
; must not be equal top1
v0
- the firstValue
; must not benull
p1
- theProvider
that supplied the secondValue
; must not benull
; must not be equal top0
v1
- the secondValue
; must not benull
- Returns:
- the
Value
to use instead; ordinarily one of the two suppliedValue
s but may benull
to indicate that disambiguation was impossible, or an entirely differentValue
altogether - Throws:
NullPointerException
- if any argument isnull
- Idempotency:
- The default implementation of this method is, and its overrides must be, idempotent. The default implementation of this method is deterministic, but its overrides need not be.
- Nullability:
- The default implementation of this method and its
overrides may return
null
. - Thread Safety:
- The default implementation of this method is, and its overrides must be, safe for concurrent use by multiple threads.
-
compatible
Returnstrue
if and only if the secondPath.Element
is compatible with respect to the firstPath.Element
.This method returns
true
unless one of the following conditions holds:- Both elements' names are non-empty and are not equal
- One element's qualified is
null
but the other is not - An
element
's qualified is non-null
but not aType
- Both element's qualifieds are
Type
s, but the second element'sType
is not assignable to the first element'sType
- If the first element's qualifiers are not empty and the second element's qualifiers are not empty and the first element's qualifiers do not intersect with the second element's qualifiers
- Parameters:
e1
- the firstPath.Element
; must not benull
e2
- the secondPath.Element
; must not benull
- Returns:
true
if and only if the secondPath.Element
is compatible with the first- Throws:
NullPointerException
- if either argument isnull
- Idempotency:
- This method is idempotent and deterministic.
- Thread Safety:
- This method is safe for concurrent use by multiple threads.
-