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

Java CurrencyUnit类代码示例

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

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



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

示例1: shouldGroupByCorrectly

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Test
public void shouldGroupByCorrectly() {
	GroupMonetarySummaryStatistics group = createGroupMonetary();

	Map<CurrencyUnit, MonetarySummaryStatistics> map = group.get();
	Assert.assertEquals(map.keySet().size(), 3);
	Assert.assertNotNull(map.get(BRAZILIAN_REAL));
	Assert.assertNotNull(map.get(EURO));
	Assert.assertNotNull(map.get(DOLLAR));

	MonetarySummaryStatistics brazilianSummary = map
			.get(BRAZILIAN_REAL);
	verifySummary(brazilianSummary, 15, 30, 2L);

	MonetarySummaryStatistics euroSummary = map.get(EURO);
	verifySummary(euroSummary, 50, 100, 2L);

	MonetarySummaryStatistics dollarSummary = map.get(DOLLAR);
	verifySummary(dollarSummary, 60, 120, 2L);

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


示例2: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit dollar = Monetary.getCurrency("USD");
    CurrencyUnit real = Monetary.getCurrency("BRL");



    MonetaryAmount money = Money.of(10, dollar);
    MonetaryAmount money2 = Money.of(10, real);
    MonetaryAmount money3 = Money.of(10, dollar);
    MonetaryAmount money4 = Money.of(9, real);
    MonetaryAmount money5 = Money.of(25, dollar);

    GroupMonetarySummaryStatistics grouped = Stream.of(money, money2, money3, money4, money5)
    .collect(MonetaryFunctions.groupBySummarizingMonetary());
    Map<CurrencyUnit, MonetarySummaryStatistics> mapSummary = grouped.get();
    MonetarySummaryStatistics summary = mapSummary.get(dollar);

    MonetaryAmount min = summary.getMin();//USD 10
    MonetaryAmount max = summary.getMax();//USD 25
    MonetaryAmount average = summary.getAverage();//USD 15
    long count = summary.getCount();//3
    MonetaryAmount sum = summary.getSum();//USD 45

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:25,代码来源:AggregateGroupSummaringMonetaryAmount.java


示例3: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit dollar = Monetary.getCurrency("USD");
    CurrencyUnit euro = Monetary.getCurrency("EUR");
    CurrencyUnit real = Monetary.getCurrency("BRL");

    MonetaryAmount money = Money.of(9, euro);
    MonetaryAmount money2 = Money.of(10, dollar);
    MonetaryAmount money3 = Money.of(11, real);

    List<MonetaryAmount> resultAsc = Stream.of(money, money2, money3)
            .sorted(MonetaryFunctions
                    .sortCurrencyUnit()).collect(Collectors.toList());//[BRL 11, EUR 9, USD 10]
    List<MonetaryAmount> resultDesc = Stream.of(money, money2, money3)
            .sorted(MonetaryFunctions
                    .sortCurrencyUnitDesc()).collect(Collectors.toList());//[USD 10, EUR 9, BRL 11]

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:18,代码来源:SortMonetaryAmountCurrency.java


示例4: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit dollar = Monetary.getCurrency("USD");
    CurrencyUnit euro = Monetary.getCurrency("EUR");
    CurrencyUnit real = Monetary.getCurrency("BRL");

    MonetaryAmount money = Money.of(9, euro);
    MonetaryAmount money2 = Money.of(10, dollar);
    MonetaryAmount money3 = Money.of(11, real);

    ExchangeRateProvider provider =
            MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);

    ;
    List<MonetaryAmount> resultAsc = Stream.of(money, money2, money3)
            .sorted(MonetaryFunctions
                    .sortValuable(provider))
            .collect(Collectors.toList());//[BRL 11, EUR 9, USD 10]

    List<MonetaryAmount> resultDesc = Stream.of(money, money2, money3)
            .sorted(MonetaryFunctions
                    .sortValuableDesc(provider)).collect(Collectors.toList());//[USD 10, EUR 9, BRL 11]

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:24,代码来源:SortMonetaryAmountExchange.java


示例5: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit dollar = Monetary.getCurrency("USD");



    MonetaryAmount money = Money.of(10, dollar);
    MonetaryAmount money2 = Money.of(10, dollar);
    MonetaryAmount money3 = Money.of(10, dollar);
    MonetaryAmount money4 = Money.of(9, dollar);
    MonetaryAmount money5 = Money.of(8, dollar);

    List<MonetaryAmount> greaterThanZero = Stream.of(money, money2, money3, money4, money5)
            .filter(MonetaryFunctions.isGreaterThan(Money.zero(dollar)))
            .collect(Collectors.toList());//[USD 10, USD 10, USD 10, USD 9, USD 8]

    boolean hasAnyGreaterThanZero = Stream.of(money, money2, money3, money4, money5)
            .anyMatch(MonetaryFunctions.isGreaterThan(Money.zero(dollar)));//true

    boolean allBetweenZeroAndTen = Stream.of(money, money2, money3, money4, money5)
            .allMatch(MonetaryFunctions.isBetween(Money.zero(dollar),
                    Money.of(BigDecimal.TEN, dollar)));//true

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:24,代码来源:PredicateMonetaryAmountNumberValue.java


示例6: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit currency = Monetary.getCurrency("BRL");
    CurrencyUnit dollar = Monetary.getCurrency(Locale.US);

    MonetaryAmount money = Money.of(120.231, currency);

    MonetaryAmount majorPartResult = money.with(MonetaryOperators.majorPart());//BRL 120
    MonetaryAmount minorPartResult = money.with(MonetaryOperators.minorPart());//BRL 0.231
    MonetaryAmount percentResult = money.with(MonetaryOperators.percent(20));//BRL 24.0462
    MonetaryAmount permilResult = money.with(MonetaryOperators.permil(100));//BRL 12.0231
    MonetaryAmount roundingResult = money.with(MonetaryOperators.rounding());//BRL 120.23
    MonetaryAmount resultExchange = money.with(ConversionOperators.exchange(dollar));//USD 120.231
}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:14,代码来源:MonetaryOperatorsExample.java


示例7: RoundedMoney

import javax.money.CurrencyUnit; //导入依赖的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


示例8: shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Test
public void shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney() {
	int scale = 3;
	int precision = 5;

	CurrencyUnit real = Monetary.getCurrency("BRL");
	BigDecimal valueOf = BigDecimal.valueOf(35.34567);
	MonetaryAmount money = Money.of(valueOf, real);

	MathContext mathContext = new MathContext(precision, RoundingMode.HALF_EVEN);
	PrecisionScaleRoundedOperator monetaryOperator = PrecisionScaleRoundedOperator.of(scale, mathContext);

	MonetaryAmount result = monetaryOperator.apply(money);
	assertTrue(RoundedMoney.class.isInstance(result));
	assertEquals(result.getCurrency(), real);
	assertEquals(result.getNumber().getScale(), scale);
	assertEquals(result.getNumber().getPrecision(), precision);
	assertEquals(BigDecimal.valueOf(35.346), result.getNumber().numberValue(BigDecimal.class));



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


示例9: computeNextHopLocalTransferAmount

import javax.money.CurrencyUnit; //导入依赖的package包/类
/**
 * Given a source transfer, compute the amount (in local units of the destination ledger) that should be transferred
 * to the next-hop local ledger.
 *
 * @param sourceTransfer          A {@link Transfer} with information from the incoming source transfer delivered to
 *                                this connector as part of a broader Interledger payment.
 * @param destinationLedgerPrefix An {@link InterledgerAddress} prefix for the destination ledger that the next-hop
 *                                tranfser will be delivered on.
 */
@VisibleForTesting
protected BigInteger computeNextHopLocalTransferAmount(
    final Transfer sourceTransfer,
    final InterledgerAddress destinationLedgerPrefix
) {
  Objects.requireNonNull(sourceTransfer);
  InterledgerAddress.requireAddressPrefix(destinationLedgerPrefix);

  final CurrencyUnit baseCurrencyUnit = this.ledgerPluginManager.getLedgerPlugin(sourceTransfer.getLedgerPrefix())
      .map(LedgerPlugin::getLedgerInfo)
      .map(LedgerInfo::getCurrencyUnit)
      .orElseThrow(() -> new LedgerPluginNotConnectedException(sourceTransfer.getLedgerPrefix()));

  final CurrencyUnit terminatingCurrencyUnit = this.ledgerPluginManager.getLedgerPlugin(destinationLedgerPrefix)
      .map(LedgerPlugin::getLedgerInfo)
      .map(LedgerInfo::getCurrencyUnit)
      .orElseThrow(() -> new LedgerPluginNotConnectedException(destinationLedgerPrefix));

  // This method does not catch the CurrencyConversionException because there's nothing to be done if that occurs. It
  // means that FX is not configured between the source/destination ledgers.
  return Optional.ofNullable(this.fxEngine.getExchangeRate(baseCurrencyUnit, terminatingCurrencyUnit))
      .map(fxRate -> {
        final MonetaryAmount sourceTransferMonetaryAmount = Money.of(sourceTransfer.getAmount(), baseCurrencyUnit);
        final CurrencyConversion conversion = MonetaryConversions.getConversion(terminatingCurrencyUnit);
        final MonetaryAmount terminatingMonetaryAmount = sourceTransferMonetaryAmount.with(conversion);
        return terminatingMonetaryAmount;
      })
      // Convert from a MonetaryAmount back to an Integer...
      .map(MonetaryAmount::getNumber)
      .map(numberValue -> numberValue.numberValueExact(BigInteger.class))
      // This is allowed because if fxEngine.getExchangeRate can't find a rate, it will throw an exception!
      .get();
}
 
开发者ID:interledger,项目名称:java-ilp-connector,代码行数:43,代码来源:AbstractLedgerPluginEventHandler.java


示例10: getLedgerPluginConfig

import javax.money.CurrencyUnit; //导入依赖的package包/类
protected ExtendedLedgerPluginConfig getLedgerPluginConfig(final InterledgerAddress ledgerPrefix) {
  return new ExtendedLedgerPluginConfig() {

    @Override
    public LedgerPluginTypeId getLedgerPluginTypeId() {
      return LedgerPluginTypeId.of("ilp-plugin-mock");
    }

    @Override
    public InterledgerAddress getLedgerPrefix() {
      return ledgerPrefix;
    }

    @Override
    public InterledgerAddress getConnectorAccount() {
      return ledgerPrefix.with("connector");
    }

    @Override
    public CurrencyUnit getExpectedCurrencyUnit() {
      return Monetary.getCurrency("USD");
    }

    @Override
    public Map<String, String> getOptions() {
      return ImmutableMap.of();
    }

    @Override
    public String getPassword() {
      return "password";
    }
  };
}
 
开发者ID:interledger,项目名称:java-ilp-connector,代码行数:35,代码来源:AbstractLedgerPluginEventHandlerTest.java


示例11: getLedgerPluginConfig

import javax.money.CurrencyUnit; //导入依赖的package包/类
protected ExtendedLedgerPluginConfig getLedgerPluginConfig() {
  return new ExtendedLedgerPluginConfig() {

    @Override
    public LedgerPluginTypeId getLedgerPluginTypeId() {
      return LedgerPluginTypeId.of("ilp-plugin-mock");
    }

    @Override
    public InterledgerAddress getLedgerPrefix() {
      return LEDGER_PREFIX;
    }

    @Override
    public InterledgerAddress getConnectorAccount() {
      return CONNECTOR_ACCOUNT_ON_LEDGER;
    }

    @Override
    public CurrencyUnit getExpectedCurrencyUnit() {
      return Monetary.getCurrency("USD");
    }

    @Override
    public Map<String, String> getOptions() {
      return ImmutableMap.of();
    }

    @Override
    public String getPassword() {
      return "password";
    }
  };
}
 
开发者ID:interledger,项目名称:java-ilp-plugin,代码行数:35,代码来源:AbstractMockLedgerPluginTest.java


示例12: parse

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Override
public MonetaryAmount parse(String text, Locale locale) throws ParseException {
	CurrencyStyleFormatter formatter = new CurrencyStyleFormatter();
	Currency currency = determineCurrency(text, locale);
	CurrencyUnit currencyUnit = Monetary.getCurrency(currency.getCurrencyCode());
	formatter.setCurrency(currency);
	formatter.setPattern(this.pattern);
	Number numberValue = formatter.parse(text, locale);
	return Monetary.getDefaultAmountFactory().setNumber(numberValue).setCurrency(currencyUnit).create();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java


示例13: providePriceSelection

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Provides
@RequestScoped
public PriceSelection providePriceSelection(final CurrencyUnit currency, final CountryCode country,
                                            final CustomerInSession customerInSession) {
    return PriceSelection.of(currency)
            .withPriceCountry(country)
            .withPriceCustomerGroupId(customerInSession.findCustomerGroupId().orElse(null));
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:9,代码来源:Module.java


示例14: CartWithCreditCardFeeViewModelFactory

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Inject
public CartWithCreditCardFeeViewModelFactory(final CurrencyUnit currency, final PriceFormatter priceFormatter,
                                             final ShippingInfoViewModelFactory shippingInfoViewModelFactory,
                                             final PaymentInfoViewModelFactory paymentInfoViewModelFactory,
                                             final AddressViewModelFactory addressViewModelFactory,
                                             final LineItemExtendedViewModelFactory lineItemExtendedViewModelFactory) {
    super(currency, priceFormatter, shippingInfoViewModelFactory, paymentInfoViewModelFactory, addressViewModelFactory, lineItemExtendedViewModelFactory);
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:9,代码来源:CartWithCreditCardFeeViewModelFactory.java


示例15: decode

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Override
public MonetaryAmount decode(BsonReader reader, DecoderContext decoderContext) {
	reader.readStartDocument();
	CurrencyUnit currency = Monetary.getCurrency(reader.readString(this.currencyKey));
	BigDecimal number = new BigDecimal(
			BigInteger.valueOf(reader.readInt64(this.unscaledKey)),
			reader.readInt32(this.scaleKey));
	reader.readEndDocument();

	return Monetary.getDefaultAmountFactory().setNumber(number).setCurrency(currency)
			.create();
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:13,代码来源:MonetaryAmountDocumentCodec.java


示例16: shouldCreateSettingCurrencyUnit

import javax.money.CurrencyUnit; //导入依赖的package包/类
@Test
public void shouldCreateSettingCurrencyUnit() {
    CurrencyUnit currencyUnit = Monetary.getCurrency("BRL");
    MonetaryAmountDecimalFormat format = (MonetaryAmountDecimalFormat) MonetaryAmountDecimalFormatBuilder.newInstance().withProducer(new FastMoneyProducer())
            .withCurrencyUnit(currencyUnit).build();
    assertEquals(format.getCurrencyUnit(), currencyUnit);
    assertEquals(format.getProducer().getClass(), FastMoneyProducer.class);
    assertEquals(format.getDecimalFormat().getCurrency().getCurrencyCode(),format.getCurrencyUnit().getCurrencyCode());
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:10,代码来源:MonetaryAmountDecimalFormatBuilderTest.java


示例17: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit currency = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(BigDecimal.TEN, currency);
    MonetaryAmount money2 = FastMoney.of(BigDecimal.TEN, currency);
    MonetaryAmount addResult = money.add(money2);//BRL 20 Money implementation
    MonetaryAmount subtractResult = money2.subtract(addResult);//BRL -10 FastMoney implementation
}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:ArithmeticOperations.java


示例18: testCompareTo

import javax.money.CurrencyUnit; //导入依赖的package包/类
/**
 * Test Comparable method for
 * {@link javax.money.CurrencyUnit}s.
 */
@Test
public void testCompareTo() {
	CurrencyUnit cur1 = Monetary.getCurrency("USD");
	CurrencyUnit cur2 = Monetary.getCurrency("EUR");
	assertNotNull(cur1);
       assertNotNull(cur2);
	assertTrue(0 < cur1.compareTo(cur2));
	assertTrue(0 > cur2.compareTo(cur1));
	assertEquals(0, cur1.compareTo(cur1));
	assertEquals(0, cur2.compareTo(cur2));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:16,代码来源:CurrenciesTest.java


示例19: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
	MonetaryAmountFormat patternFormat = MonetaryAmountDecimalFormatBuilder.of("¤ ###,###.00").build();
	
    CurrencyUnit currency = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(12, currency);
    String format = patternFormat.format(money);//$ 12.00
    MonetaryAmount moneyParsed = Money.parse(format, patternFormat);//or using defafult.parse(format);

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:10,代码来源:MonetaryAmountDecimalFormatBuilderExample3.java


示例20: main

import javax.money.CurrencyUnit; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit currency = Monetary.getCurrency(Locale.US);
    MonetaryAmount money = Money.of(10, currency);
    MonetaryAmount money2 = FastMoney.of(20, currency);
    MonetaryAmount money3 = RoundedMoney.of(30, currency, MonetaryOperators.rounding());
    String text = money.toString();//USD 10
    String text2 = money2.toString();//USD 20
    String text3 = money3.toString();//USD 30
    MonetaryAmount result = Money.parse(text);
    MonetaryAmount result2 = FastMoney.parse(text2);
    MonetaryAmount result3 = RoundedMoney.parse(text3);

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:14,代码来源:ToStringExample.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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