Skip to content

Commit a0bd837

Browse files
committed
JAVAMONEY-91: renamed getXXXContext() to getContext().
1 parent ce0fbbd commit a0bd837

24 files changed

+212
-208
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public int getDefaultFractionDigits() {
8787
}
8888

8989
@Override
90-
public CurrencyContext getCurrencyContext() {
90+
public CurrencyContext getContext() {
9191
return currencyContext;
9292
}
9393

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void setExchangeRateChain(List<ExchangeRate> chain) {
153153
*
154154
* @return the conversion context, never null.
155155
*/
156-
public final ConversionContext getConversionContext() {
156+
public final ConversionContext getContext() {
157157
return this.conversionContext;
158158
}
159159

@@ -224,7 +224,7 @@ public int compareTo(ExchangeRate o) {
224224
compare = this.getCurrency().getCurrencyCode().compareTo(o.getCurrency().getCurrencyCode());
225225
}
226226
if (compare == 0) {
227-
compare = this.getConversionContext().getProviderName().compareTo(o.getConversionContext().getProviderName());
227+
compare = this.getContext().getProviderName().compareTo(o.getContext().getProviderName());
228228
}
229229
return compare;
230230
}
@@ -274,7 +274,7 @@ public boolean equals(Object obj) {
274274
* @return a new {@link ExchangeRateBuilder}, never {@code null}.
275275
*/
276276
public ExchangeRateBuilder toBuilder() {
277-
return new ExchangeRateBuilder(getConversionContext()).setBase(getBaseCurrency()).setTerm(getCurrency())
277+
return new ExchangeRateBuilder(getContext()).setBase(getBaseCurrency()).setTerm(getCurrency())
278278
.setFactor(getFactor()).setRateChain(getExchangeRateChain());
279279
}
280280
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ExchangeRateBuilder(ConversionContext context) {
6565
* @param rate the {@link javax.money.convert.ExchangeRate} to be applied
6666
*/
6767
public ExchangeRateBuilder(ExchangeRate rate) {
68-
setContext(rate.getConversionContext());
68+
setContext(rate.getContext());
6969
setFactor(rate.getFactor());
7070
setTerm(rate.getCurrency());
7171
setBase(rate.getBaseCurrency());
@@ -168,7 +168,7 @@ public ExchangeRate build() {
168168
public ExchangeRateBuilder setRate(ExchangeRate rate) {
169169
this.base = rate.getBaseCurrency();
170170
this.term = rate.getCurrency();
171-
this.conversionContext = rate.getConversionContext();
171+
this.conversionContext = rate.getContext();
172172
this.factor = rate.getFactor();
173173
this.rateChain = rate.getExchangeRateChain();
174174
this.term = rate.getCurrency();

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
* different results:
4040
* </p>
4141
* <pre><code>
42-
* Money money1 = money1.add(Money.of(EURO, 1234567.3444));
43-
* money1 = money1.subtract(Money.of(EURO, 232323));
42+
* Money money1 = money1.add(Money.of("EUR", 1234567.3444));
43+
* money1 = money1.subtract(Money.of("EUR", 232323));
4444
* money1 = money1.multiply(3.4);
4545
* money1 = money1.divide(5.456);
4646
* </code></pre>
@@ -51,8 +51,8 @@
5151
* whereas
5252
* </p>
5353
* <pre><code>
54-
* FastMoney money1 = money1.add(FastMoney.of(EURO, 1234567.3444));
55-
* money1 = money1.subtract(FastMoney.of(EURO, 232323));
54+
* FastMoney money1 = money1.add(FastMoney.of("EUR", 1234567.3444));
55+
* money1 = money1.subtract(FastMoney.of("EUR", 232323));
5656
* money1 = money1.multiply(3.4);
5757
* money1 = money1.divide(5.456);
5858
* </code></pre>
@@ -64,8 +64,8 @@
6464
* code above with the following: *
6565
* </p>
6666
* <pre><code>
67-
* FastMoney money1 = money1.add(Money.of(EURO, 1234567.3444));
68-
* money1 = money1.subtract(FastMoney.of(EURO, 232323));
67+
* FastMoney money1 = money1.add(Money.of("EUR", 1234567.3444));
68+
* money1 = money1.subtract(FastMoney.of("EUR", 232323));
6969
* money1 = money1.multiply(3.4);
7070
* money1 = money1.divide(5.456);
7171
* </code></pre>
@@ -183,10 +183,10 @@ public CurrencyUnit getCurrency() {
183183
* Access the {@link MonetaryContext} used by this instance.
184184
*
185185
* @return the {@link MonetaryContext} used, never null.
186-
* @see javax.money.MonetaryAmount#getMonetaryContext()
186+
* @see javax.money.MonetaryAmount#getContext()
187187
*/
188188
@Override
189-
public MonetaryContext getMonetaryContext() {
189+
public MonetaryContext getContext() {
190190
return MONETARY_CONTEXT;
191191
}
192192

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public CurrencyUnit getCurrency() {
144144
* Access the {@link MonetaryContext} used by this instance.
145145
*
146146
* @return the {@link MonetaryContext} used, never null.
147-
* @see javax.money.MonetaryAmount#getMonetaryContext()
147+
* @see javax.money.MonetaryAmount#getContext()
148148
*/
149149
@Override
150-
public MonetaryContext getMonetaryContext() {
150+
public MonetaryContext getContext() {
151151
return monetaryContext;
152152
}
153153

@@ -427,7 +427,7 @@ public Money divide(Number divisor) {
427427
return this;
428428
}
429429
BigDecimal dec =
430-
this.number.divide(divisorBD, MoneyUtils.getMathContext(getMonetaryContext(), RoundingMode.HALF_EVEN));
430+
this.number.divide(divisorBD, MoneyUtils.getMathContext(getContext(), RoundingMode.HALF_EVEN));
431431
return new Money(dec, getCurrency());
432432
}
433433

@@ -807,7 +807,7 @@ public static Money from(MonetaryAmount amt) {
807807
if (amt.getClass() == Money.class) {
808808
return (Money) amt;
809809
}
810-
return Money.of(amt.getNumber().numberValue(BigDecimal.class), amt.getCurrency(), amt.getMonetaryContext());
810+
return Money.of(amt.getNumber().numberValue(BigDecimal.class), amt.getCurrency(), amt.getContext());
811811
}
812812

813813
/**
@@ -859,4 +859,5 @@ public static boolean isInfinityAndNotNaN(Number number) {
859859
}
860860
return false;
861861
}
862+
862863
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public CurrencyUnit getCurrency() {
293293
* @return the {@link MathContext} used, never null.
294294
*/
295295
@Override
296-
public MonetaryContext getMonetaryContext() {
296+
public MonetaryContext getContext() {
297297
return this.monetaryContext;
298298
}
299299

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

Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,90 +14,93 @@
1414

1515
/**
1616
* class to format and parse a text string such as 'EUR 25.25' or vice versa.
17+
*
1718
* @author otaviojava
1819
*/
1920
class ToStringMonetaryAmountFormat implements MonetaryAmountFormat {
2021

21-
private ToStringMonetaryAmountFormatStyle style;
22-
23-
private ToStringMonetaryAmountFormat(ToStringMonetaryAmountFormatStyle style) {
24-
this.style = Objects.requireNonNull(style);
25-
}
26-
27-
public static ToStringMonetaryAmountFormat of(
28-
ToStringMonetaryAmountFormatStyle style) {
29-
return new ToStringMonetaryAmountFormat(style);
30-
}
31-
32-
@Override
33-
public String queryFrom(MonetaryAmount amount) {
34-
if (Objects.isNull(amount)) {
35-
return null;
36-
}
37-
return amount.toString();
38-
}
39-
40-
@Override
41-
public AmountFormatContext getAmountFormatContext() {
42-
throw new UnsupportedOperationException(
43-
"ToStringMonetaryAmountFormat does not the method suport getAmountFormatContext()");
44-
}
45-
46-
@Override
47-
public void print(Appendable appendable, MonetaryAmount amount)
48-
throws IOException {
49-
appendable.append(Optional.ofNullable(amount)
50-
.map(MonetaryAmount::toString).orElse("null"));
51-
52-
}
53-
54-
@Override
55-
public MonetaryAmount parse(CharSequence text)
56-
throws MonetaryParseException {
57-
ParserMonetaryAmount amount = parserMonetaryAmount(text);
58-
return style.to(amount);
59-
}
60-
61-
private ParserMonetaryAmount parserMonetaryAmount(CharSequence text) {
62-
String[] array = Objects.requireNonNull(text).toString().split(" ");
63-
CurrencyUnit currencyUnit = MonetaryCurrencies.getCurrency(array[0]);
64-
BigDecimal number = new BigDecimal(array[1]);
65-
return new ParserMonetaryAmount(currencyUnit, number);
66-
}
67-
private class ParserMonetaryAmount {
68-
public ParserMonetaryAmount(CurrencyUnit currencyUnit, BigDecimal number) {
69-
this.currencyUnit = currencyUnit;
70-
this.number = number;
71-
}
72-
73-
private CurrencyUnit currencyUnit;
74-
private BigDecimal number;
75-
}
76-
77-
/**
78-
* indicates with implementation will used to format or parser in
79-
* ToStringMonetaryAmountFormat
80-
*/
81-
enum ToStringMonetaryAmountFormatStyle {
82-
MONEY {
83-
@Override
84-
MonetaryAmount to(ParserMonetaryAmount amount) {
85-
return Money.of(amount.number, amount.currencyUnit);
86-
}
87-
},
88-
FAST_MONEY {
89-
@Override
90-
MonetaryAmount to(ParserMonetaryAmount amount) {
91-
return FastMoney.of(amount.number, amount.currencyUnit);
92-
}
93-
},
94-
ROUNDED_MONEY {
95-
@Override
96-
MonetaryAmount to(ParserMonetaryAmount amount) {
97-
return RoundedMoney.of(amount.number, amount.currencyUnit);
98-
}
99-
};
100-
abstract MonetaryAmount to(ParserMonetaryAmount amount);
101-
}
22+
private ToStringMonetaryAmountFormatStyle style;
23+
24+
private ToStringMonetaryAmountFormat(ToStringMonetaryAmountFormatStyle style) {
25+
this.style = Objects.requireNonNull(style);
26+
}
27+
28+
public static ToStringMonetaryAmountFormat of(
29+
ToStringMonetaryAmountFormatStyle style) {
30+
return new ToStringMonetaryAmountFormat(style);
31+
}
32+
33+
@Override
34+
public String queryFrom(MonetaryAmount amount) {
35+
if (Objects.isNull(amount)) {
36+
return null;
37+
}
38+
return amount.toString();
39+
}
40+
41+
@Override
42+
public AmountFormatContext getContext() {
43+
throw new UnsupportedOperationException(
44+
"ToStringMonetaryAmountFormat does not the method suport getContext()");
45+
}
46+
47+
@Override
48+
public void print(Appendable appendable, MonetaryAmount amount)
49+
throws IOException {
50+
appendable.append(Optional.ofNullable(amount)
51+
.map(MonetaryAmount::toString).orElse("null"));
52+
53+
}
54+
55+
@Override
56+
public MonetaryAmount parse(CharSequence text)
57+
throws MonetaryParseException {
58+
ParserMonetaryAmount amount = parserMonetaryAmount(text);
59+
return style.to(amount);
60+
}
61+
62+
private ParserMonetaryAmount parserMonetaryAmount(CharSequence text) {
63+
String[] array = Objects.requireNonNull(text).toString().split(" ");
64+
CurrencyUnit currencyUnit = MonetaryCurrencies.getCurrency(array[0]);
65+
BigDecimal number = new BigDecimal(array[1]);
66+
return new ParserMonetaryAmount(currencyUnit, number);
67+
}
68+
69+
private class ParserMonetaryAmount {
70+
public ParserMonetaryAmount(CurrencyUnit currencyUnit, BigDecimal number) {
71+
this.currencyUnit = currencyUnit;
72+
this.number = number;
73+
}
74+
75+
private CurrencyUnit currencyUnit;
76+
private BigDecimal number;
77+
}
78+
79+
/**
80+
* indicates with implementation will used to format or parser in
81+
* ToStringMonetaryAmountFormat
82+
*/
83+
enum ToStringMonetaryAmountFormatStyle {
84+
MONEY {
85+
@Override
86+
MonetaryAmount to(ParserMonetaryAmount amount) {
87+
return Money.of(amount.number, amount.currencyUnit);
88+
}
89+
},
90+
FAST_MONEY {
91+
@Override
92+
MonetaryAmount to(ParserMonetaryAmount amount) {
93+
return FastMoney.of(amount.number, amount.currencyUnit);
94+
}
95+
},
96+
ROUNDED_MONEY {
97+
@Override
98+
MonetaryAmount to(ParserMonetaryAmount amount) {
99+
return RoundedMoney.of(amount.number, amount.currencyUnit);
100+
}
101+
};
102+
103+
abstract MonetaryAmount to(ParserMonetaryAmount amount);
104+
}
102105

103106
}

src/main/java/org/javamoney/moneta/convert/internal/AbstractECBCurrentRateProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void newDataLoaded(String data, InputStream is) {
8383
final int oldSize = this.historicRates.size();
8484
try {
8585
SAXParser parser = saxParserFactory.newSAXParser();
86-
parser.parse(is, new RateReadingHandler(historicRates, getProviderContext()));
86+
parser.parse(is, new RateReadingHandler(historicRates, getContext()));
8787
} catch (Exception e) {
8888
LOGGER.log(Level.FINEST, "Error during data load.", e);
8989
}
@@ -149,7 +149,7 @@ private ExchangeRate createExchangeRate(ConversionQuery query,
149149
return builder.build();
150150
}
151151
throw new CurrencyConversionException(query.getBaseCurrency(),
152-
query.getCurrency(), sourceRate.getConversionContext());
152+
query.getCurrency(), sourceRate.getContext());
153153
}
154154
}
155155

@@ -161,7 +161,7 @@ private boolean areBothBaseCurrencies(ConversionQuery query) {
161161

162162
private ExchangeRateBuilder getBuilder(ConversionQuery query, LocalDate localDate) {
163163
ExchangeRateBuilder builder = new ExchangeRateBuilder(
164-
ConversionContextBuilder.create(getProviderContext(), RateType.HISTORIC)
164+
ConversionContextBuilder.create(getContext(), RateType.HISTORIC)
165165
.set(localDate).build());
166166
builder.setBase(query.getBaseCurrency());
167167
builder.setTerm(query.getCurrency());

src/main/java/org/javamoney/moneta/convert/internal/DefaultMonetaryConversionsSingletonSpi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public DefaultMonetaryConversionsSingletonSpi() {
6262
public void reload() {
6363
Map<String, ExchangeRateProvider> newProviders = new ConcurrentHashMap<>();
6464
for (ExchangeRateProvider prov : Bootstrap.getServices(ExchangeRateProvider.class)) {
65-
newProviders.put(prov.getProviderContext().getProviderName(), prov);
65+
newProviders.put(prov.getContext().getProviderName(), prov);
6666
}
6767
this.conversionProviders = newProviders;
6868
}

src/main/java/org/javamoney/moneta/convert/internal/IMFRateProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private ExchangeRate lookupRate(List<ExchangeRate> list, LocalDate localDate) {
282282
if (Objects.isNull(localDate)) {
283283
localDate = LocalDate.now();
284284
}
285-
if (isValid(rate.getConversionContext(), localDate)) {
285+
if (isValid(rate.getContext(), localDate)) {
286286
return rate;
287287
}
288288
if (Objects.isNull(found)) {

0 commit comments

Comments
 (0)