简体   繁体   English

JSR 363的UCUM单位格式

[英]UCUM UnitFormat for JSR 363

I'm using JSR 363 "Units of Measurement" with the latest reference implementation: 我正在将JSR 363“度量单位”与最新的参考实现一起使用:

<dependency>
  <groupId>javax.measure</groupId>
  <artifactId>unit-api</artifactId>
  <version>1.0</version>
</dependency>

<dependency>
  <groupId>tec.units</groupId>
  <artifactId>unit-ri</artifactId>
  <version>1.0.2</version>
</dependency>

I want to print out "milliliters" in UCUM format, ie "mL": 我想以UCUM格式打印“毫升”,即“毫升”:

final UnitFormat unitFormat =
    ServiceProvider.current().getUnitFormatService().getUnitFormat();
final Unit<?> unit = MILLI(LITRE);
final String unitString=unitFormat.format(unit);

Unfortunately this gives me "ml", not "mL" from UCUM. 不幸的是,这给了我“ ml”,而不是UCUM的“ mL”。 And even though the JSR 363 specification (and source code) teases me throughout with references to the UCUM, UnitFormatService.getAvailableFormatNames() on the RI only gives me "ASCII" and "Default", so I can't use getUnitFormat("UCUM") as the JSR 363 specification hints that I should be able to do (if only someone would support UCUM). 而且即使JSR 363规范(和源代码)在整个UCUM引用UnitFormatService.getAvailableFormatNames()我感到UnitFormatService.getAvailableFormatNames() ,但RI上的UnitFormatService.getAvailableFormatNames()仅给了我“ ASCII”和“默认”,所以我不能使用getUnitFormat("UCUM")因为JSR 363规范暗示我应该能够做到(如果只有某人会支持UCUM)。

So where can I get a JSR 363 UnitFormat implementation supporting the UCUM? 那么,在哪里可以获得支持UCUM的JSR 363 UnitFormat实现?

In UCUM both l (lower case ell) and L are used for liter. 在UCUM中, l (小写ell)和L都用于升。 The lower case is continental European style, the upper case is US style. 小写字母是欧洲大陆风格,大写字母是美国风格。 Both are equivalent in UCUM. 两者在UCUM中是等效的。 So it's just a style issue. 因此,这只是一个样式问题。

See the JSR 363 extension module https://github.com/unitsofmeasurement/uom-systems/tree/master/ucum-java8 for UCUM support. 请参阅JSR 363扩展模块https://github.com/unitsofmeasurement/uom-systems/tree/master/ucum-java8以获取UCUM支持。

It provides support for the Unified Code for Units of Measure on Java SE 8. At the moment UCUM is more powerful and extensive, parsing uses a SymbolMap concept (based on Java ResourceBundles though it is not local-sensitive) so we cannot make it available for the JSR 363 RI. 它为Java SE 8上的计量单位统一代码提供支持。目前,UCUM更加强大和广泛,解析使用SymbolMap概念(基于Java ResourceBundles,尽管它对本地不敏感),所以我们无法使它可用JSR 363 RI。 Please use the compatible Java SE 8 port UoM SE if you can. 如果可以,请使用兼容的Java SE 8端口UoM SE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM