2

我们有一个系统,用户可以提供任何单位的数据。数据被存储并可能转换为相同维度的任何其他单位。它基于 JScience api。

我想生成所有受支持单位的列表,以及它们拥有的所有别名。我似乎找不到这样做的方法。目前我只是这样做:

    for (javax.measure.unit.Unit<?> unit: javax.measure.unit.SI.getInstance().getUnits())
        System.out.println(UnitFormat.getInstance().format(unit));

    for (javax.measure.unit.Unit<?> unit: javax.measure.unit.NonSI.getInstance().getUnits())
        System.out.println(UnitFormat.getInstance().format(unit));

首先,这只会产生标签列表,我根本找不到获取别名的方法。

其次,它甚至似乎并不包含所有单位。如果我查看反编译的文件 javax.measure.unit.UnitFormat,它似乎是所有标签的附加位置;我看到这条线:

DEFAULT.label(NonSI.ROENTGEN, "Roentgen");

但我在输出中没有看到“Reontgen”。有没有人有办法解决吗?

4

1 回答 1

2

您可能想先尝试一下JSR 363。它是 JScience 4 和 JSR 275 的继任者,而 JSR 363 在 2016 年 9 月完成时从未进入决赛。

JSR 363 知道多个单元系统,但我们只使用 RI 中内置的一个。您可以应用一个名为SystemOfUnitsReporter的库实用程序,并按如下方式应用它:

import tec.units.ri.unit.Units;
import tec.uom.lib.common.util.SystemOfUnitsReporter;

SystemOfUnitsReporter reporter = SystemOfUnitsReporter.of(Units.getInstance());
reporter.report();

这会将实现中的单元列表打印SystemOfUnits到控制台。

于 2017-06-02T14:43:26.857 回答