• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MonetaryOperator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.money.MonetaryOperator的典型用法代码示例。如果您正苦于以下问题:Java MonetaryOperator类的具体用法?Java MonetaryOperator怎么用?Java MonetaryOperator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MonetaryOperator类属于javax.money包,在下文中一共展示了MonetaryOperator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: apply

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
    MonetaryOperator minorRounding = Monetary
            .getRounding(RoundingQueryBuilder.of().set("scale", 2).set(RoundingMode.HALF_UP).build());
    MonetaryAmount amt = amount.with(minorRounding);
    MonetaryAmount mp = amt.with(MonetaryOperators.minorPart());
    if (mp.isGreaterThanOrEqualTo(
            Monetary.getDefaultAmountFactory().setCurrency(amount.getCurrency()).setNumber(0.03)
                    .create())) {
        // add
        return amt.add(Monetary.getDefaultAmountFactory().setCurrency(amt.getCurrency())
                .setNumber(new BigDecimal("0.05")).create().subtract(mp));
    } else {
        // subtract
        return amt.subtract(mp);
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:TestRoundingProvider.java


示例2: main

import javax.money.MonetaryOperator; //导入依赖的package包/类
public  static void main(String[] args) {
    CurrencyUnit currency = Monetary.getCurrency("BRL");
    MonetaryAmount money = FastMoney.of(10, currency);
    MonetaryOperator doubleOperator = m -> m.multiply(2);
    MonetaryAmount result = doubleOperator.apply(money);//BRL 20.00000
    MonetaryAmount result2 = result.with(doubleOperator);//BRL 40.00000
}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:HelloMonetaryOperator.java


示例3: RoundedMoney

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Deprecated
public RoundedMoney(Number number, CurrencyUnit currency, MonetaryContext context, MonetaryOperator rounding) {
    Objects.requireNonNull(currency, "Currency is required.");
    this.currency = currency;
    Objects.requireNonNull(number, "Number is required.");
    checkNumber(number);
    MonetaryContextBuilder monetaryContextBuilder = DEFAULT_MONETARY_CONTEXT.toBuilder();
    if (context != null) {
        monetaryContextBuilder.importContext(context);
    }
    this.rounding = RoundedMoneyMonetaryOperatorFactory.INSTANCE.getDefaultMonetaryOperator(rounding, monetaryContextBuilder.build());
    monetaryContextBuilder.set(MONETARY_ROUNDING_KEY, this.rounding);

    this.monetaryContext = monetaryContextBuilder.build();
    this.number = MoneyUtils.getBigDecimal(number, monetaryContext);
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:17,代码来源:RoundedMoney.java


示例4: testGetCashRoundingCurrencyUnit

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.CurrencyUnit, String...)} for cash ropundings.
 * .
 */
@Test
public void testGetCashRoundingCurrencyUnit() {
    MonetaryOperator r = Monetary.getRounding(
            RoundingQueryBuilder.of().setCurrency(Monetary.getCurrency("GBP")).set("cashRounding", true)
                    .build());
    assertNotNull(r);
    r = Monetary.getRounding(
            RoundingQueryBuilder.of().setCurrency(Monetary.getCurrency("CHF")).set("cashRounding", true)
                    .build());
    assertNotNull(r);
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(2).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(2.02).create().with(r));
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(2.05).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(2.025).create().with(r));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:21,代码来源:MonetaryRoundingsTest.java


示例5: shouldReturnMathContextOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnMathContextOperator() {
	int precision = 6;
	RoundingMode roundingMode = RoundingMode.HALF_EVEN;
	MonetaryRoundedFactory factory = MonetaryRoundedFactory
			.withRoundingMode(roundingMode).withPrecision(precision)
			.build();

	assertNotNull(factory);
	MonetaryOperator roundingOperator = factory.getRoundingOperator();
	assertNotNull(roundingOperator);
	assertTrue(PrecisionContextRoundedOperator.class.isInstance(roundingOperator));
	MathContext result = PrecisionContextRoundedOperator.class.cast(roundingOperator).getMathContext();

	assertEquals(precision, result.getPrecision());
	assertEquals(roundingMode, result.getRoundingMode());

}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:19,代码来源:MonetaryRoundedFactoryBuilderTest.java


示例6: shouldReturnScaleRoundingOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnScaleRoundingOperator() {
	int scale = 6;
	RoundingMode roundingMode = RoundingMode.HALF_EVEN;
	MonetaryRoundedFactory factory = MonetaryRoundedFactory
			.withRoundingMode(roundingMode).withScale(scale)
			.build();

	assertNotNull(factory);
	MonetaryOperator roundingOperator = factory.getRoundingOperator();
	assertNotNull(roundingOperator);
	assertTrue(ScaleRoundedOperator.class.isInstance(roundingOperator));
	ScaleRoundedOperator result = ScaleRoundedOperator.class.cast(roundingOperator);

	assertEquals(scale, result.getScale());
	assertEquals(roundingMode, result.getRoundingMode());

}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:19,代码来源:MonetaryRoundedFactoryBuilderTest.java


示例7: shouldReturnMathContextScaleOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnMathContextScaleOperator() {
	int precision = 6;
	int scale = 3;
	RoundingMode roundingMode = RoundingMode.HALF_EVEN;
	MonetaryRoundedFactory factory = MonetaryRoundedFactory
			.withRoundingMode(roundingMode).withPrecision(precision).withScale(scale)
			.build();

	assertNotNull(factory);
	MonetaryOperator roundingOperator = factory.getRoundingOperator();
	assertNotNull(roundingOperator);
	assertTrue(PrecisionScaleRoundedOperator.class.isInstance(roundingOperator));
	PrecisionScaleRoundedOperator result = PrecisionScaleRoundedOperator.class.cast(roundingOperator);

	assertEquals(precision, result.getMathContext().getPrecision());
	assertEquals(scale, result.getScale());
	assertEquals(roundingMode, result.getMathContext().getRoundingMode());

}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:21,代码来源:MonetaryRoundedFactoryBuilderTest.java


示例8: shouldReturnScaleMathContextOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnScaleMathContextOperator() {
	int precision = 6;
	int scale = 3;
	RoundingMode roundingMode = RoundingMode.HALF_EVEN;
	MonetaryRoundedFactory factory = MonetaryRoundedFactory
			.withRoundingMode(roundingMode).withScale(scale).withPrecision(precision)
			.build();

	assertNotNull(factory);
	MonetaryOperator roundingOperator = factory.getRoundingOperator();
	assertNotNull(roundingOperator);
	assertTrue(PrecisionScaleRoundedOperator.class.isInstance(roundingOperator));
	PrecisionScaleRoundedOperator result = PrecisionScaleRoundedOperator.class.cast(roundingOperator);

	assertEquals(precision, result.getMathContext().getPrecision());
	assertEquals(scale, result.getScale());
	assertEquals(roundingMode, result.getMathContext().getRoundingMode());

}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:21,代码来源:MonetaryRoundedFactoryBuilderTest.java


示例9: otherOperations

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Test
public void otherOperations() {
    CurrencyUnit euro = Monetary.getCurrency("EUR");

    MonetaryAmount amount = FastMoney.of(150, euro);
    FastMoney money = FastMoney.of(150, "EUR");
    assertEquals(amount, money);

    FastMoney third = money.divide(3);
    assertEquals(third, FastMoney.of(50, euro));

    MonetaryOperator tenPercent = MonetaryOperators.percent(10);
    FastMoney tenPercentValue = money.with(tenPercent);
    assertEquals(tenPercentValue, FastMoney.of(15, "EUR"));

    // excellent comparison functions:
    //money.isZero()

    //MonetaryFunctions

    Log.d("test", "the end, debug manually");
}
 
开发者ID:moneymanagerex,项目名称:android-money-manager-ex,代码行数:23,代码来源:JavaMoneyTests.java


示例10: testOfAndApply

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Method: of(Rate rate, int periods)
 */
@Test
public void testOfAndApply() throws Exception {
    Money money = Money.of(100, "CHF");
    MonetaryOperator rounding = Monetary.getRounding(RoundingQueryBuilder.of().setScale(2).set(RoundingMode.HALF_EVEN)
            .build());
    assertEquals(Money.of(BigDecimal.valueOf(95.12), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(0.05), 1)).with(rounding));
    assertEquals(Money.of(BigDecimal.valueOf(90.48), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(0.05), 2)).with(rounding));
    assertEquals(Money.of(BigDecimal.valueOf(46.3), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(0.07), 11)).with(rounding));

    assertEquals(Money.of(BigDecimal.valueOf(100.00), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(0.05), 0)).with(rounding));
    assertEquals(Money.of(BigDecimal.valueOf(100.00), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(-0.05), 0)).with(rounding));

    assertEquals(Money.of(BigDecimal.valueOf(105.13), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(-0.05), 1)).with(rounding));
    assertEquals(Money.of(BigDecimal.valueOf(110.52), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(-0.05), 2)).with(rounding));
    assertEquals(Money.of(BigDecimal.valueOf(215.98), "CHF"), money.with(PresentValueContinuousCompounding.of(Rate.of(-0.07), 11)).with(rounding));
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:20,代码来源:PresentValueContinuousCompoundingTest.java


示例11: testWithMonetaryOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for {@link org.javamoney.moneta.FastMoney#with(javax.money.MonetaryOperator)} .
 */
@Test
public void testWithMonetaryOperator() {
    MonetaryOperator adj = amount -> FastMoney.of(-100, amount.getCurrency());
    FastMoney m = FastMoney.of(new BigDecimal("1.2345"), "XXX");
    FastMoney a = m.with(adj);
    assertNotNull(a);
    assertNotSame(m, a);
    assertEquals(m.getCurrency(), a.getCurrency());
    assertEquals(FastMoney.of(-100, m.getCurrency()), a);
    adj = amount -> amount.multiply(2).getFactory().setCurrency(Monetary.getCurrency("CHF")).create();
    a = m.with(adj);
    assertNotNull(a);
    assertNotSame(m, a);
    assertEquals(Monetary.getCurrency("CHF"), a.getCurrency());
    assertEquals(FastMoney.of(1.2345 * 2, a.getCurrency()), a);
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:20,代码来源:FastMoneyTest.java


示例12: main

import javax.money.MonetaryOperator; //导入依赖的package包/类
public  static void main(String[] args) {
    MonetaryOperator doubleOperator = m -> m.multiply(2);
    MonetaryOperator halfOperator = m -> m.divide(2);
    MonetaryOperator operator = m -> {
        if(m.isPositive()){
            return m.multiply(2);
        }
        return m.divide(2);
    };
}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:MonetaryOperatorExamples.java


示例13: testPercentToString

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link org.javamoney.moneta.function.MonetaryOperators#percent(java.lang.Number)}
 * .
 */
@Test
public void testPercentToString() {
	MonetaryOperator p = MonetaryOperators.percent((short) 25);
	assertTrue(p.toString().contains("25"));
	assertTrue(p.toString().contains("%"));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:MonetaryOperatorsTest.java


示例14: testGetRoundingIntRoundingMode

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.RoundingQuery)} for arithmetic rounding.
 * .
 */
@Test
public void testGetRoundingIntRoundingMode() {
    MonetaryAmount[] samples = new MonetaryAmount[]{
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("0.0000000001"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("1.00000000000023")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.1123442323"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.50000000000"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("-1.000000003"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("-1.100232876532876389")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF")
                    .setNumber(new BigDecimal("-1.500000000000")).create()};
    int[] scales = new int[]{0, 1, 2, 3, 4, 5};
    for (MonetaryAmount sample : samples) {
        for (int scale : scales) {
            for (RoundingMode roundingMode : RoundingMode.values()) {
                if (roundingMode == RoundingMode.UNNECESSARY) {
                    continue;
                }
                MonetaryOperator rounding = Monetary
                        .getRounding(RoundingQueryBuilder.of().setScale(scale).set(roundingMode).build());
                BigDecimal dec = sample.getNumber().numberValue(BigDecimal.class);
                BigDecimal expected = dec.setScale(scale, roundingMode);
                MonetaryAmount r = sample.with(rounding);
                assertEquals(
                        Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(expected).create(),
                        r);
            }
        }
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:40,代码来源:MonetaryRoundingsTest.java


示例15: testGetRoundingCurrencyUnit

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.CurrencyUnit, String...)}
 * .
 */
@Test
public void testGetRoundingCurrencyUnit() {
    MonetaryAmount[] samples = new MonetaryAmount[]{
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("0.0000000001"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("1.00000000000023")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.1123442323"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.50000000000"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("-1.000000003"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("-1.100232876532876389")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF")
                    .setNumber(new BigDecimal("-1.500000000000")).create()};
    for (MonetaryAmount sample : samples) {
        for (Currency currency : Currency.getAvailableCurrencies()) {
            CurrencyUnit cur = Monetary.getCurrency(currency.getCurrencyCode());
            // Omit test roundings, which are for testing only...
            if ("XXX".equals(cur.getCurrencyCode())) {
                continue;
            } else if ("CHF".equals(cur.getCurrencyCode())) {
                continue;
            }
            MonetaryOperator rounding = Monetary.getRounding(cur);
            BigDecimal dec = sample.getNumber().numberValue(BigDecimal.class);
            BigDecimal expected;
            if (cur.getDefaultFractionDigits() < 0) {
                expected = dec.setScale(0, RoundingMode.HALF_UP);
            } else {
                expected = dec.setScale(cur.getDefaultFractionDigits(), RoundingMode.HALF_UP);
            }
            MonetaryAmount r = sample.with(rounding);
            assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(expected).create(),
                    r, "Rouding for: " + sample);
        }
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:44,代码来源:MonetaryRoundingsTest.java


示例16: testGetRoundingCurrencyUnitLong

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.RoundingQuery)} with timestamps.
 * .
 */
@Test
public void testGetRoundingCurrencyUnitLong() {
    Calendar date = GregorianCalendar.getInstance();
    date.add(Calendar.DAY_OF_YEAR, 1);
    MonetaryOperator r = Monetary.getRounding(
            RoundingQueryBuilder.of().setCurrency(Monetary.getCurrency("XXX"))
                    .set(date).build());
    assertNotNull(r);
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("XXX").setNumber(-1).create(),
            Monetary.getDefaultAmountFactory().setCurrency("XXX").setNumber(2.0234343).create()
                    .with(r));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:MonetaryRoundingsTest.java


示例17: testGetCashRoundingCurrencyUnitLong

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.RoundingQuery)} with cashRounding, timestamps.
 * .
 */
@Test
public void testGetCashRoundingCurrencyUnitLong() {
    Calendar date = GregorianCalendar.getInstance();
    date.add(Calendar.DAY_OF_YEAR, 1);
    MonetaryOperator r = Monetary.getRounding(
            RoundingQueryBuilder.of().setCurrency(Monetary.getCurrency("XXX"))
                    .set(date).set("cashRounding", true).build());
    assertNotNull(r);
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(-1).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(2.0234343).create()
                    .with(r));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:MonetaryRoundingsTest.java


示例18: testGetRoundingString

import javax.money.MonetaryOperator; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(String, String...)}.
 */
@Test
public void testGetRoundingString() {
    assertNotNull(Monetary.getRounding("zero"));
    assertNotNull(Monetary.getRounding("minusOne"));
    assertNotNull(Monetary.getRounding("CHF-cash"));
    MonetaryOperator minusOne = Monetary.getRounding("minusOne");
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(-1).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(213873434.3463843847)
                    .create().with(minusOne));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:15,代码来源:MonetaryRoundingsTest.java


示例19: shouldReturnTheSameMonetaryOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnTheSameMonetaryOperator() {
	MonetaryOperator monetaryOperator = new MonetaryOperator() {

		@Override
		public MonetaryAmount apply(MonetaryAmount amount) {
			return amount;
		}
	};
	MonetaryRoundedFactory factory = MonetaryRoundedFactory.of(monetaryOperator);
	assertNotNull(factory);
	assertEquals(monetaryOperator, factory.getRoundingOperator());

}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:15,代码来源:MonetaryRoundedFactoryBuilderTest.java


示例20: CompositeMonetaryOperator

import javax.money.MonetaryOperator; //导入依赖的package包/类
@SafeVarargs
public CompositeMonetaryOperator(Iterable<MonetaryOperator>... operations) {
    if (operations != null) {
        for (Iterable<MonetaryOperator> iterable : operations) {
            for (MonetaryOperator monetaryOperator : iterable) {
                functions.add(monetaryOperator);
            }
        }
    }
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:11,代码来源:CompositeMonetaryOperator.java



注:本文中的javax.money.MonetaryOperator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectUtil类代码示例发布时间:2022-05-23
下一篇:
Java FOAF类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap