Skip to content

Commit 25f3630

Browse files
committed
https://java.net/jira/browse/JAVAMONEY-77
Replaced create() with of() in builders. Removed exposure of BuildableCurrencyUnit and DefaultExchangeRate in RI by refactoring builder pattern similar to RI.
1 parent 19609ae commit 25f3630

File tree

56 files changed

+788
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+788
-791
lines changed

pom.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<moduleDir>.</moduleDir>
3030

31-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<project.create.sourceEncoding>UTF-8</project.create.sourceEncoding>
3232
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3333

3434
<jdkVersion>1.8</jdkVersion>
@@ -259,7 +259,7 @@
259259
<value>true</value>
260260
</property>
261261
</activation>
262-
<build>
262+
<create>
263263
<pluginManagement>
264264
<plugins>
265265
<plugin>
@@ -317,7 +317,7 @@
317317
</executions>
318318
</plugin>
319319
</plugins>
320-
</build>
320+
</create>
321321
</profile>
322322

323323
<profile>
@@ -328,7 +328,7 @@
328328
<value>true</value>
329329
</property>
330330
</activation>
331-
<build>
331+
<create>
332332
<pluginManagement>
333333
<plugins>
334334
<!-- ======================================================= -->
@@ -374,7 +374,7 @@
374374
</executions>
375375
</plugin>
376376
</plugins>
377-
</build>
377+
</create>
378378
</profile>
379379
<profile>
380380
<id>cloudbees-deployment</id>
@@ -433,7 +433,7 @@
433433
</dependency -->
434434
</dependencies>
435435

436-
<build>
436+
<create>
437437

438438
<defaultGoal>install</defaultGoal>
439439

@@ -520,7 +520,7 @@
520520
<source>${maven.compile.sourceLevel}</source>
521521
<target>${maven.compile.targetLevel}</target>
522522
<compilerArgument>-g</compilerArgument>
523-
<encoding>${project.build.sourceEncoding}</encoding>
523+
<encoding>${project.create.sourceEncoding}</encoding>
524524
</configuration>
525525
</plugin>
526526
<plugin>
@@ -801,8 +801,8 @@
801801
802802
<postProcess>
803803
<zip
804-
destfile="${project.build.directory}/${project.artifactId}-${project.version}-docs.zip">
805-
<fileset dir="${project.build.directory}/docs"
804+
destfile="${project.of.directory}/${project.artifactId}-${project.version}-docs.zip">
805+
<fileset dir="${project.of.directory}/docs"
806806
includes="**/*.pdf" />
807807
</zip>
808808
</postProcess -->
@@ -826,7 +826,7 @@
826826
</executions>
827827
</plugin -->
828828
</plugins>
829-
</build>
829+
</create>
830830

831831

832832
<reporting>
@@ -852,7 +852,7 @@
852852
<keywords>true</keywords>
853853
<linksource>true</linksource>
854854
<!-- overview>${basedir}/overview.html</overview -->
855-
<source>${project.build.sourceCompilerLevel}</source>
855+
<source>${project.create.sourceCompilerLevel}</source>
856856
<!-- stylesheetfile>${basedir}/src/site/css/money-jdoc.css</stylesheetfile -->
857857
<verbose>true</verbose>
858858
<aggregate>true</aggregate>
@@ -893,7 +893,7 @@
893893
<version>2.4</version>
894894
<configuration>
895895
<aggregate>true</aggregate>
896-
<encoding>${project.build.sourceEncoding}</encoding>
896+
<encoding>${project.create.sourceEncoding}</encoding>
897897
<tagListOptions>
898898
<tagClasses>
899899
<tagClass>
@@ -951,7 +951,7 @@
951951
<format>xml</format>
952952
<linkXRef>true</linkXRef>
953953
<aggregate>true</aggregate>
954-
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
954+
<sourceEncoding>${project.create.sourceEncoding}</sourceEncoding>
955955
</configuration>
956956
</plugin>
957957
<plugin>

src/main/asciidoc/JavaMoneySpecification.adoc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ enum MyFlavor{ // only an example, not part of the API
10711071
SLOW. FAST
10721072
}
10731073

1074-
MonetaryContext ctx = MonetaryContextBuilder.create()
1074+
MonetaryContext ctx = MonetaryContextBuilder.of()
10751075
.setMaxScale(2)
10761076
.setFixedScale(true)
10771077
.setPrecision(12)
@@ -1107,7 +1107,7 @@ MyMoney money = fact.setCurrency("USD").setNumber(10.50).create();
11071107
.Usage Example for reating an Amount, querying for a +MonetaryAmountFactory+
11081108
-------------------------------------------------------------------------------
11091109
MonetaryAmountFactory<?> fact = MonetaryAmounts.getAmountFactory(
1110-
MonetaryAmountFactoryQueryBuilder.create().setMaxScale(2).setPrecision(10).build());
1110+
MonetaryAmountFactoryQueryBuilder.of().setMaxScale(2).setPrecision(10).build());
11111111
MonetaryAmount money = fact.setCurrency("USD").setNumber(10.50).create();
11121112
-------------------------------------------------------------------------------
11131113
@@ -1216,7 +1216,7 @@ Hereby
12161216
-------------------------------------------------------------------------------
12171217
// Note: Enum Region only serves as an example and not part of the API
12181218
Collection<CurrencyUnit> currencies = MonetaryCurrencies.getCurrencies(
1219-
CurrencyQueryBuilder.create().setProvider("A", "B").set(Region.EMEA).setInt("contractNr", 12345).build()
1219+
CurrencyQueryBuilder.of().setProvider("A", "B").set(Region.EMEA).setInt("contractNr", 12345).build()
12201220
);
12211221
-------------------------------------------------------------------------------
12221222
@@ -1228,7 +1228,7 @@ provider would be implemented and registered one could perform the following que
12281228
-------------------------------------------------------------------------------
12291229
// Note: This is just an example: no historic provider is part of the API or RI currently
12301230
Collection<CurrencyUnit> currencies = MonetaryCurrencies.getCurrencies(
1231-
CurrencyQueryBuilder.create().set(Locale.GERMANY).setTimestamp(LocalDate.of(1930,1,1)).build()
1231+
CurrencyQueryBuilder.of().set(Locale.GERMANY).setTimestamp(LocalDate.of(1930,1,1)).build()
12321232
);
12331233
-------------------------------------------------------------------------------
12341234
@@ -1399,11 +1399,11 @@ default currency rounding (e.g. for +CHF/Swiss Francs+), as follows:
13991399
.Example how a cash rounding could be accessed (not part of the API)
14001400
-------------------------------------------------------------------------------
14011401
MonetaryRounding rounding = MonetaryRoundings.getRounding(
1402-
RoundingQueryBuilder.create() <1>
1402+
RoundingQueryBuilder.of() <1>
14031403
.setRoundingName("cashRounding") <2>
14041404
.setCurrencyUnit("USD") <3>
14051405
.setTimestamp(temporalAccessor) <4>
1406-
.create()); <5>
1406+
.build()); <5>
14071407
-------------------------------------------------------------------------------
14081408
<1> Access a rounding by passing a +RoundingQuery+
14091409
<2> Acquire a specific _named_ rounding.
@@ -1652,13 +1652,13 @@ can be passed to parametrize the +<<CurrencyConversion>>+ or +<<ExchangeRateProv
16521652
[source,java]
16531653
.Usage Sample Create for Currency Conversion using Customized Parameters
16541654
--------------------------------------------------------------------------
1655-
ConversionContext ctx = ConversionContextBuilder.create()
1655+
ConversionContext ctx = ConversionContextBuilder.of()
16561656
.setRateType(RateType.DEFERRED).
16571657
.set("customerID", 1234)
16581658
.set("contractID", "213453-GFDT-02")
16591659
.set(FallbackStragey.PROVIDER)
16601660
.set(amount)
1661-
.create();
1661+
.build();
16621662

16631663
// Access a conversion...
16641664
CurrencyConversion conversion = MonetaryConversions.getConversion("CHF", ctx);
@@ -1814,7 +1814,7 @@ for this we could configure an +AmountFormatContext+ that implements this behavi
18141814
[source,java]
18151815
.Usage Example (continued) Formatting a MonetaryAmount
18161816
--------------------------------------------------------------------------
1817-
AmountFormatQuery query = AmountFormatQueryBuilder.create(new Locale("","INR"))
1817+
AmountFormatQuery query = AmountFormatQueryBuilder.of(new Locale("","INR"))
18181818
.set("groupSizes", new int[]{3,2]).build();
18191819
MonetaryAmountFormat format = MonetaryAmountFormats.getAmountFormat(query);
18201820
MonetaryAmountFactory<?> f = MonetaryAmounts.getDefaultAmountFactory();
@@ -1922,12 +1922,12 @@ THe code below illustrates a more complex example:
19221922
[source,java]
19231923
.Advanced setup of a AmountFormatContext
19241924
-------------------------------------------------------------------------------
1925-
AmountFormatContext ctx = new AmountFormatContext.Builder("htmlFormat") <1>
1926-
.setText("title", "MyTitle") <2>
1927-
.setText("negativeStyle", ".negNumber") <3>
1928-
.setText("positiveStyle", ".posNumber+) <3>
1929-
.setText("styleClass", "styledAmount") <4>
1930-
.create(); <5>
1925+
AmountFormatContext ctx = new AmountFormatContextBuilder.of("htmlFormat") <1>
1926+
.setText("title", "MyTitle") <2>
1927+
.setText("negativeStyle", ".negNumber") <3>
1928+
.setText("positiveStyle", ".posNumber+) <3>
1929+
.setText("styleClass", "styledAmount") <4>
1930+
.build(); <5>
19311931
-------------------------------------------------------------------------------
19321932
<1> Access a format with name +htmlFormat+
19331933
<2> Sets the format's display name
@@ -2878,7 +2878,7 @@ When accessing +MonetaryAmountFactory+ instances it is possible to configure the
28782878
.Example Configuring a +MonetaryAmountFactory+, using the RI class +Money+ as example.
28792879
-------------------------------------------------------------------
28802880
MonetaryAmountFactory<Money> fact = MonetaryAmounts.getAmountFactory(
2881-
MonetaryAmountFactoryQueryBuilder.create(Money.class)
2881+
MonetaryAmountFactoryQueryBuilder.of(Money.class)
28822882
.set(new MathContext(250, RoundingMode.HALF_EVEN)).build()
28832883
);
28842884
// Creates an instance of Money with the given MathContext
@@ -3121,7 +3121,7 @@ conversion, e.g.:
31213121
[source,java]
31223122
-------------------------------------------------------------------
31233123
MonetaryAmount inCHF =...;
3124-
CurrencyConversion conv = MonetaryConversions.getConversion(ConversionQueryBuilder.create()
3124+
CurrencyConversion conv = MonetaryConversions.getConversion(ConversionQueryBuilder.of()
31253125
.setProviders("CS", "EZB", "IMF")
31263126
.setTermCurrency("EUR")
31273127
.set(MonetaryAmount.class, inCHF, MonetaryAmount.class)

src/main/java/javax/money/AbstractContext.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
* extensions os specialities.<p>
2323
* Superclasses of this class must be final, immutable, serializable and thread-safe.
2424
*/
25-
public abstract class AbstractContext implements Serializable {
25+
public abstract class AbstractContext implements Serializable{
2626

27-
/** Key for storing the target providers to be queried */
27+
/**
28+
* Key for storing the target providers to be queried
29+
*/
2830
public static final String KEY_PROVIDER = "provider";
2931

30-
/** Key name for the timestamp attribute. */
32+
/**
33+
* Key name for the timestamp attribute.
34+
*/
3135
public static final String KEY_TIMESTAMP = "timestamp";
3236

3337
/**
@@ -374,7 +378,7 @@ public String getProvider(){
374378
}
375379

376380
/**
377-
* Get the current target timestamp of the query in UTC milliseconds. If not set it tries to create an
381+
* Get the current target timestamp of the query in UTC milliseconds. If not set it tries to of an
378382
* UTC timestamp from #getTimestamp(). This allows to select historical roundings that were valid in the
379383
* past. Its implementation specific, to what extend historical roundings are available. By default if this
380384
* property is not set always current {@link javax.money.MonetaryRounding} instances are provided.
@@ -393,7 +397,7 @@ public Long getTimestampMillis(){
393397
}
394398

395399
/**
396-
* Get the current target timestamp of the query. If not set it tries to create an Instant from
400+
* Get the current target timestamp of the query. If not set it tries to of an Instant from
397401
* #getTimestampMillis(). This allows to select historical roundings that were valid in the
398402
* past. Its implementation specific, to what extend historical roundings are available. By default if this
399403
* property is not set always current {@link javax.money.MonetaryRounding} instances are provided.
@@ -432,6 +436,7 @@ public int hashCode(){
432436

433437
/**
434438
* Access all the values present.
439+
*
435440
* @param type the type used.
436441
* @return
437442
*/

src/main/java/javax/money/AbstractContextBuilder.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/**
2222
* This interface defines the common generic parts of a query. Queries are used to pass complex parameters sets
23-
* to lookup monetary artifacts, e.g. {@link javax.money.MonetaryAmountFactory},
23+
* to lookup monetary artifacts, e.g. {@link MonetaryAmountFactory},
2424
* {@link javax.money.MonetaryRounding},
2525
* {@link javax.money.CurrencyUnit}, {@link javax.money.convert.ExchangeRateProvider} and {@link javax.money.convert
2626
* .CurrencyConversion}.
@@ -270,7 +270,7 @@ public B setProvider(String provider){
270270
*/
271271
public B setTimestampMillis(long timestamp){
272272
set(AbstractContext.KEY_TIMESTAMP, timestamp);
273-
return (B)this;
273+
return (B) this;
274274
}
275275

276276
/**
@@ -283,10 +283,10 @@ public B setTimestampMillis(long timestamp){
283283
* @return this instance for chaining
284284
* @see #setTimestampMillis(long)
285285
*/
286-
public B setTimestamp(TemporalAccessor timestamp){
286+
public B setTimestamp(TemporalAccessor timestamp){
287287
Objects.requireNonNull(timestamp);
288288
set(AbstractContext.KEY_TIMESTAMP, timestamp, TemporalAccessor.class);
289-
return (B)this;
289+
return (B) this;
290290
}
291291

292292
/**
@@ -340,7 +340,6 @@ public <T> B set(Object key, T value, Class<? extends T> type){
340340
}
341341

342342

343-
344343
/**
345344
* Creates a new {@link AbstractContext} with the data from this Builder
346345
* instance.
@@ -354,12 +353,12 @@ public <T> B set(Object key, T value, Class<? extends T> type){
354353
*
355354
* @see Object#toString()
356355
*/
357-
358-
@Override
356+
357+
@Override
359358
public String toString(){
360359
StringBuilder attrsBuilder = new StringBuilder();
361360
for(Map.Entry<Class,Map<Object,Object>> en : ((Map<Class,Map<Object,Object>>) this.data).entrySet()){
362-
361+
363362
Map<Object,Object> sortedMap = new TreeMap<>(Comparator.comparing(Object::toString));
364363
sortedMap.putAll(en.getValue());
365364
for(Map.Entry<Object,Object> entry : sortedMap.entrySet()){

src/main/java/javax/money/AbstractQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Class<?> getTargetType(){
7171
}
7272

7373
/**
74-
* Get the current timestamp of the context in UTC milliseconds. If not set it tries to create an
74+
* Get the current timestamp of the context in UTC milliseconds. If not set it tries to of an
7575
* UTC timestamp from #getTimestamp().
7676
*
7777
* @return the timestamp in millis, or null.
@@ -88,7 +88,7 @@ public Long getTimestampMillis(){
8888
}
8989

9090
/**
91-
* Get the current timestamp. If not set it tries to create an Instant from #getTimestampMillis().
91+
* Get the current timestamp. If not set it tries to of an Instant from #getTimestampMillis().
9292
*
9393
* @return the current timestamp, or null.
9494
*/

0 commit comments

Comments
 (0)