Skip to content
This repository was archived by the owner on Jun 27, 2021. It is now read-only.

Commit 9006f95

Browse files
committed
Renamed methods similar to Java 8 version.
1 parent 4d8089d commit 9006f95

File tree

6 files changed

+99
-76
lines changed

6 files changed

+99
-76
lines changed

UserGuide.adoc

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Java Money and Currency API -- Backport for Java 7
22
==================================================
3-
:title: Java Money and Currency API -- Backport for Java 7
4-
:revnumber: 1.0-RC1
5-
:revdate: March 2015
6-
:longversion: 1.0-RC1 March 2015
3+
:title: Java Money and Currency API for Java 7
4+
:revnumber: 1.0
5+
:revdate: April 2015
6+
:longversion: 1.0 April 2015
77
:authorinitials: ATR
88
:author: Anatole Tresch, Credit Suisse
99
@@ -25,10 +25,10 @@ image::https://raw.githubusercontent.com/JavaMoney/jsr354-api/master/src/main/as
2525

2626
==== Version Information:
2727
------------------------------------------------------------------
28-
Specification: Java Money and Currency API -- Backport for Java 7
29-
Version: 1.0-RC1
30-
Status: Prerelease
31-
Release Date: March 2015
28+
Specification: Java Money and Currency API for Java 7
29+
Version: 1.0
30+
Status: Release
31+
Release Date: April 2015
3232
Copyright: 2012-2015
3333
Credit Suisse AG
3434
P.O.Box
@@ -46,25 +46,18 @@ toc::[]
4646
<<<
4747

4848
== Introduction
49-
This document is the user guide of the Java API for Money and Currency Backport of JSR 354. The technical objective is
49+
This document is the user guide of the Java API for Money and Currency of JSR 354 targeting Java 7. The technical objective is
5050
to provide a money and currency API for Java, targeted at all users of currencies and monetary amounts, compatible
5151
with Android and Java 7.
5252
The API will provide support for standard [ISO-4217] and custom currencies, and a model for monetary amounts and
5353
rounding. It will have extension points for adding additional features like currency exchange, financial calculations
5454
and formulas. For detailed information on the API and its usage, we recommend reading the JSR's specification, which can
5555
be downloaded from the JCP page http://jcp.org/en/jsr/detail?id=35[JSR 354 on jcp.org .
5656

57-
Basically the specification of JSR 354 can be used as documentation base, if you want to have some introduction how
58-
to use this library. Hereby you must map the following packages:
59-
60-
* org.javamoney.bp.api -> org.javamoney.bp
61-
* org.javamoney.bp.api.spi -> org.javamoney.bp.spi
62-
* org.javamoney.bp.api.convert -> org.javamoney.bp.convert
63-
* org.javamoney.bp.api.format -> org.javamoney.bp.format
64-
65-
Additionally this library provides a package +org.javamoney.bp.spi.base+, which contains abstract classes that
66-
contain the logic included as _default_ methods in the JSR 354 API. So basically, when you have code based on
67-
JSR 354 Java 8 API as follows:
57+
The APIs for both Java 7 and Java 8 are basically the same. Java 8 additionally provides full support for _default
58+
methods_, which adds lots of comfort implementing the SPIs. For Java 7 users the reference implementation provides
59+
a set of common base classes, that provide the same functionality as provided by default methods in the Java 8 version
60+
of the API:
6861

6962
[source,java]
7063
----------------------------------------------------------------------
@@ -88,31 +81,32 @@ public class MyImplClass extends BaseCurrencyProviderSpi{
8881
[[ProjectStructure]]
8982
== Package and Project Structure
9083
==== Package Overview
91-
Similar to JSR 354 the backport defines the following 4 main packages:
84+
Similar to JSR 354 Java 8 API this the Java 7 API defines 4 main packages:
9285

93-
+org.javamoney.bp.api+:: contains the main artifacts, such as +CurrencyUnit, MonetaryAmount, MonetaryContext, MonetaryOperator,
94-
MonetaryQuery, MonetaryRounding+, and the singleton accessors +MonetaryCurrencies, MonetaryAmounts, MonetaryRoundings+.
86+
+javax.money+:: contains the main artifacts, such as +CurrencyUnit, MonetaryAmount, MonetaryContext, MonetaryOperator,
87+
MonetaryQuery, MonetaryRounding+, and the singleton accessor +Monetary+.
9588

96-
+org.javamoney.bp.api.conversion+:: contains the conversion artifacts +ExchangeRate, ExchangeRateProvider, CurrencyConversion+
89+
+javax.money.conversion+:: contains the conversion artifacts +ExchangeRate, ExchangeRateProvider, CurrencyConversion+
9790
and the according +MonetaryConversions+ accessor singleton.
9891

99-
+org.javamoney.bp.api.format+:: contains the formatting artifacts +MonetaryAmountFormat, AmountFormatContext+ and the according
92+
+javax.money.format+:: contains the formatting artifacts +MonetaryAmountFormat, AmountFormatContext+ and the according
10093
+MonetaryFormats+ accessor singleton.
10194

102-
+org.javamoney.bp.api.spi+:: contains the SPI interfaces provided by the JSR 354 API and the bootstrap logic, to support
95+
+javax.money.spi+:: contains the SPI interfaces provided by the JSR 354 API and the bootstrap logic, to support
10396
different runtime environments and component loading mechanisms.
10497

10598

10699
[[Modules]]
107100
==== Module/Repository Overview
108101
The JSR’s source code repository under <<source>> provides several modules:
109102

110-
javamoney-api-bp:: contains the API backport for use with Java 7.
111-
javamoney-moneta-bp:: contains the ''moneta'' implementation, based on Java 7.
103+
jsr354-api-bp:: contains the API backport compatible with Java g and 7.
104+
jsr354-ri-bp:: contains the ''moneta'' implementation, based on Java 7.
112105
jsr354-api:: contains the JSR 354 API for use with Java 8. We highly recommend using this version, if possible, to
113106
benefit from the power of Java 8.
114107
jsr354-ri:: contains the ''moneta'' reference implementation, based on Java 8.
115-
jsr354-tck:: contains the technical compatibility kit (TCK) of the JSR, requiring as well Java 8.
108+
jsr354-tck:: contains the technical compatibility kit (TCK) of the JSR, requiring as well Java 7. The TCK is the same
109+
for Java 7 and Java 8.
116110
javamoney-parent:: is a root “POM” project for all modules under +org.javamoney+. This includes the RI/TCK projects,
117111
but not jsr354-api and javamoney-api-bp (which are standalone).
118112
javamoney-library:: contains a financial library (JavaMoney) adding comprehensive support for several extended
@@ -121,14 +115,14 @@ javamoney-examples:: finally contains the examples and demos, and also is not pa
121115

122116

123117
== Examples
124-
The following sections illustrate the backport's API usage in more detail.
118+
The following sections illustrate the API usage in more detail.
125119

126-
=== Working with org.javamoney.moneta.bp.Money
127-
The Javamoney backport implementation of JSR 354 has to provide value type classes for monetary amounts, hereby implementing
128-
+org.javamoney.moneta.bp.api.MonetaryAmount+, and registering at least one implementation class with the +org.javamoney.moneta.bp.api.MonetaryAmounts+ singleton by
129-
implementing and registering a corresponding +org.javamoney.moneta.bp.api.MonetayAmountFactory+ instance.
120+
=== Working with javax.money.Money
121+
The Java 7 based implementation of JSR 354 has to provide value type classes for monetary amounts, hereby implementing
122+
+javax.money.MonetaryAmount+, and registering at least one implementation class with the +javax.money.Monetary+
123+
singleton by implementing and registering a corresponding +javax.money.MonetayAmountFactory+ instance.
130124

131-
As an example the reference implementation provides a class +org.javamoney.moneta.bp.Money+, which is using
125+
As an example the reference implementation provides a class +org.javamoney.moneta.Money+, which is using
132126
+java.math.BigDecimal+ internally:
133127

134128
[source,java]
@@ -246,7 +240,7 @@ Below is a rather academical example of a +MonetaryOperator+ that simply convert
246240
the same numeric value, but with XXX (undefined) as currency:
247241

248242
[source,java]
249-
.Simple example of a +MonetaryOperstor+ using the +MonetaryAmountFactory+ provided.
243+
.Simple example of a +MonetaryOperator+ using the +MonetaryAmountFactory+ provided.
250244
-------------------------------------------------------------------------------
251245
public final class ToInvalid implements MonetaryOperator{
252246
public <T extends MonetaryAmount> T apply(T amount){
@@ -495,23 +489,3 @@ Public Source Code Repository on GitHub: http://github.com/JavaMoney,
495489
* http://java.net/projects/javamoney/[JavaMoney Project on Java.net]
496490
** https://github.com/JavaMoney[JSR 354 API GitHub Repository]
497491
** https://github.com/JavaMoney/jsr354-ro[Moneta RI GitHub Repository]
498-
* http://www.javapractices.com/topic/TopicAction.do?Id=13[Java Practices about Representing Money]
499-
* http://blog.eisele.net/2011/08/working-with-money-in-java.html[Working with Money in Java]
500-
* http://mindprod.com/jgloss/currency.html[Java currency] by Roedy Green, http://mindprod.com[Canadian Mind Products]
501-
* http://www.eclipse.org/uomo/[UOMo Business], based on ICU4J and concepts by JScience Economics]
502-
* http://site.icu-project.org/[ICU4J] Uses Number for all operations and internal storage in its Money type.
503-
* http://moneydance.com/dev/apidoc/[MoneyDance API]
504-
* http://javamoney.org[JavaMoney] is the Apache 2.0 licensed OSS project that evolved from JSR 354 development. It provides concrete implementations for currency conversion and mapping, advanced formatting, historic data access, regions and a set of financial calculations and formulas.
505-
* http://www.joda.org/joda-money[Joda Money] can be referred to as an inspiration for API and design style. it is based on real-world use cases in an e-commerce application for airlines
506-
* http://grails.org/plugin/currencies[Grails Currencies] uses BigDecimal as internal representation, but API only exposes Number in all Money operations like plus(), minus() or similar.
507-
* http://lemnik.wordpress.com/2011/03/25/bigdecimal-and-your-money/[Why not to use BigDecimal for Money]
508-
* http://de.wikipedia.org/wiki/M-Pesa[M-Pesa-Mobile Money] in Africa
509-
* Currency Internationalization (i18n), Multiple Currencies and Foreign Exchange (FX).
510-
* http://en.wikipedia.org/wiki/Japanese_units_of_measurement#Money: Discussion of internationalization of currencies, rounding, grouping and formatting, separators etc]
511-
* http://speleotrove.com/decimal/
512-
* http://sourceforge.net/projects/oquote/
513-
* http://en.wikipedia.org/wiki/Karatsuba_algorithm[Karatsuba Algorithm] for Fast Big Decimal Multiplication
514-
515-
=== Related Initiatives
516-
* http://timeandmoney.sourceforge.net/ [Eric Evans Time and Money Library]
517-
* http://bitcoinj.github.io/ [Bitcoin Java Client]

pom.xml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
</roles>
104104
</developer>
105105
<developer>
106-
<id>-</id>
106+
<id>simasch</id>
107107
<name>Simon Martinelli</name>
108108
<roles>
109109
<role>Expert Group Member</role>
@@ -132,6 +132,55 @@
132132
<role>Expert Group Member</role>
133133
</roles>
134134
</developer>
135+
<developer>
136+
<id>-</id>
137+
<name>Scot James</name>
138+
<roles>
139+
<role>Expert Group Member</role>
140+
</roles>
141+
</developer>
142+
<developer>
143+
<id>-</id>
144+
<name>Matthias Buecker</name>
145+
<roles>
146+
<role>Expert Group Member</role>
147+
</roles>
148+
</developer>
149+
<developer>
150+
<id>-</id>
151+
<name>Sanjay Nagpal</name>
152+
<roles>
153+
<role>Expert Group Member</role>
154+
</roles>
155+
</developer>
156+
<developer>
157+
<id>keilw</id>
158+
<name>Werner Keil</name>
159+
<roles>
160+
<role>Expert Group Member</role>
161+
</roles>
162+
</developer>
163+
<developer>
164+
<id>crazybob</id>
165+
<name>Bob Lee</name>
166+
<roles>
167+
<role>Expert Group Member</role>
168+
</roles>
169+
</developer>
170+
<developer>
171+
<id>crazybob</id>
172+
<name>Bob Lee</name>
173+
<roles>
174+
<role>Expert Group Member</role>
175+
</roles>
176+
</developer>
177+
<developer>
178+
<id>-</id>
179+
<name>Arumugam Swaminathan</name>
180+
<roles>
181+
<role>Expert Group Member</role>
182+
</roles>
183+
</developer>
135184
</developers>
136185

137186
<ciManagement>

src/main/java/javax/money/convert/MonetaryConversions.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private MonetaryConversions(){
7070

7171
/**
7272
* Access an instance of {@link CurrencyConversion} for the given providers.
73-
* Use {@link #getProviderNames()} to check, which are available.
73+
* Use {@link #getConversionProviderNames()} to check, which are available.
7474
*
7575
* @param termCurrency the terminating or target currency, not {@code null}
7676
* @param providers Additional providers, for building a provider chain
@@ -82,7 +82,7 @@ public static CurrencyConversion getConversion(CurrencyUnit termCurrency, String
8282
Objects.requireNonNull(termCurrency);
8383
if(providers.length == 0){
8484
return MONETARY_CONVERSION_SPI.getConversion(
85-
ConversionQueryBuilder.of().setTermCurrency(termCurrency).setProviderNames(getDefaultProviderChain())
85+
ConversionQueryBuilder.of().setTermCurrency(termCurrency).setProviderNames(getDefaultConversionProviderChain())
8686
.build());
8787
}
8888
return MONETARY_CONVERSION_SPI.getConversion(
@@ -91,7 +91,7 @@ public static CurrencyConversion getConversion(CurrencyUnit termCurrency, String
9191

9292
/**
9393
* Access an instance of {@link CurrencyConversion} for the given providers.
94-
* Use {@link #getProviderNames()}} to check, which are available.
94+
* Use {@link #getConversionProviderNames()}} to check, which are available.
9595
*
9696
* @param termCurrencyCode the terminating or target currency code, not {@code null}
9797
* @param providers Additional providers, for building a provider chain
@@ -106,7 +106,7 @@ public static CurrencyConversion getConversion(String termCurrencyCode, String..
106106

107107
/**
108108
* Access an instance of {@link CurrencyConversion} for the given providers.
109-
* Use {@link #getProviderNames()}} to check, which are available.
109+
* Use {@link #getConversionProviderNames()}} to check, which are available.
110110
*
111111
* @param conversionQuery The {@link ConversionQuery} required, not {@code null}
112112
* @return the {@link CurrencyConversion} instance matching.
@@ -167,15 +167,15 @@ public static boolean isConversionAvailable(CurrencyUnit termCurrency, String...
167167

168168
/**
169169
* Access an instance of {@link CurrencyConversion} using the given
170-
* providers as a provider chain. Use {@link #getProviderNames()}s
170+
* providers as a provider chain. Use {@link #getConversionProviderNames()}s
171171
* to check, which are available.
172172
*
173173
* @return the exchange rate provider.
174174
* @throws IllegalArgumentException if no such {@link ExchangeRateProvider} is available.
175175
*/
176176
public static ExchangeRateProvider getExchangeRateProvider(String... providers){
177177
if(providers.length == 0){
178-
List<String> defaultProviderChain = getDefaultProviderChain();
178+
List<String> defaultProviderChain = getDefaultConversionProviderChain();
179179
return MONETARY_CONVERSION_SPI.getExchangeRateProvider(ConversionQueryBuilder.of().setProviderNames(
180180
defaultProviderChain.toArray(new String[defaultProviderChain.size()])).build());
181181
}
@@ -216,7 +216,7 @@ public static ExchangeRateProvider getExchangeRateProvider(
216216
}
217217
/**
218218
* Access an instance of {@link CurrencyConversion} using the given
219-
* providers as a provider chain. Use {@link #getProviderNames()}
219+
* providers as a provider chain. Use {@link #getConversionProviderNames()}
220220
* to check, which are available.
221221
*
222222
* @return the exchange rate provider.
@@ -252,7 +252,7 @@ public static boolean isExchangeRateProviderAvailable(ConversionQuery conversion
252252
*
253253
* @return all supported provider ids, never {@code null}.
254254
*/
255-
public static Collection<String> getProviderNames(){
255+
public static Collection<String> getConversionProviderNames(){
256256
if(MONETARY_CONVERSION_SPI==null){
257257
throw new MonetaryException(
258258
"No MonetaryConveresionsSingletonSpi " + "loaded, query functionality is not available.");
@@ -265,7 +265,7 @@ public static Collection<String> getProviderNames(){
265265
*
266266
* @return the default provider, never {@code null}.
267267
*/
268-
public static List<String> getDefaultProviderChain(){
268+
public static List<String> getDefaultConversionProviderChain(){
269269
if(MONETARY_CONVERSION_SPI==null){
270270
throw new MonetaryException(
271271
"No MonetaryConveresionsSingletonSpi " + "loaded, query functionality is not available.");

src/main/java/javax/money/format/MonetaryFormats.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public static Set<Locale> getAvailableLocales(String... providers) {
167167
*
168168
* @return the provider names, never null.
169169
*/
170-
public static Collection<String> getProviderNames() {
170+
public static Collection<String> getFormatProviderNames() {
171171
if(monetaryFormatsSingletonSpi==null){
172172
throw new MonetaryException(
173173
"No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.");
@@ -180,7 +180,7 @@ public static Collection<String> getProviderNames() {
180180
*
181181
* @return the default provider chain, never null.
182182
*/
183-
public static List<String> getDefaultProviderChain() {
183+
public static List<String> getDefaultFormatProviderChain() {
184184
if(monetaryFormatsSingletonSpi==null){
185185
throw new MonetaryException(
186186
"No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.");

src/test/java/javax/money/convert/MonetaryConversionsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public void testGetExchangeRateProvider_Invalid() throws Exception {
106106

107107
@Test
108108
public void testGetProviderNames() throws Exception {
109-
assertNotNull(MonetaryConversions.getProviderNames());
110-
assertTrue(MonetaryConversions.getProviderNames().contains("test"));
111-
assertTrue(MonetaryConversions.getProviderNames().size() == 1);
109+
assertNotNull(MonetaryConversions.getConversionProviderNames());
110+
assertTrue(MonetaryConversions.getConversionProviderNames().contains("test"));
111+
assertTrue(MonetaryConversions.getConversionProviderNames().size() == 1);
112112
}
113113

114114
@Test
115115
public void testGetDefaultProviderChain() throws Exception {
116-
assertNotNull(MonetaryConversions.getDefaultProviderChain());
117-
assertFalse(MonetaryConversions.getDefaultProviderChain().isEmpty());
118-
assertEquals(1, MonetaryConversions.getDefaultProviderChain().size());
116+
assertNotNull(MonetaryConversions.getDefaultConversionProviderChain());
117+
assertFalse(MonetaryConversions.getDefaultConversionProviderChain().isEmpty());
118+
assertEquals(1, MonetaryConversions.getDefaultConversionProviderChain().size());
119119
}
120120
}

src/test/java/javax/money/format/MonetaryFormatsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ public void testGeAmountFormat_Name_Providers() {
9696

9797
@Test
9898
public void testGetProviderNames() {
99-
Collection<String> provs = MonetaryFormats.getProviderNames();
99+
Collection<String> provs = MonetaryFormats.getFormatProviderNames();
100100
assertNotNull(provs);
101101
System.out.println(provs);
102102
assertTrue(provs.contains("TestAmountFormatProvider"));
103103
}
104104

105105
@Test
106106
public void testGetDefaultProviderChain() {
107-
List<String> provs = MonetaryFormats.getDefaultProviderChain();
107+
List<String> provs = MonetaryFormats.getDefaultFormatProviderChain();
108108
assertNotNull(provs);
109109
assertTrue(provs.contains("TestAmountFormatProvider"));
110110
}

0 commit comments

Comments
 (0)