当前位置: 首页 > news >正文

温州做网站seo网站开发翻译功能

温州做网站seo,网站开发翻译功能,wordpress会员到期,wordpress同步到头条号jsr 269 apiJSR 354定义了一个用于处理货币和货币的新Java API#xff0c;计划将其包含在Java 9中。在本文中#xff0c;我们将研究参考实现的当前状态#xff1a; JavaMoney 。 就像我关于Java 8日期/时间API的帖子一样#xff0c;该帖子将主要由显示新API的代码驱动。 … jsr 269 api JSR 354定义了一个用于处理货币和货币的新Java API计划将其包含在Java 9中。在本文中我们将研究参考实现的当前状态 JavaMoney 。 就像我关于Java 8日期/时间API的帖子一样该帖子将主要由显示新API的代码驱动。 但是在开始之前我想引用一下规范中的一小部分以总结一下此新API的动机 货币价值是许多应用程序的关键功能但是JDK提供的支持很少或没有。 现有的java.util.Currency类严格来说是一种用于表示当前ISO 4217货币的结构但不能表示关联的值或自定义货币。 JDK还不支持货币算术或货币转换也不支持代表货币金额的标准值类型。 如果使用Maven则可以通过将以下依赖项添加到项目中来轻松尝试参考实现的当前状态 dependencygroupIdorg.javamoney/groupIdartifactIdmoneta/artifactIdversion0.9/version /dependency 所有规范类和接口都位于javax.money。*包中。 我们将从两个核心接口CurrencyUnit和MonetaryAmount开始。 之后我们将研究汇率货币转换和格式。 货币单位和货币金额 CurrencyUnit为货币建模。 CurrencyUnit与现有的java.util.Currency类非常相似不同之处在于它允许自定义实现。 根据规范java.util.Currency应该可以实现CurrencyUnit。 可以使用MonetaryCurrencies工厂获取CurrencyUnit实例 // getting CurrencyUnits by currency code CurrencyUnit euro  MonetaryCurrencies.getCurrency(EUR); CurrencyUnit usDollar  MonetaryCurrencies.getCurrency(USD);// getting CurrencyUnits by locale CurrencyUnit yen  MonetaryCurrencies.getCurrency(Locale.JAPAN); CurrencyUnit canadianDollar  MonetaryCurrencies.getCurrency(Locale.CANADA); MontetaryAmount表示货币金额的具体数字表示。 MonetaryAmount始终绑定到CurrencyUnit。 与CurrencyUnit一样MonetaryAmount是支持不同实现的接口。 CurrencyUnit和MonetaryAmount实现必须是不可变的线程安全的可序列化的和可比较的。 // get MonetaryAmount from CurrencyUnit CurrencyUnit euro  MonetaryCurrencies.getCurrency(EUR); MonetaryAmount fiveEuro  Money.of(5, euro);// get MonetaryAmount from currency code MonetaryAmount tenUsDollar  Money.of(10, USD);// FastMoney is an alternative MonetaryAmount factory that focuses on performance MonetaryAmount sevenEuro  FastMoney.of(7, euro); Money和FastMoney是JavaMoney的两个MonetaryAmount实现。 Money是使用BigDecimal存储数字值的默认实现。 FastMoney是一种将金额存储在长字段中的替代实现。 根据文档与Money相比FastMoney的运行速度快10到15倍。 但是FastMoney受long类型的大小和精度的限制。 请注意Money和FastMoney是实现特定的类位于org.javamoney.moneta。*而不是javax.money。*中。 如果要避免实现特定的类则必须获取MonetaryAmountFactory来创建MonetaryAmount实例 MonetaryAmount specAmount  MonetaryAmounts.getDefaultAmountFactory().setNumber(123.45).setCurrency(USD).create(); 如果实现类货币单位和数值相等则认为两个MontetaryAmount实例相等 MonetaryAmount oneEuro  Money.of(1, MonetaryCurrencies.getCurrency(EUR)); boolean isEqual  oneEuro.equals(Money.of(1, EUR)); // true boolean isEqualFast  oneEuro.equals(FastMoney.of(1, EUR)); // false MonetaryAmount具有多种方法可用于访问分配的货币数字量其精度等 MonetaryAmount monetaryAmount  Money.of(123.45, euro); CurrencyUnit currency  monetaryAmount.getCurrency(); NumberValue numberValue  monetaryAmount.getNumber();int intValue  numberValue.intValue(); // 123 double doubleValue  numberValue.doubleValue(); // 123.45 long fractionDenominator  numberValue.getAmountFractionDenominator(); // 100 long fractionNumerator  numberValue.getAmountFractionNumerator(); // 45 int precision  numberValue.getPrecision(); // 5// NumberValue extends java.lang.Number.  // So we assign numberValue to a variable of type Number Number number  numberValue;使用MonetaryAmounts 可以使用MonetaryAmount执行数学运算 MonetaryAmount twelveEuro  fiveEuro.add(sevenEuro); // EUR 12 MonetaryAmount twoEuro  sevenEuro.subtract(fiveEuro); // EUR 2 MonetaryAmount sevenPointFiveEuro  fiveEuro.multiply(1.5); // EUR 7.5// MonetaryAmount can have a negative NumberValue MonetaryAmount minusTwoEuro  fiveEuro.subtract(sevenEuro); // EUR -2// some useful utility methods boolean greaterThan  sevenEuro.isGreaterThan(fiveEuro); // true boolean positive  sevenEuro.isPositive(); // true boolean zero  sevenEuro.isZero(); // false// Note that MonetaryAmounts need to have the same CurrencyUnit to do mathematical operations // this fails with: javax.money.MonetaryException: Currency mismatch: EUR/USD fiveEuro.add(tenUsDollar); 四舍五入是使用金钱时的另一个重要部分。 可以使用舍入运算符舍入MonetaryAmount CurrencyUnit usd  MonetaryCurrencies.getCurrency(USD); MonetaryAmount dollars  Money.of(12.34567, usd); MonetaryOperator roundingOperator  MonetaryRoundings.getRounding(usd); MonetaryAmount roundedDollars  dollars.with(roundingOperator); // USD 12.35 在这里12.3456美元使用该货币的默认舍入取整。 使用MonetaryAmounts的集合时可以使用一些不错的实用程序方法进行过滤排序和分组。 这些方法可以与Java 8 Stream API一起使用。 考虑以下集合 ListMonetaryAmount amounts  new ArrayList(); amounts.add(Money.of(2, EUR)); amounts.add(Money.of(42, USD)); amounts.add(Money.of(7, USD)); amounts.add(Money.of(13.37, JPY)); amounts.add(Money.of(18, USD)); 现在我们可以按CurrencyUnit过滤金额 CurrencyUnit yen  MonetaryCurrencies.getCurrency(JPY); CurrencyUnit dollar  MonetaryCurrencies.getCurrency(USD);// filter by currency, get only dollars // result is [USD 18, USD 7, USD 42] ListMonetaryAmount onlyDollar  amounts.stream().filter(MonetaryFunctions.isCurrency(dollar)).collect(Collectors.toList());// filter by currency, get only dollars and yen // [USD 18, USD 7, JPY 13.37, USD 42] ListMonetaryAmount onlyDollarAndYen  amounts.stream().filter(MonetaryFunctions.isCurrency(dollar, yen)).collect(Collectors.toList()); 我们还可以过滤出小于或大于特定阈值的MonetaryAmounts MonetaryAmount tenDollar  Money.of(10, dollar);// [USD 42, USD 18] ListMonetaryAmount greaterThanTenDollar  amounts.stream().filter(MonetaryFunctions.isCurrency(dollar)).filter(MonetaryFunctions.isGreaterThan(tenDollar)).collect(Collectors.toList()); 排序的工作方式类似 // Sorting dollar values by number value // [USD 7, USD 18, USD 42] ListMonetaryAmount sortedByAmount  onlyDollar.stream().sorted(MonetaryFunctions.sortNumber()).collect(Collectors.toList());// Sorting by CurrencyUnit // [EUR 2, JPY 13.37, USD 42, USD 7, USD 18] ListMonetaryAmount sortedByCurrencyUnit  amounts.stream().sorted(MonetaryFunctions.sortCurrencyUnit()).collect(Collectors.toList()); 分组功能 // Grouping by CurrencyUnit // {USD[USD 42, USD 7, USD 18], EUR[EUR 2], JPY[JPY 13.37]} MapCurrencyUnit, ListMonetaryAmount groupedByCurrency  amounts.stream().collect(MonetaryFunctions.groupByCurrencyUnit());// Grouping by summarizing MonetaryAmounts MapCurrencyUnit, MonetarySummaryStatistics summary  amounts.stream().collect(MonetaryFunctions.groupBySummarizingMonetary()).get();// get summary for CurrencyUnit USD MonetarySummaryStatistics dollarSummary  summary.get(dollar); MonetaryAmount average  dollarSummary.getAverage(); // USD 22.333333333333333333.. MonetaryAmount min  dollarSummary.getMin(); // USD 7 MonetaryAmount max  dollarSummary.getMax(); // USD 42 MonetaryAmount sum  dollarSummary.getSum(); // USD 67 long count  dollarSummary.getCount(); // 3 MonetaryFunctions还提供归约函数可用于获取MonetaryAmount集合的最大值最小值和总和 ListMonetaryAmount amounts  new ArrayList(); amounts.add(Money.of(10, EUR)); amounts.add(Money.of(7.5, EUR)); amounts.add(Money.of(12, EUR));OptionalMonetaryAmount max  amounts.stream().reduce(MonetaryFunctions.max()); // EUR 7.5 OptionalMonetaryAmount min  amounts.stream().reduce(MonetaryFunctions.min()); // EUR 12 OptionalMonetaryAmount sum  amounts.stream().reduce(MonetaryFunctions.sum()); // EUR 29.5自定义MonetaryAmount操作 MonetaryAmount提供了一个很好的扩展点称为MonetaryOperator。 MonetaryOperator是一个功能接口该接口将MonetaryAmount作为输入并根据输入创建一个新的MonetaryAmount。 // A monetary operator that returns 10% of the input MonetaryAmount // Implemented using Java 8 Lambdas MonetaryOperator tenPercentOperator  (MonetaryAmount amount) - {BigDecimal baseAmount  amount.getNumber().numberValue(BigDecimal.class);BigDecimal tenPercent  baseAmount.multiply(new BigDecimal(0.1));return Money.of(tenPercent, amount.getCurrency()); };MonetaryAmount dollars  Money.of(12.34567, USD);// apply tenPercentOperator to MonetaryAmount MonetaryAmount tenPercentDollars  dollars.with(tenPercentOperator); // USD 1.234567 一些标准API功能被实现为MonetaryOperator。 例如我们在上面看到的舍入功能被实现为MonetaryOperator。 汇率 可以使用ExchangeRateProvider获得货币汇率。 JavaMoney带有多个不同的ExchangeRateProvider实现。 两个最重要的实现是ECBCurrentRateProvider和IMFRateProvider。 ECBCurrentRateProvider查询欧洲中央银行ECB数据供稿以获取当前汇率而IMFRateProvider使用国际货币基金组织IMF转换率。 // get the default ExchangeRateProvider (CompoundRateProvider) ExchangeRateProvider exchangeRateProvider  MonetaryConversions.getExchangeRateProvider();// get the names of the default provider chain // [IDENT, ECB, IMF, ECB-HIST] ListString defaultProviderChain  MonetaryConversions.getDefaultProviderChain();// get a specific ExchangeRateProvider (here ECB) ExchangeRateProvider ecbExchangeRateProvider  MonetaryConversions.getExchangeRateProvider(ECB); 如果未请求特定的ExchangeRateProvider则将返回CompoundRateProvider。 CompoundRateProvider将汇率请求委托给一系列ExchangeRateProviders并从第一个返回适当结果的提供程序返回结果。 // get the exchange rate from euro to us dollar ExchangeRate rate  exchangeRateProvider.getExchangeRate(EUR, USD);NumberValue factor  rate.getFactor(); // 1.2537 (at time writing) CurrencyUnit baseCurrency  rate.getBaseCurrency(); // EUR CurrencyUnit targetCurrency  rate.getCurrency(); // USD货币转换 货币之间的转换是通过从ExchangeRateProviders获得的CurrencyConversions完成的 // get the CurrencyConversion from the default provider chain CurrencyConversion dollarConversion  MonetaryConversions.getConversion(USD);// get the CurrencyConversion from a specific provider CurrencyConversion ecbDollarConversion  ecbExchangeRateProvider.getCurrencyConversion(USD);MonetaryAmount tenEuro  Money.of(10, EUR);// convert 10 euro to us dollar  MonetaryAmount inDollar  tenEuro.with(dollarConversion); // USD 12.537 (at the time writing) 请注意CurrencyConversion实现了MonetaryOperator。 像其他运算符一样可以使用MonetaryAmount.with来应用它。 格式化和解析 MonetaryAmounts可以使用MonetaryAmountFormat从字符串解析/格式化为字符串 // formatting by locale specific formats MonetaryAmountFormat germanFormat  MonetaryFormats.getAmountFormat(Locale.GERMANY); MonetaryAmountFormat usFormat  MonetaryFormats.getAmountFormat(Locale.CANADA);MonetaryAmount amount  Money.of(12345.67, USD);String usFormatted  usFormat.format(amount); // USD12,345.67 String germanFormatted  germanFormat.format(amount); // 12.345,67 USD// A MonetaryAmountFormat can also be used to parse MonetaryAmounts from strings MonetaryAmount parsed  germanFormat.parse(12,4 USD); 使用AmountFormatQueryBuilder可以创建自定义格式 // Creating a custom MonetaryAmountFormat MonetaryAmountFormat customFormat  MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.NAME).set(pattern, 00,00,00,00.00 ¤).build());// results in 00,01,23,45.67 US Dollar String formatted  customFormat.format(amount); 请注意¤符号\ u00A用作模式字符串内的货币占位符。 摘要 我们研究了新的Money and Currency API的许多部分。 该实现看起来已经很可靠了但肯定需要更多文档。 我期待在Java 9中看到此API 您可以在GitHub上找到此处显示的所有示例。 翻译自: https://www.javacodegeeks.com/2014/12/looking-into-the-java-9-money-and-currency-api-jsr-354.htmljsr 269 api
http://www.huolong8.cn/news/441191/

相关文章:

  • 广西区建设厅网站网站站群建设
  • 电子商务做网站wordpress 自动备份
  • 网站建设需要注意那些点扬州seo招聘
  • c 做网站教程wordpress 文章合集
  • 网站建设工作会议上的讲话网站建设就找奇思网络
  • 网站建设目标分析wordpress 刷浏览量
  • 番禺定制型网站建设快懂百科登录入口
  • 可以做课程的网站公司免费网页怎么制作
  • 网站建设 利润地坪漆东莞网站建设技术支持
  • 网络推广工作好干吗网站seo主管招聘
  • 凡科网制作网站教程建立公司的流程
  • 沈阳营销型网站建设上海企业信用信息公示系统
  • 网站没内容 可以备案么广州安全教育
  • wordpress个人下载网站中国联通业绩
  • 设置本机外网ip做网站阿里指数怎么没有了
  • 以什么主题做网站好济宁网站建设只要500元
  • 惠州企业网站建设做网站写页面多少钱
  • 网站备案用英文网站宣传文案有哪些
  • 高端网站建设案例中国那个公司的网站做的最好
  • 备案 网站语言织梦营销型网站模板
  • 无备案网站可以做百度推广密山网站建设
  • 建站哪个网站比较好wordpress 功能小工具
  • 站酷网首页网站设计师联盟
  • 网站title在哪里wordpress 商城模板下载
  • 网站域名有了 网站如何建设深圳百度推广开户
  • 贵州建设职业技术学院网站做嗳嗳的网站
  • 网站开发环境写什么打工网站校企合作建设
  • app制作和网站一样吗怎么把广告发到各大平台
  • 企业网站需要多大带宽南昌购物网站开发
  • 网站建设管理情况报告云南网站优化