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 theMonetaryAmountFactoryimplementation class, that best matches to cover the givenMonetaryContext.default MonetaryAmountFactorygetAmountFactory(MonetaryAmountFactoryQuery query)Executes the query and returns theMonetaryAmountFactoryimplementation type found, if there is only one type.default java.lang.Class<? extends MonetaryAmount>getAmountType(MonetaryAmountFactoryQuery query)Executes the query and returns theMonetaryAmountimplementation 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 theMonetaryAmountimplementation types found.default booleanisAvailable(MonetaryAmountFactoryQuery query)Checks if anMonetaryAmountFactoryis matching the given query.
-
Method Details
-
getAmountFactories
java.util.Collection<MonetaryAmountFactory<? extends MonetaryAmount>> getAmountFactories(MonetaryAmountFactoryQuery query)Get theMonetaryAmountFactoryimplementation 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, aMonetaryExceptionshould 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), theMonetaryAmountimplementation candidate should be chosen with highest possible precision. - If still multiple implementation candidates qualify, the ones with
Flavor.PERFORMANCEare preferred. - After this point the selection may be arbitrary.
- Parameters:
query- the factory query, not null.- Returns:
- the
MonetaryAmountimplementation class, that best matches to cover the givenMonetaryContext, nevernull. - Throws:
MonetaryException- if noMonetaryAmountimplementation class can cover the requiredMonetaryContext.
- If
-
isAvailable
Checks if anMonetaryAmountFactoryis matching the given query.- Parameters:
query- the factory query, not null.- Returns:
- true, if at least one
MonetaryAmountFactorymatches the query.
-
getAmountType
Executes the query and returns theMonetaryAmountimplementation 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 theMonetaryAmountimplementation types found.- Parameters:
query- the factory query, not null.- Returns:
- the type found, or null.
-
getAmountFactory
Executes the query and returns theMonetaryAmountFactoryimplementation 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.
-