本文整理汇总了Java中javax.money.CurrencyUnit类的典型用法代码示例。如果您正苦于以下问题:Java CurrencyUnit类的具体用法?Java CurrencyUnit怎么用?Java CurrencyUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CurrencyUnit类属于javax.money包,在下文中一共展示了CurrencyUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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]
}
示例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]
}
示例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
}
示例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
}
示例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);
}
示例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));
}
示例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();
}
示例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";
}
};
}
示例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";
}
};
}
示例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));
}
示例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();
}