@@ -1495,26 +1495,12 @@ This runtime exception +extends MonetaryException+ and is thrown whenever
14951495* a +Locale+ given cannot be resolved into a corresponding +CurrencyUnit+ instance. The unresolvable +Locale+ passed is
14961496 provided as a property on the exception as +public Locale getLocale();+.
14971497
1498- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1499- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1500- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1501- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1502- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1503- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1504- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1505- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1506- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1507- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1508- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1509- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1510- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1511-
15121498[[CurrencyConversion]]
15131499=== Currency Conversion
1514- Currency conversion is an important aspects when dealing with monetary amounts. Unfortunately currency conversion has
1500+ Currency conversion is an important aspect when dealing with monetary amounts. Unfortunately currency conversion has
15151501a great variety of how it is implemented. Whereas a web shop may base its logic on an API provided by a financial
1516- backend, that make explicit conversion even not necessary, in the financial industry, conversion is a very complex
1517- aspects , since
1502+ backend, that makes explicit conversion even not necessary, in the financial industry, conversion is a very complex
1503+ concern , since
15181504
15191505* conversion may be different based on the use case
15201506* conversion may be different based on the provider of the exchange rates
@@ -1523,51 +1509,69 @@ aspects, since
15231509* conversion rates are different related to the target timestamp
15241510
15251511Hereby this list is not complete. Different companies may have further requirements and aspects to be considered.
1512+ The API focuses on the common aspects of currency conversion such as:
1513+
1514+ * a source and a target currency
1515+ * an exchange rate
1516+ * providing conversion providers and having the possibiity to address and combine providers as needed.
1517+
1518+ Hereby currency conversion or the access of exchange rates can be parametrized with additional meta-data, similar
1519+ to other models defined by this JSR. This allows to enrich the basic model with whatever complexity is required,
1520+ hereby keeping the basic model as simple as possible.
15261521
15271522[[AccessingConversions]]
15281523==== Accessing Monetary Conversions
1529- The API defines a singleton accessor, called +MonetaryConversions+, which provides access to all different aspects
1530- related to currency conversion, such as
1524+ Similar to other areas of this JSR a +MonetaryConversions+ singleoton is defined , which provides access to all different
1525+ aspects related to currency conversion, such as
15311526
1532- * access to providers that offer conversion rates, modelled as +<<ExchangeRate>>+.
1533- * access to conversion operators (extending +MonetaryOperator+), that can be used with any +MonetaryAmount+ instances.
1527+ * access to providers that offer conversion rates, modelled as +<<ExchangeRateProviders, ExchangeRate>>+.
1528+ * access to conversion operators (+CurrencyConversion extends MonetaryOperator+), that can be used with any
1529+ +MonetaryAmount+ instances.
15341530* access to further information about the providers currently available.
15351531
1536- The following sections give an overview about the functionality in more detail. Similar to other singletons in this API
1537- the singleton is backed up by a +MonetaryConversionsSingletonSpi+ SPI to allow customized (contextual) implementation
1538- of the functionality defined. Refer to the SPI section in this document for more details.
1532+ The following sections give an overview about the functionality in more detail. Similar to other singletons also
1533+ +MonetaryConversions+ is backed up by a +MonetaryConversionsSingletonSpi+ SPI to allow customized (e.g. contextual)
1534+ implementation of the functionality defined. Refer to the << SPI>> section in this document for more details.
15391535
15401536==== Converting Amounts
1541- Basically converting of amounts is modelled by the +CurrencyConversion+ interface which + extends MonetaryOperator+,
1537+ Basically converting of amounts is modelled by the +CurrencyConversion+ interface which extends + MonetaryOperator+,
15421538hereby adding meta-data support, modelled by +ConversionContext+. Hereby a *conversion is always bound to a specific
1543- terminating (target) currency*. So basically a +MonetaryAmount+ can simply be converted by
1539+ terminating (target) currency*. So basically a +MonetaryAmount+ can simply be converted by passing a
1540+ +CurrencyConversion+ to the amount's +with(MonetaryOperator)+ method:
15441541
15451542[source,java]
15461543.Usage Sample Currency Conversion
15471544-------------------------------------------------------------------------------
15481545MonetaryAmount amount = ...;
1546+
1547+ // Get a default conversion to Swiss Franc
15491548CurrencyConversion conversion = MonetaryConversions.getConversion("CHF");
1549+
1550+ // Convert the amount
15501551MonetaryAmount amount2 = amount.with(conversion);
15511552-------------------------------------------------------------------------------
15521553
15531554Using a fluent API style this can be written even shorter as:
15541555
15551556[source,java]
1556- .Usage Sample Currency Conversion, using the fluent API
15571557-------------------------------------------------------------------------------
15581558MonetaryAmount amount2 = amount.with(MonetaryConversions.getConversion("CHF"));
15591559-------------------------------------------------------------------------------
15601560
1561- A +CurrencyConversion+ instance hereby also allows to extract the +ExchangeRate+ instances used:
1561+ A +CurrencyConversion+ instance hereby also allows to extract the concrete +ExchangeRate+ applied. This allows
1562+ further pass the +ExchangeRate+ instance to any subsequent logic.
15621563
15631564[source,java]
1564- .Usage Sample Currency Conversion, accessing exchange rates
1565+ .Currency Conversion, accessing exchange rates
15651566-------------------------------------------------------------------------------
15661567CurrencyConversion conversion = MonetaryConversions.getConversion("CHF");
15671568MonetaryAmount amount = ...;
15681569ExchangeRate rate = conversion.getExchangeRate(amount);
15691570-------------------------------------------------------------------------------
15701571
1572+ Nevertheless for accessing +ExchangeRate+ instances an +ExchangeRateProvider+ is much more effective. It can be accessed
1573+ from the +MonetaryConversions+ singletons as well as from a +CurrencyConversion+.
1574+
15711575[[ExchangeRates]]
15721576==== Exchange Rates and Rate Providers
15731577===== Exchange Rates
@@ -1586,11 +1590,11 @@ Summarizing an +ExchangeRate+ is modelled as follows:
15861590[source,java]
15871591.Interface ExchangeRate
15881592-------------------------------------------------------------------------------
1589- public interface ExchangeRate{
1593+ public interface ExchangeRate extends CurrencySupplier {
15901594 ...
15911595 ConversionContext getConversionContext();
1592- CurrencyUnit getBase ();
1593- CurrencyUnit getTerm ();
1596+ CurrencyUnit getBaseCurrency ();
1597+ CurrencyUnit getCurrency ();
15941598 NumberValue getFactor();
15951599 // Support for chained rates
15961600 List<ExchangeRate> getExchangeRateChain();
@@ -1600,7 +1604,7 @@ public interface ExchangeRate{
16001604
16011605Hereby
16021606
1603- * +getBase (), getTerm (), getFactor()+ model basically the mapping from the base currency to the target currency.
1607+ * +getBaseCurrency (), getCurrency (), getFactor()+ model basically the mapping from the base currency to the target currency.
16041608* +isDerived()+ allows to check if the mapping in fact is backed up by a derived mapping, e.g. a triangular rate chain.
16051609* +getExchangeRateChain()+ return the full rate chain. In case of a non derived rate, this chain must contain only
16061610 the single rate itself. In case of triangular rate the chain contains all contained subrates.
@@ -1624,8 +1628,8 @@ Implementations of +ExchangeRate+
16241628. should be implemented as value types, with a fluent Builder pattern.
16251629
16261630===== Exchange Rate Providers
1627- We have seen in the previous section that an +ExchangeRate+ can be obtained from a +CurrencyConversion+. Hereby a
1628- currency conversion is backed up by an +ExchangeRateProvider+. Such a provider allows
1631+ We have seen in the previous section that an +ExchangeRate+ can be obtained from a +CurrencyConversion+ or from
1632+ its backing +ExchangeRateProvider+. Such a provider allows
16291633
16301634* to access +ExchangeRate+ instances, providing a base and a terminating (target) currency.
16311635* to access +CurrencyConversion+ instances, providing a terminating (target) currency.
@@ -1637,20 +1641,20 @@ Summarizing an +ExchangeRateProvider+ is modelled as follows:
16371641-------------------------------------------------------------------------------
16381642public interface ExchangeRateProvider{
16391643 ProviderContext getProviderContext();
1640- boolean isAvailable(CurrencyUnit base, CurrencyUnit term, ConversionContext conversionContext);
1641- ExchangeRate getExchangeRate(CurrencyUnit base, CurrencyUnit term, ConversionContext conversionContext );
1642- CurrencyConversion getCurrencyConversion(CurrencyUnit term, ConversionContext conversionContext );
1643-
1644- default boolean isAvailable(CurrencyUnit base, CurrencyUnit term){...}
1645- default boolean isAvailable(String baseCode, String termCode){...}
1646- default boolean isAvailable(String baseCode, String termCode, ConversionContext conversionContext){...}
1647- default ExchangeRate getExchangeRate(CurrencyUnit base, CurrencyUnit term){...}
1648- default ExchangeRate getExchangeRate(String baseCode, String termCode){...}
1649- default ExchangeRate getExchangeRate(String baseCode, String termCode, ConversionContext conversionContext){...}
1650- default ExchangeRate getReversed(ExchangeRate rate){...}
1651- default CurrencyConversion getCurrencyConversion(CurrencyUnit term){...}
1652- default CurrencyConversion getCurrencyConversion(String termCode){...}
1653- default CurrencyConversion getCurrencyConversion(String termCode, ConversionContext conversionContext){...}
1644+
1645+ boolean isAvailable(ConversionQuery conversionQuery );
1646+ ExchangeRate getExchangeRate(ConversionQuery conversionQuery );
1647+ CurrencyConversion getCurrencyConversion(ConversionQuery conversionQuery);
1648+
1649+ default boolean isAvailable(CurrencyUnit base, CurrencyUnit term);
1650+ default boolean isAvailable(String baseCode, String termCode);
1651+ default ExchangeRate getExchangeRate(CurrencyUnit base, CurrencyUnit term);
1652+ default ExchangeRate getExchangeRate(String baseCode, String termCode);
1653+ default CurrencyConversion getCurrencyConversion(CurrencyUnit term);
1654+ default CurrencyConversion getCurrencyConversion(String termCode);
1655+
1656+ default ExchangeRate getReversed(ExchangeRate rate);
1657+
16541658}
16551659-------------------------------------------------------------------------------
16561660
@@ -1664,6 +1668,24 @@ Hereby
16641668* the +getCurrencyConversion+ methods allow to access a +CurrencyConversion+ that is internally backed up by the
16651669 given rate provider instance.
16661670
1671+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1672+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1673+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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%%%%%%%%%%%%%%%%%%%%
1682+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1683+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1684+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1685+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1686+
1687+
1688+
16671689===== Conversion Context
16681690The API allows additionally to pass a +ConversionContext+, which allow to pass any additional attributes/parameters
16691691that may be required by a concrete +ExchangeRateProvider+ instance. This allows to support arbitrary complex use cases,
0 commit comments