public interface MonetaryAmountsSingletonQuerySpi
SPI (core) for the backing implementation of the
Monetary
singleton, implementing
the query functionality for amounts.- Author:
- Anatole Tresch
-
Method Summary
Modifier and Type Method Description java.util.Collection<MonetaryAmountFactory<? extends MonetaryAmount>>
getAmountFactories(MonetaryAmountFactoryQuery query)
Get theMonetaryAmountFactory
implementation class, that best matches to cover the givenMonetaryContext
.default MonetaryAmountFactory
getAmountFactory(MonetaryAmountFactoryQuery query)
Executes the query and returns theMonetaryAmountFactory
implementation type found, if there is only one type.default java.lang.Class<? extends MonetaryAmount>
getAmountType(MonetaryAmountFactoryQuery query)
Executes the query and returns theMonetaryAmount
implementation type found, if there is only one type.default java.util.Collection<java.lang.Class<? extends MonetaryAmount>>
getAmountTypes(MonetaryAmountFactoryQuery query)
Executes the query and returns theMonetaryAmount
implementation types found.default boolean
isAvailable(MonetaryAmountFactoryQuery query)
Checks if anMonetaryAmountFactory
is matching the given query.
-
Method Details
-
getAmountFactories
java.util.Collection<MonetaryAmountFactory<? extends MonetaryAmount>> getAmountFactories(MonetaryAmountFactoryQuery query)Get theMonetaryAmountFactory
implementation class, that best matches to cover the givenMonetaryContext
.The evaluation order should consider the following aspects:
- If
MonetaryContext.getAmountType()
is explicitly defined, it should be considered. Nevertheless if precision/scale cannot be met, aMonetaryException
should be thrown. - The remaining implementation class candidates must cover the required precision.
- The remaining implementation class candidates must cover the required max scale.
- If max scale is met, but
precision==0
(unlimited precision), theMonetaryAmount
implementation candidate should be chosen with highest possible precision. - If still multiple implementation candidates qualify, the ones with
Flavor.PERFORMANCE
are preferred. - After this point the selection may be arbitrary.
- Parameters:
query
- the factory query, not null.- Returns:
- the
MonetaryAmount
implementation class, that best matches to cover the givenMonetaryContext
, nevernull
. - Throws:
MonetaryException
- if noMonetaryAmount
implementation class can cover the requiredMonetaryContext
.
- If
-
isAvailable
Checks if anMonetaryAmountFactory
is matching the given query.- Parameters:
query
- the factory query, not null.- Returns:
- true, if at least one
MonetaryAmountFactory
matches the query.
-
getAmountType
Executes the query and returns theMonetaryAmount
implementation type found, if there is only one type. If multiple types match the query, the first one is selected.- Parameters:
query
- the factory query, not null.- Returns:
- the type found, or null.
-
getAmountTypes
default java.util.Collection<java.lang.Class<? extends MonetaryAmount>> getAmountTypes(MonetaryAmountFactoryQuery query)Executes the query and returns theMonetaryAmount
implementation types found.- Parameters:
query
- the factory query, not null.- Returns:
- the type found, or null.
-
getAmountFactory
Executes the query and returns theMonetaryAmountFactory
implementation type found, if there is only one type. If multiple types match the query, the first one is selected.- Parameters:
query
- the factory query, not null.- Returns:
- the type found, or null.
-