Skip to content

Commit 58b3a78

Browse files
committed
- Simplified/streamlined confusing AbstractContext API based on user feedback.
- Added some minor tweaks.
1 parent a1ce8ac commit 58b3a78

26 files changed

+1116
-1099
lines changed

src/main/java/org/javamoney/moneta/CurrencyUnitBuilder.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Builder for constructing new instances of {@link BuildableCurrencyUnit} using a fluent
2727
* API.
2828
*/
29-
public final class CurrencyUnitBuilder{
29+
public final class CurrencyUnitBuilder {
3030
/**
3131
* The currency code.
3232
*/
@@ -47,7 +47,7 @@ public final class CurrencyUnitBuilder{
4747
/**
4848
* Private constructor, use #of() methods.
4949
*/
50-
private CurrencyUnitBuilder(){
50+
private CurrencyUnitBuilder() {
5151
}
5252

5353
/**
@@ -56,7 +56,7 @@ private CurrencyUnitBuilder(){
5656
* @param currencyCode the (unique) and identifying currency code, not null.
5757
* @param currencyContext The currency context to be used.
5858
*/
59-
public static CurrencyUnitBuilder of(String currencyCode, javax.money.CurrencyContext currencyContext){
59+
public static CurrencyUnitBuilder of(String currencyCode, javax.money.CurrencyContext currencyContext) {
6060
return new CurrencyUnitBuilder(currencyCode, currencyContext);
6161
}
6262

@@ -66,7 +66,7 @@ public static CurrencyUnitBuilder of(String currencyCode, javax.money.CurrencyCo
6666
* @param currencyCode the (unique) and identifying currency code, not null.
6767
* @param providerName the currency provider, not null.
6868
*/
69-
public static CurrencyUnitBuilder of(String currencyCode, String providerName){
69+
public static CurrencyUnitBuilder of(String currencyCode, String providerName) {
7070
return new CurrencyUnitBuilder(currencyCode, CurrencyContextBuilder.of(providerName).build());
7171
}
7272

@@ -75,21 +75,21 @@ public static CurrencyUnitBuilder of(String currencyCode, String providerName){
7575
*
7676
* @param currencyCode the (unique) and identifying currency code, not null.
7777
*/
78-
private CurrencyUnitBuilder(String currencyCode, javax.money.CurrencyContext currencyContext){
78+
private CurrencyUnitBuilder(String currencyCode, javax.money.CurrencyContext currencyContext) {
7979
Objects.requireNonNull(currencyCode, "currencyCode required");
8080
this.currencyCode = currencyCode;
8181
Objects.requireNonNull(currencyContext, "currencyContext required");
8282
this.currencyContext = currencyContext;
8383
}
8484

8585
/**
86-
* Allows to set the currency code, for creating multiple instances, using one Builder.
86+
* Allows to setTyped the currency code, for creating multiple instances, using one Builder.
8787
*
8888
* @param currencyCode the (unique) and identifying currency code, not null.
8989
* @return the Builder, for chaining.
9090
* @see javax.money.CurrencyUnit#getCurrencyCode()
9191
*/
92-
public CurrencyUnitBuilder setCurrencyCode(String currencyCode){
92+
public CurrencyUnitBuilder setCurrencyCode(String currencyCode) {
9393
Objects.requireNonNull(currencyCode, "currencyCode required");
9494
this.currencyCode = currencyCode;
9595
this.currencyContext = CurrencyContextBuilder.of(getClass().getSimpleName()).build();
@@ -103,8 +103,8 @@ public CurrencyUnitBuilder setCurrencyCode(String currencyCode){
103103
* @return the Builder, for chaining.
104104
* @see javax.money.CurrencyUnit#getNumericCode()
105105
*/
106-
public CurrencyUnitBuilder setNumericCode(int numericCode){
107-
if(numericCode < -1){
106+
public CurrencyUnitBuilder setNumericCode(int numericCode) {
107+
if (numericCode < -1) {
108108
throw new IllegalArgumentException("numericCode must be >= -1");
109109
}
110110
this.numericCode = numericCode;
@@ -118,8 +118,8 @@ public CurrencyUnitBuilder setNumericCode(int numericCode){
118118
* @return the Builder, for chaining.
119119
* @see javax.money.CurrencyUnit#getDefaultFractionDigits()
120120
*/
121-
public CurrencyUnitBuilder setDefaultFractionDigits(int defaultFractionDigits){
122-
if(defaultFractionDigits < 0){
121+
public CurrencyUnitBuilder setDefaultFractionDigits(int defaultFractionDigits) {
122+
if (defaultFractionDigits < 0) {
123123
throw new IllegalArgumentException("defaultFractionDigits must be >= 0");
124124
}
125125
this.defaultFractionDigits = defaultFractionDigits;
@@ -132,7 +132,7 @@ public CurrencyUnitBuilder setDefaultFractionDigits(int defaultFractionDigits){
132132
* @return the new CurrencyUnit instance.
133133
* @throws javax.money.MonetaryException if creation fails
134134
*/
135-
public CurrencyUnit build(){
135+
public CurrencyUnit build() {
136136
return build(false);
137137
}
138138

@@ -145,9 +145,9 @@ public CurrencyUnit build(){
145145
* @return the new CurrencyUnit instance.
146146
* @see javax.money.MonetaryCurrencies#getCurrency(String, String...)
147147
*/
148-
public CurrencyUnit build(boolean register){
148+
public CurrencyUnit build(boolean register) {
149149
BuildableCurrencyUnit cu = new BuildableCurrencyUnit(this);
150-
if(register){
150+
if (register) {
151151
ConfigurableCurrencyUnitProvider.registerCurrencyUnit(cu);
152152
}
153153
return cu;
@@ -164,9 +164,9 @@ public CurrencyUnit build(boolean register){
164164
* @see javax.money.MonetaryCurrencies#getCurrency(String, String...)
165165
* @see javax.money.MonetaryCurrencies#getCurrency(java.util.Locale, String...)
166166
*/
167-
public CurrencyUnit build(boolean register, Locale locale){
167+
public CurrencyUnit build(boolean register, Locale locale) {
168168
BuildableCurrencyUnit cu = new BuildableCurrencyUnit(this);
169-
if(register){
169+
if (register) {
170170
ConfigurableCurrencyUnitProvider.registerCurrencyUnit(cu);
171171
ConfigurableCurrencyUnitProvider.registerCurrencyUnit(cu, locale);
172172
}

src/main/java/org/javamoney/moneta/DefaultExchangeRate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* This class models an exchange rate, which defines the factor the numeric value of a base amount in some currency
2525
* 'A' must be multiplied
26-
* to get the corresponding amount in the terminating currency 'B'. Hereby
26+
* to getTyped the corresponding amount in the terminating currency 'B'. Hereby
2727
* <ul>
2828
* <li>an exchange rate always models one rate from a base (source) to a term
2929
* (target) {@link javax.money.CurrencyUnit}.</li>
@@ -129,10 +129,10 @@ class DefaultExchangeRate implements ExchangeRate, Serializable, Comparable<Exch
129129
}
130130

131131
/**
132-
* Internal method to set the rate chain, which also ensure that the chain
132+
* Internal method to setTyped the rate chain, which also ensure that the chain
133133
* passed, when not null, contains valid elements.
134134
*
135-
* @param chain the chain to set.
135+
* @param chain the chain to setTyped.
136136
*/
137137
private void setExchangeRateChain(List<ExchangeRate> chain) {
138138
this.chain.clear();

src/main/java/org/javamoney/moneta/DefaultMonetaryContextFactory.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public MonetaryContext getContext() {
4545
} catch (Exception e) {
4646
Logger.getLogger(DefaultMonetaryContextFactory.class.getName())
4747
.log(Level.SEVERE, "Error evaluating default NumericContext, using default (NumericContext.NUM64).", e);
48-
return MonetaryContextBuilder.of(Money.class).set(MathContext.DECIMAL64).build();
48+
return MonetaryContextBuilder.of(Money.class).setTyped(MathContext.DECIMAL64).build();
4949
}
5050
}
5151

@@ -57,32 +57,32 @@ private MonetaryContext createContextWithConfig(Map<String, String> config) {
5757
case "DECIMAL32":
5858
Logger.getLogger(Money.class.getName()).info(
5959
"Using MathContext.DECIMAL32");
60-
builder.set(MathContext.DECIMAL32);
60+
builder.setTyped(MathContext.DECIMAL32);
6161
break;
6262
case "DECIMAL64":
6363
Logger.getLogger(Money.class.getName()).info(
6464
"Using MathContext.DECIMAL64");
65-
builder.set(MathContext.DECIMAL64);
65+
builder.setTyped(MathContext.DECIMAL64);
6666
break;
6767
case "DECIMAL128":
6868
Logger.getLogger(Money.class.getName()).info(
6969
"Using MathContext.DECIMAL128");
70-
builder.set(MathContext.DECIMAL128);
70+
builder.setTyped(MathContext.DECIMAL128);
7171
break;
7272
case "UNLIMITED":
7373
Logger.getLogger(Money.class.getName()).info(
7474
"Using MathContext.UNLIMITED");
75-
builder.set(MathContext.UNLIMITED);
75+
builder.setTyped(MathContext.UNLIMITED);
7676
break;
7777
default:
7878
Logger.getLogger(Money.class.getName()).warning(
7979
"Found invalid MathContext: " + value + ", using default MathContext.DECIMAL64");
80-
builder.set(MathContext.DECIMAL64);
80+
builder.setTyped(MathContext.DECIMAL64);
8181
}
8282
} else {
8383
Logger.getLogger(Money.class.getName()).info(
8484
"Using default MathContext.DECIMAL64");
85-
builder.set(MathContext.DECIMAL64);
85+
builder.setTyped(MathContext.DECIMAL64);
8686
}
8787
return builder.build();
8888
}
@@ -91,7 +91,7 @@ private MonetaryContext createMonetaryContextNonNullConfig(Map<String, String> c
9191
String value = config.get("org.javamoney.moneta.Money.defaults.roundingMode");
9292
RoundingMode rm = Objects.nonNull(value) ? RoundingMode.valueOf(value
9393
.toUpperCase(Locale.ENGLISH)) : RoundingMode.HALF_UP;
94-
MonetaryContext mc = MonetaryContextBuilder.of(Money.class).setPrecision(prec).set(rm).set(Money.class).build();
94+
MonetaryContext mc = MonetaryContextBuilder.of(Money.class).setPrecision(prec).setTyped(rm).setTyped(Money.class).build();
9595
Logger.getLogger(DefaultMonetaryContextFactory.class.getName()).info("Using custom MathContext: precision=" + prec
9696
+ ", roundingMode=" + rm);
9797
return mc;

src/main/java/org/javamoney/moneta/Money.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public final class Money implements MonetaryAmount, Comparable<MonetaryAmount>,
7373
private static final long serialVersionUID = -7565813772046251748L;
7474

7575
/**
76-
* The default {@link MonetaryContext} applied, if not set explicitly on
76+
* The default {@link MonetaryContext} applied, if not setTyped explicitly on
7777
* creation.
7878
*/
7979
public static final MonetaryContext DEFAULT_MONETARY_CONTEXT = new DefaultMonetaryContextFactory().getContext();
@@ -93,12 +93,6 @@ public final class Money implements MonetaryAmount, Comparable<MonetaryAmount>,
9393
*/
9494
private BigDecimal number;
9595

96-
/**
97-
* The number value.
98-
*/
99-
private transient NumberValue numberValue;
100-
101-
10296
/**
10397
* Creates a new instance os {@link Money}.
10498
*
@@ -164,10 +158,7 @@ public MonetaryContext getMonetaryContext(){
164158
*/
165159
@Override
166160
public NumberValue getNumber(){
167-
if(Objects.isNull(numberValue)){
168-
numberValue = new DefaultNumberValue(this.number);
169-
}
170-
return numberValue;
161+
return new DefaultNumberValue(number);
171162
}
172163

173164
/**

0 commit comments

Comments
 (0)