org.javamoney.moneta.CurrencyUnitBuilder Java Examples
The following examples show how to use
org.javamoney.moneta.CurrencyUnitBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurableCurrencyUnitProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
/** * Tests that searching by numeric code is supported by {@link ConfigurableCurrencyUnitProvider}. */ @Test public void testSearchByNumericCurrencyCode() { CurrencyUnit usd = CurrencyUnitBuilder.of("USD", "search-test") .setNumericCode(840) .setDefaultFractionDigits(2) .build(false); CurrencyUnit eur = CurrencyUnitBuilder.of("EUR", "search-test") .setNumericCode(978) .setDefaultFractionDigits(2) .build(false); ConfigurableCurrencyUnitProvider.registerCurrencyUnit(usd); ConfigurableCurrencyUnitProvider.registerCurrencyUnit(eur); try { CurrencyQuery query = CurrencyQueryBuilder.of() .setProviderName(ConfigurableCurrencyUnitProvider.class.getSimpleName()) .setNumericCodes(840) .build(); CurrencyUnit currency = Monetary.getCurrency(query); assertEquals(usd, currency); } finally { ConfigurableCurrencyUnitProvider.removeCurrencyUnit(usd.getCurrencyCode()); ConfigurableCurrencyUnitProvider.removeCurrencyUnit(eur.getCurrencyCode()); } }
Example #2
Source File: CurrencyUnitDeserializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldDeserialize() throws IOException { final CurrencyUnit actual = unit.readValue("\"EUR\"", CurrencyUnit.class); final CurrencyUnit expected = CurrencyUnitBuilder.of("EUR", "default").build(); assertThat(actual, is(expected)); }
Example #3
Source File: CurrencyUnitDeserializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldDeserializeWithTyping() throws IOException { unit.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().build()); final CurrencyUnit actual = unit.readValue("\"EUR\"", CurrencyUnit.class); final CurrencyUnit expected = CurrencyUnitBuilder.of("EUR", "default").build(); assertThat(actual, is(expected)); }
Example #4
Source File: CurrencyUnitSerializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldSerialize() throws JsonProcessingException { final String expected = "EUR"; final CurrencyUnit currency = CurrencyUnitBuilder.of(expected, "default").build(); final String actual = unit.writeValueAsString(currency); assertThat(actual, is('"' + expected + '"')); }
Example #5
Source File: MonetaryRoundingsTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testCashRoundings(){ CurrencyUnit chf = CurrencyUnitBuilder.of("CHF","").build(); CurrencyUnit eur = CurrencyUnitBuilder.of("EUR","").build(); CurrencyUnit sek = CurrencyUnitBuilder.of("SEK","").build(); MonetaryRounding rounding = Monetary.getRounding( RoundingQueryBuilder.of() .setCurrency(chf) .set("cashRounding", true).build()); MonetaryRounding roundingEUR = Monetary.getRounding( RoundingQueryBuilder.of() .setCurrency(eur) .set("cashRounding", true).build()); MonetaryRounding roundingSEK = Monetary.getRounding( RoundingQueryBuilder.of() .setCurrency(sek) .set("cashRounding", true).build()); System.out.println(MonetaryFormats.getAmountFormat(new Locale("ch", "")).format(Money.of(3459.97,chf))); System.out.println(MonetaryFormats.getAmountFormat(new Locale("ch", "")).format(Money.of(3459.97,chf).with(rounding))); System.out.println(MonetaryFormats.getAmountFormat(new Locale("de", "")).format(Money.of(3459.97,eur))); System.out.println(MonetaryFormats.getAmountFormat(new Locale("de", "")).format(Money.of(3459.97,eur).with(roundingEUR))); System.out.println(MonetaryFormats.getAmountFormat(new Locale("sv", "")).format(Money.of(3459.97,sek))); System.out.println(MonetaryFormats.getAmountFormat(new Locale("sv", "")).format(Money.of(3459.97,sek).with(roundingSEK))); }
Example #6
Source File: MoneyAlgorithmicsTest.java From javamoney-examples with Apache License 2.0 | 5 votes |
/** * Implement a {@link javax.money.MonetaryQuery} that return {@code true} for each amount, that has an ISO * currency (as available on {@link java.util.Currency}. */ @Test public void testCountingQuery(){ MonetaryQuery<Boolean> query = alg.getCountingQuery(); assertTrue(Money.of(2, "CHF").query(query)); assertFalse(FastMoney.of(4.5, CurrencyUnitBuilder.of("GEEC", CURENCY_CONTEXT).build()).query(query)); assertTrue(Money.of(10, "INR").query(query)); assertFalse(FastMoney.of(-1.5, CurrencyUnitBuilder.of("2xx2", CURENCY_CONTEXT).build()).query(query)); }
Example #7
Source File: CurrenciesAccess.java From javamoney-examples with Apache License 2.0 | 5 votes |
/** * @param args */ public static void main(String[] args) { ConsoleUtils.printDetails(Monetary.getCurrency("CHF")); Monetary.getCurrencies(CurrencyQueryBuilder.of().setProviderNames("ConfigurableCurrencyUnitProvider").build()).forEach( ConsoleUtils::printDetails ); CurrencyUnitBuilder.of("Devoxx", "Devoxx-Conference").build(true); Monetary.getCurrencies(CurrencyQueryBuilder.of().setProviderNames("ConfigurableCurrencyUnitProvider").build()).forEach( ConsoleUtils::printDetails ); }
Example #8
Source File: CurrenciesUseBuilder.java From javamoney-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ConsoleUtils.printDetails( CurrencyUnitBuilder.of("DevoxxFranc", "BuildingCurrenciesExample").setCurrencyCode("DXF").setDefaultFractionDigits(2).build()); Monetary.getCurrencies(CurrencyQueryBuilder.of().setProviderNames("ConfigurableCurrencyUnitProvider").build()).forEach( ConsoleUtils::printDetails ); ConsoleUtils.printDetails( CurrencyUnitBuilder.of("DevoxxFranc", "BuildingCurrenciesExample").setCurrencyCode("DXF").setDefaultFractionDigits(2).build(true)); }
Example #9
Source File: BitcoinCurrencyProvider.java From consensusj with Apache License 2.0 | 4 votes |
public BitcoinCurrencyProvider() { CurrencyUnit btcUnit = CurrencyUnitBuilder.of("BTC", CONTEXT) .setDefaultFractionDigits(bitcoinFractionDigits) .build(); bitcoinSet = Collections.singleton(btcUnit); }
Example #10
Source File: CDITestCurrencyProvider.java From javamoney-lib with Apache License 2.0 | 4 votes |
public CDITestCurrencyProvider() { currencies.add(CurrencyUnitBuilder.of("CDITest", "CDITestCurrencyProvider").build()); currencies = Collections.unmodifiableSet(currencies); }
Example #11
Source File: GeeConCurrencyProvider.java From javamoney-examples with Apache License 2.0 | 4 votes |
public GeeConCurrencyProvider(){ currencies.add(CurrencyUnitBuilder.of("GeeCon1",context ).setDefaultFractionDigits(1).build()); currencies.add(CurrencyUnitBuilder.of("GeeCon2",context ).setDefaultFractionDigits(2).build()); currencies.add(CurrencyUnitBuilder.of("GeeCon3",context ).setDefaultFractionDigits(3).build()); currencies = Collections.unmodifiableSet(currencies); }
Example #12
Source File: GeeConCurrencyProvider.java From javamoney-examples with Apache License 2.0 | 4 votes |
public GeeConCurrencyProvider(){ currencies.add(CurrencyUnitBuilder.of("GeeCon1",context ).setDefaultFractionDigits(1).build()); currencies.add(CurrencyUnitBuilder.of("GeeCon2",context ).setDefaultFractionDigits(2).build()); currencies.add(CurrencyUnitBuilder.of("GeeCon3",context ).setDefaultFractionDigits(3).build()); currencies = Collections.unmodifiableSet(currencies); }