2017-03-07 78 views
0

我使用JSR 363 「計量單位」 與最新的參考實現:UCUM UnitFormat對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> 

我想在UCUM格式打印出 「毫升」,即 「ML」:

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

不幸的是,這給了我「毫升」,而不是從UCUM「mL」。儘管JSR 363規範(以及源代碼)在引用了UCUM的同時對我進行了調整,但RI上的UnitFormatService.getAvailableFormatNames()僅給出了「ASCII」和「默認」,因此我不能使用getUnitFormat("UCUM"),因爲JSR 363規範提示我應該能夠做到(如果只有人會支持UCUM)。

那麼我在哪裏可以得到支持UCUM的JSR 363 UnitFormat實現?

+0

我試圖通過引入JScience 4.3.1(它僅支持JSR-275)來進行格式化,但JScience的'UnitFormat.getUCUMInstance()'的源代碼似乎確實返回了'UnitFormat.ASCII '評論:'TBD - 提供UCUM實現。'呃。 –

回答

-1

有關UCUM支持,請參閱JSR 363擴展模塊https://github.com/unitsofmeasurement/uom-systems/tree/master/ucum-java8

它提供了一個統一的代碼支持針對Java SE 8 計量單位目前UCUM更加強大和廣泛,分析使用SymbolMap概念(基於Java把ResourceBundle雖然它不是本地敏感的),所以我們無法將其提供給JSR 363 RI。如果可以,請使用兼容的Java SE 8端口UoM SE