Skip to content

Commit 2e65e9b

Browse files
committed
18: ECB Rate Provider not working in JavaMoney Demo Application
Task-Url: https://github.com/JavaMoney/javamoney-examples/issues/issues/18
1 parent f37f2e9 commit 2e65e9b

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

console/javamoney-console-java10/src/main/java/module-info.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
the License.
1515
*/
1616
module org.javamoney.examples.console.java10 {
17-
exports org.javamoney.examples.console.java10;
17+
exports org.javamoney.examples.console.java10.convert;
18+
exports org.javamoney.examples.console.java10.core;
19+
exports org.javamoney.examples.console.java10.format;
1820

1921
requires transitive java.money;
2022
requires org.javamoney.moneta;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.javamoney.examples.console.java10.convert;
17+
18+
import org.javamoney.moneta.Money;
19+
20+
import javax.money.MonetaryAmount;
21+
import javax.money.convert.ConversionQueryBuilder;
22+
import javax.money.convert.CurrencyConversion;
23+
import javax.money.convert.MonetaryConversions;
24+
25+
import java.text.MessageFormat;
26+
import java.time.LocalDate;
27+
28+
/**
29+
* Showing accessing exchange rates and doing conversions.
30+
*/
31+
public class ConversionExample {
32+
private static final String DEFAULT_TERM_CURRENCY_CODE = "CHF";
33+
34+
public static void main(String... args) {
35+
String termCurrencyCode = DEFAULT_TERM_CURRENCY_CODE;
36+
if (args.length > 0) {
37+
termCurrencyCode = args[0];
38+
}
39+
final MonetaryAmount amt = Money.of(2000, "EUR");
40+
CurrencyConversion conv= MonetaryConversions.getConversion(termCurrencyCode, "ECB");
41+
System.out.println(MessageFormat.format("2000 EUR (ECB)-> {0} = {1}",
42+
termCurrencyCode, amt.with(conv)));
43+
conv= MonetaryConversions.getConversion(termCurrencyCode, "IMF");
44+
System.out.println(MessageFormat.format("2000 EUR (IMF)-> {0} = {1}",
45+
termCurrencyCode, amt.with(conv)));
46+
47+
System.out.println(MessageFormat.format(
48+
"2000 EUR (ECB, at 5th Jan 2015)-> {0} = {1}",
49+
termCurrencyCode, amt.with(MonetaryConversions
50+
.getConversion(ConversionQueryBuilder.of()
51+
.setTermCurrency(termCurrencyCode)
52+
.set(LocalDate.of(2015, 01, 05)).build()))));
53+
}
54+
55+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.javamoney.examples.console.java10;
16+
package org.javamoney.examples.console.java10.core;
1717

1818
import org.javamoney.examples.console.java10.util.ConsoleUtils;
1919
import org.javamoney.moneta.FastMoney;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.javamoney.examples.console.java10;
16+
package org.javamoney.examples.console.java10.format;
1717

1818
import org.javamoney.moneta.Money;
1919
import org.javamoney.moneta.format.AmountFormatParams;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.javamoney.examples.console.java10;
16+
package org.javamoney.examples.console.java10.format;
1717

1818
import java.util.Locale;
1919

0 commit comments

Comments
 (0)