本文整理汇总了Java中javax.money.MonetaryAmount类的典型用法代码示例。如果您正苦于以下问题:Java MonetaryAmount类的具体用法?Java MonetaryAmount怎么用?Java MonetaryAmount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MonetaryAmount类属于javax.money包,在下文中一共展示了MonetaryAmount类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldSetTimeInLocalDateTime
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime() {
Calendar localDate = GregorianCalendar.getInstance();
localDate.add(Calendar.DAY_OF_YEAR, -80);
localDate.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:20,代码来源:ECBHistoric90RateProviderTest.java
示例2: toProduct
import javax.money.MonetaryAmount; //导入依赖的package包/类
private Product toProduct(WebElement element) {
double discount;
MonetaryAmount newPrice;
String name = textOf(element, productName);
String label = textOf(element, productLabel);
String productPrice = textOf(element, productOldPrice);
MonetaryAmount oldPrice = productPrice != null ? moneyOf(productPrice) : zeroAmount();
if (label != null && !"NEW".equalsIgnoreCase(label)) {
discount = MoneyUtils.discountOf(label);
productPrice = textOf(element, productNewPrice);
newPrice = productPrice != null ? moneyOf(productPrice) : zeroAmount();
} else {
discount = zeroDiscount();
newPrice = zeroAmount();
}
return new Product(name != null ? name : "Unknown", oldPrice, newPrice, discount);
}
开发者ID:sskorol,项目名称:selenium-camp-17,代码行数:21,代码来源:Java7ProductsPage.java
示例3: configureFormatterFrom
import javax.money.MonetaryAmount; //导入依赖的package包/类
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) {
if (StringUtils.hasLength(annotation.pattern())) {
return new PatternDecoratingFormatter(resolveEmbeddedValue(annotation.pattern()));
}
else {
Style style = annotation.style();
if (style == Style.NUMBER) {
return new NumberDecoratingFormatter(new NumberStyleFormatter());
}
else if (style == Style.PERCENT) {
return new NumberDecoratingFormatter(new PercentStyleFormatter());
}
else {
return new NumberDecoratingFormatter(new CurrencyStyleFormatter());
}
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java
示例4: testWithNumber
import javax.money.MonetaryAmount; //导入依赖的package包/类
/**
* Test method for {@link Money#getFactory()#setNumber(java.lang.Number)}.
*/
@Test
public void testWithNumber() {
Money[] moneys = new Money[]{Money.of(100, "CHF"), Money.of(34242344, "CHF"),
Money.of(new BigDecimal("23123213.435"), "CHF"), Money.of(new BigDecimal("-23123213.435"), "CHF"),
Money.of(-23123213, "CHF"), Money.of(0, "CHF")};
Money s = Money.of(10, "CHF");
MonetaryAmount[] moneys2 =
new MonetaryAmount[]{s.getFactory().setCurrency(s.getCurrency()).setNumber(100).create(),
s.getFactory().setCurrency(s.getCurrency()).setNumber(34242344).create(),
s.getFactory().setCurrency(s.getCurrency()).setNumber(new BigDecimal("23123213.435")).create(),
s.getFactory().setCurrency(s.getCurrency()).setNumber(new BigDecimal("-23123213.435")).create(),
s.getFactory().setCurrency(s.getCurrency()).setNumber(-23123213).create(),
s.getFactory().setCurrency(s.getCurrency()).setNumber(0).create()};
for (int i = 0; i < moneys.length; i++) {
assertEquals(moneys[i], moneys2[i], "with(Number) failed.");
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:21,代码来源:MoneyTest.java
示例5: shouldSetTimeInLocalDateTime
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Test
public void shouldSetTimeInLocalDateTime() {
Calendar localDate = new GregorianCalendar(2014, Calendar.JANUARY, 9);
ConversionQuery conversionQuery = ConversionQueryBuilder.of()
.setTermCurrency(EURO).set(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), EURO);
assertTrue(result.getNumber().doubleValue() > 0);
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:18,代码来源:ECBHistoricRateProviderTest.java
示例6: testQuery
import javax.money.MonetaryAmount; //导入依赖的package包/类
/**
* Test method for
* {@link RoundedMoney#query(javax.money.MonetaryQuery)}
* .
*/
@Test
public void testQuery() {
MonetaryQuery<Integer> q = new MonetaryQuery<Integer>(){
@Override
public Integer queryFrom(MonetaryAmount amount) {
return RoundedMoney.from(amount).getPrecision();
}
};
RoundedMoney[] moneys = new RoundedMoney[]{RoundedMoney.of(100, "CHF"), RoundedMoney.of(34242344, "USD"),
RoundedMoney.of(23123213.435, "EUR"), RoundedMoney.of(-23123213.435, "USS"),
RoundedMoney.of(-23123213, "USN"), RoundedMoney.of(0, "GBP")};
for (RoundedMoney money : moneys) {
assertEquals(money.query(q), (Integer) money.getPrecision());
}
}
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:21,代码来源:RoundedMoneyTest.java
示例7: main
import javax.money.MonetaryAmount; //导入依赖的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
示例8: main
import javax.money.MonetaryAmount; //导入依赖的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);
MonetarySummaryStatistics summary = Stream.of(money, money2, money3, money4, money5)
.collect(MonetaryFunctions.summarizingMonetary(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,代码行数:23,代码来源:AggregateSummaringMonetaryAmount.java
示例9: main
import javax.money.MonetaryAmount; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit euro = Monetary.getCurrency("EUR");
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
MonetaryAmount money = Money.of(10, dollar);
MonetaryAmount money2 = Money.of(10, euro);
MonetaryAmount money3 = Money.of(10, dollar);
MonetaryAmount money4 = Money.of(9, euro);
MonetaryAmount money5 = Money.of(8, dollar);
Optional<MonetaryAmount> max = Stream.of(money, money2, money3, money4, money5).reduce(
MonetaryFunctions.max(provider));//javax.money.MonetaryException: Currency mismatch: BRL/USD
max.ifPresent(System.out::println);//EUR 10
Optional<MonetaryAmount> min = Stream.of(money, money2, money3, money4, money5).reduce(
MonetaryFunctions.min(provider));
min.ifPresent(System.out::println);//USD 8
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:21,代码来源:ReduceMaxMinMonetaryAmountExchange.java
示例10: main
import javax.money.MonetaryAmount; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
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);
MonetarySummaryStatistics summary = Stream.of(money, money2, money3, money4, money5)
.collect(ConversionOperators.summarizingMonetary(dollar, provider));
MonetaryAmount min = summary.getMin();//USD 2.831248
MonetaryAmount max = summary.getMax();//USD 25
MonetaryAmount average = summary.getAverage();//USD 10.195416
long count = summary.getCount();//5
MonetaryAmount sum = summary.getSum();//50.97708
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:24,代码来源:AggregateSummaringExchangeRateMonetaryAmount.java
示例11: main
import javax.money.MonetaryAmount; //导入依赖的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
示例12: main
import javax.money.MonetaryAmount; //导入依赖的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
示例13: computeNextHopLocalTransferAmount
import javax.money.MonetaryAmount; //导入依赖的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
示例14: act
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
try {
JsonReader reader = Json.createReader(req.body());
JsonObject json = reader.readObject();
String name = json.getString("name");
String desc = json.getString("desc");
MonetaryAmount price = FastMoney.of(new BigDecimal(json.getString("price")), "CZK");
Product result = base.products().add(name, desc, price);
return new RsJson(result);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:15,代码来源:TkProductAdd.java
示例15: price
import javax.money.MonetaryAmount; //导入依赖的package包/类
private MonetaryAmount price() {
try {
return FastMoney.of(
new BigDecimal(
new JdbcSession(dBase)
.sql("SELECT price FROM product WHERE id=?")
.set(this.number)
.select(new SingleOutcome<>(String.class))),
"CZK");
} catch (SQLException e) {
return ExceptionUtils.rethrow(e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:14,代码来源:H2Product.java
示例16: update
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Override
public Product update(String name, String desc, MonetaryAmount price) {
try {
new JdbcSession(dBase)
.sql("UPDATE product SET name=?, desc=?, price=? WHERE id=?")
.set(name)
.set(desc)
.set(price.getNumber())
.set(this.number)
.update(Outcome.VOID);
return new H2Product(dBase, this.number);
} catch (SQLException e) {
return ExceptionUtils.rethrow(e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:16,代码来源:H2Product.java
示例17: add
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Override
public Product add(String name, String desc, MonetaryAmount price) {
try {
return new H2Product(dBase,
new JdbcSession(this.dBase)
.sql("INSERT INTO product (name, desc, price) VALUES (?, ?, ?)")
.set(name)
.set(desc)
.set(price.getNumber())
.insert(new SingleOutcome<>(Long.class)));
} catch (SQLException e) {
return ExceptionUtils.rethrow(e);
}
}
开发者ID:yaroska,项目名称:true_oop,代码行数:15,代码来源:H2Products.java
示例18: productDiscountShouldMatchNewPrice
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Test(dataProvider = "getData")
public void productDiscountShouldMatchNewPrice(MonetaryAmount expectedPrice, BinaryOperator<Product> reductionOperator) {
val actualProduct = open(Java8ProductsPage.class).getProduct(reductionOperator);
assertThat(actualProduct)
.isNotEmpty()
.map(p -> p.getOldPrice().subtract(p.getOldPrice().multiply(p.getDiscount())))
.hasValue(expectedPrice);
}
开发者ID:sskorol,项目名称:selenium-camp-17,代码行数:10,代码来源:SC17Java8WithDPTests.java
示例19: print
import javax.money.MonetaryAmount; //导入依赖的package包/类
@Override
public String print(MonetaryAmount object, Locale locale) {
CurrencyStyleFormatter formatter = new CurrencyStyleFormatter();
formatter.setCurrency(Currency.getInstance(object.getCurrency().getCurrencyCode()));
formatter.setPattern(this.pattern);
return formatter.print(object.getNumber(), locale);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java
示例20: parse
import javax.money.MonetaryAmount; //导入依赖的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
注:本文中的javax.money.MonetaryAmount类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论