Search in sources :

Example 11 with Money

use of org.javamoney.moneta.Money in project tutorials by eugenp.

the class JavaMoneyUnitManualTest method givenArithmetic_whenStringified_thanEqualsAmount.

@Test
public void givenArithmetic_whenStringified_thanEqualsAmount() {
    CurrencyUnit usd = Monetary.getCurrency("USD");
    Money moneyof = Money.of(12, usd);
    MonetaryAmount fstAmtUSD = Monetary.getDefaultAmountFactory().setCurrency(usd).setNumber(200.50).create();
    MonetaryAmount oneDolar = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(1).create();
    Money subtractedAmount = Money.of(1, "USD").subtract(fstAmtUSD);
    MonetaryAmount multiplyAmount = oneDolar.multiply(0.25);
    MonetaryAmount divideAmount = oneDolar.divide(0.25);
    assertEquals("USD", usd.toString());
    assertEquals("USD 1", oneDolar.toString());
    assertEquals("USD 200.5", fstAmtUSD.toString());
    assertEquals("USD 12", moneyof.toString());
    assertEquals("USD -199.5", subtractedAmount.toString());
    assertEquals("USD 0.25", multiplyAmount.toString());
    assertEquals("USD 4", divideAmount.toString());
}
Also used : FastMoney(org.javamoney.moneta.FastMoney) Money(org.javamoney.moneta.Money) CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.junit.Test)

Example 12 with Money

use of org.javamoney.moneta.Money in project tutorials by eugenp.

the class JavaMoneyUnitManualTest method givenAmounts_whenSummed_thanCorrect.

@Test
public void givenAmounts_whenSummed_thanCorrect() {
    List<MonetaryAmount> monetaryAmounts = Arrays.asList(Money.of(100, "CHF"), Money.of(10.20, "CHF"), Money.of(1.15, "CHF"));
    Money sumAmtCHF = (Money) monetaryAmounts.stream().reduce(Money.of(0, "CHF"), MonetaryAmount::add);
    assertEquals("CHF 111.35", sumAmtCHF.toString());
}
Also used : FastMoney(org.javamoney.moneta.FastMoney) Money(org.javamoney.moneta.Money) MonetaryAmount(javax.money.MonetaryAmount) Test(org.junit.Test)

Example 13 with Money

use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.

the class StreamFactory method currenciesToSummary.

public static Stream<MonetaryAmount> currenciesToSummary() {
    Money r1 = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    Money r2 = Money.of(BigDecimal.ZERO, BRAZILIAN_REAL);
    Money r3 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r4 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r5 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r6 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r7 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r8 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money e1 = Money.of(BigDecimal.TEN, EURO);
    Money d1 = Money.of(BigDecimal.ONE, DOLLAR);
    return Stream.of(r1, r2, r3, r4, r5, r6, r7, r8, e1, d1);
}
Also used : Money(org.javamoney.moneta.Money)

Example 14 with Money

use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.

the class StreamFactory method streamCurrencyDifferent.

public static Stream<MonetaryAmount> streamCurrencyDifferent() {
    Money m1 = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    Money m2 = Money.of(BigDecimal.ZERO, BRAZILIAN_REAL);
    Money m3 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money m4 = Money.of(BigDecimal.valueOf(4L), EURO);
    Money m5 = Money.of(BigDecimal.valueOf(5L), BRAZILIAN_REAL);
    return Stream.of(m1, m2, m3, m4, m5);
}
Also used : Money(org.javamoney.moneta.Money)

Example 15 with Money

use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.

the class StreamFactory method currenciesToSummary.

public static Stream<MonetaryAmount> currenciesToSummary() {
    Money r1 = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    Money r2 = Money.of(BigDecimal.ZERO, BRAZILIAN_REAL);
    Money r3 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r4 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r5 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r6 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r7 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money r8 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
    Money e1 = Money.of(BigDecimal.TEN, EURO);
    Money d1 = Money.of(BigDecimal.ONE, DOLLAR);
    return Stream.of(r1, r2, r3, r4, r5, r6, r7, r8, e1, d1);
}
Also used : Money(org.javamoney.moneta.Money)

Aggregations

Money (org.javamoney.moneta.Money)31 AttributeMoney (life.genny.qwanda.attribute.AttributeMoney)7 CurrencyUnit (javax.money.CurrencyUnit)4 MonetaryAmount (javax.money.MonetaryAmount)4 FastMoney (org.javamoney.moneta.FastMoney)4 Test (org.junit.Test)4 BaseEntity (life.genny.qwanda.entity.BaseEntity)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Scanner (java.util.Scanner)2 Answer (life.genny.qwanda.Answer)2 QRules (life.genny.rules.QRules)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CurrencyConversion (javax.money.convert.CurrencyConversion)1 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)1 MonetaryAmountFormat (javax.money.format.MonetaryAmountFormat)1 AttributeBoolean (life.genny.qwanda.attribute.AttributeBoolean)1