简体   繁体   English

JSR 363添加新单位

[英]JSR 363 adding new units

I am using the reference implementation of JSR 363: Units of Measurement API from maven (tec.units:unit-ri). 我正在使用来自maven(tec.units:unit-ri)的JSR 363:Measurement of Measurement API的参考实现。

Now I have to add a few units like teaspoon, fluid ounce and so on. 现在我必须添加一些单位,如茶匙,液体盎司等。

Im extending the Units class to add a new unit like this: 我扩展Units类来添加一个像这样的新单元:

public static final Unit<Volume> TEASPOON = addUnit(new TransformedUnit<Volume>("tsp", CUBIC_METRE, new MultiplyConverter(0.000005)));

This seems to work for converting but "tsp" is not parsing, so how do I add it to the parser? 这似乎适用于转换,但“tsp”不解析,所以如何将其添加到解析器?

And Im having trouble adding Fahrenheit for example: T(°F) = T(K) × 9/5 - 459.67 我在添加华氏温度时遇到了麻烦:T(°F)= T(K)×9/5 - 459.67

How can I do this with the converters, or do I have to extend UnitConverter and create my own? 如何使用转换器执行此操作,还是必须扩展UnitConverter并创建自己的转换器?

Though you may define your own unit, common units like TEASPOON or Fluid Ounce are already available in extension modules for JSR 363 like https://github.com/unitsofmeasurement/uom-systems 虽然您可以定义自己的单元,但是常见的单元如TEASPOONFluid Ounce已经可用于JSR 363的扩展模块,如https://github.com/unitsofmeasurement/uom-systems

https://github.com/unitsofmeasurement/uom-systems/tree/master/common for the RI-based library. https://github.com/unitsofmeasurement/uom-systems/tree/master/common用于基于RI的库。 Fahrenheit is also there. 华氏也在那里。

All these systems or the "full SI" system are available on the JCenter public repo. 所有这些系统或“完整SI”系统都可以在JCenter公共回购中找到。 We plan to also sync it to MavenCentral soon, but you can use it the same way from JCenter if you add its repository definition to your Maven (or Gradle, etc.) build files. 我们计划很快将它同步到MavenCentral,但如果将其存储库定义添加到Maven(或Gradle等)构建文件中,则可以从JCenter以相同的方式使用它。

Thanks for mentioning. 谢谢你的提及。 If you're using SimpleUnitFormat (leaving Locale aside for now) you may be missing a label() expression in the right places. 如果您正在使用SimpleUnitFormatSimpleUnitFormat将Locale放在一边),您可能会在正确的位置缺少label()表达式。

Do you have a GitHub account, then please file it under https://github.com/unitsofmeasurement/uom-systems/issues if you can and we'll address the issue as soon as possible. 你有一个GitHub帐户,如果可以,请在https://github.com/unitsofmeasurement/uom-systems/issues下提交,我们会尽快解决这个问题。 Or file a PR. 或者提交PR。

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

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