Loader seeks configured objects
by way of various Providers.- Author:
- Laird Nelson
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancompatible(Path.Element<?> e1, Path.Element<?> e2) Returnstrueif and only if the secondPath.Elementis 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 voidproviderRejected(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider) Called to notify thisAmbiguityHandlerthat aProviderwas discarded during the search for a configured object.default @org.microbean.development.annotation.Experimental intReturns a score indicating the relative specificity ofvaluePathwith respect toabsoluteReferencePath, orInteger.MIN_VALUEifvaluePathis wholly unsuitable for further consideration or processing.default intscore(Qualifiers<? extends String, ?> referenceQualifiers, Qualifiers<? extends String, ?> valueQualifiers) Returns a score indicating the relative specificity ofvalueQualifierswith respect toreferenceQualifiers, orInteger.MIN_VALUEifvalueQualifiersis wholly unsuitable for further consideration or processing.default voidvalueRejected(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider, Value<?> value) Called to notify thisAmbiguityHandlerthat aValueprovided by aProviderwas 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 thisAmbiguityHandlerthat aProviderwas discarded during the search for a configured object.The default implementation of this method does nothing.
- Parameters:
rejector- theLoaderthat rejected theProvider; must not benullabsolutePath- the absolutePathfor which a configured object is being sought; must not benullprovider- the rejectedProvider, which may benull- Throws:
NullPointerException- if eitherrejectororabsolutePathisnull
-
valueRejected
default void valueRejected(Loader<?> rejector, Path<? extends Type> absolutePath, Provider provider, Value<?> value) Called to notify thisAmbiguityHandlerthat aValueprovided by aProviderwas discarded during the search for a configured object.The default implementation of this method does nothing.
- Parameters:
rejector- theLoaderthat rejected theProvider; must not benullabsolutePath- the absolutePathfor which a configured object is being sought; must not benullprovider- theProviderproviding the rejected value; must not benullvalue- 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 ofvalueQualifierswith respect toreferenceQualifiers, orInteger.MIN_VALUEifvalueQualifiersis wholly unsuitable for further consideration or processing.This is not a comparison method.
- Parameters:
referenceQualifiers- theQualifiersagainst which to score the suppliedvalueQualifiers; must not benullvalueQualifiers- theQualifiersto score against the suppliedreferenceQualifiers; must not benull- Returns:
- a relative score for
valueQualifierswith respect toreferenceQualifiers; meaningless on its own unless it isInteger.MIN_VALUEin which case the suppliedvalueQualifierswill 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 ofvaluePathwith respect toabsoluteReferencePath, orInteger.MIN_VALUEifvaluePathis 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. absoluteReferencePathmust be absolutevaluePathmust be selectable with respect toabsoluteReferencePath, where the definition of selectability is described below
For
valuePathto "be selectable" with respect toabsoluteReferencePathfor the purposes of this method and for no other purpose,truemust be returned by a hypothetical invocation of code whose behavior is that of the following:absoluteReferencePath.endsWith(valuePath,
AmbiguityHandler::compatible);If, during scoring,
valuePathis found to be wholly unsuitable for further consideration or processing,Integer.MIN_VALUEwill 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- thePathagainst which to score the suppliedvaluePath; must not benull; must adhere to the preconditions abovevaluePath- thePathto score against the suppliedabsoluteReferencePath; must not benull; must adhere to the preconditions above- Returns:
- a relative score for
valuePathwith respect toabsoluteReferencePath; meaningless on its own unless it isInteger.MIN_VALUEin which case the suppliedvaluePathwill be treated as wholly unsuitable for further consideration or processing - Throws:
NullPointerException- if either parameter isnullIllegalArgumentException- 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
Paths. - 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 twoValues and some contextual objects, chooses one over the other and returns it, or synthesizes a newValueand returns that, or indicates that disambiguation is impossible by returningnull.- Type Parameters:
U- the type of objects theValues in question can supply- Parameters:
requestor- theLoadercurrently seeking aValue; must not benullabsolutePath- an absolutePathfor which a value is being sought; must not benullp0- theProviderthat supplied the firstValue; must not benull; must not be equal top1v0- the firstValue; must not benullp1- theProviderthat supplied the secondValue; must not benull; must not be equal top0v1- the secondValue; must not benull- Returns:
- the
Valueto use instead; ordinarily one of the two suppliedValues but may benullto indicate that disambiguation was impossible, or an entirely differentValuealtogether - 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
Returnstrueif and only if the secondPath.Elementis compatible with respect to the firstPath.Element.This method returns
trueunless one of the following conditions holds:- Both elements' names are non-empty and are not equal
- One element's qualified is
nullbut the other is not - An
element's qualified is non-nullbut not aType - Both element's qualifieds are
Types, but the second element'sTypeis 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 benulle2- the secondPath.Element; must not benull- Returns:
trueif and only if the secondPath.Elementis 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.
-