UCUM UnitFormat for JSR 363

浪子不回头ぞ 提交于 2019-12-02 11:45:17

问题


I'm using JSR 363 "Units of Measurement" with the latest reference implementation:

<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, i.e. "mL":

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. 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).

So where can I get a JSR 363 UnitFormat implementation supporting the UCUM?


回答1:


In UCUM both l (lower case ell) and L are used for liter. The lower case is continental European style, the upper case is US style. Both are equivalent in UCUM. So it's just a style issue.




回答2:


See the JSR 363 extension module https://github.com/unitsofmeasurement/uom-systems/tree/master/ucum-java8 for UCUM support.

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. Please use the compatible Java SE 8 port UoM SE if you can.



来源:https://stackoverflow.com/questions/42653545/ucum-unitformat-for-jsr-363

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!