Java - JScience 定义一个新单元
我想在 JScience 中定义一个新的距离单位。项目网站的“教程”部分只是指向 Javadoc,虽然相当完整,但对我来说有点太密集了,无法理解我实际上是如何定义自己的单元的。
你能举个例子吗?
干杯。
皮特
I want to define a new distance unit in JScience. The "Tutorial" section of the project website just leads to Javadoc which, while fairly complete, is a bit too dense for me to fathom how I actually go about defining my own unit.
Could you provide an example?
Cheers.
Pete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一篇旧帖子,但是..无论如何我都会发布答案,也许它对某人有用
为了在 JScience 中定义自定义单位,您必须扩展类
SystemOfUnits< /code> 并在此处定义所有自定义单位。
检查下面的示例(我正在定义 ACRE 的单位)
I know this is an old post, but.. i'm going to post the answer anyways, maybe it'll be useful to someone
In order to define a custom unit in JScience, you have to extend the class
SystemOfUnits
and define here all your custom units.Check the exemple below (i'm defining the unit for ACREs)
也许关于Java中单位的这个其他SO问题可以提供帮助。
perhaps this other SO question about units in Java can help.
请看一下 JSR 363 RI 如何做到这一点(JScience 4 实现的 275 的后继者)
https:// /github.com/unitsofmeasurement/unit-ri/blob/master/src/main/java/tec/units/ri/format/SimpleUnitFormat.java
SimpleUnitFormat 的默认风格支持 UTF-8,而 ASCII 用于可能没有 GUI 或有限字符集的有限环境或设备:
DEFAULT.label(MetricPrefix.MICRO(Units.LITRE), "µl");
ASCII.label(MetricPrefix.MICRO(Units.LITRE), "microL");
请注意,label() 方法将在公共草案的下一个候选版本中引入 JSR 363 API。目前它是 RI 的一部分 (https://github.com/unitsofmeasurement/unit-ri,不是 JScience,尽管它最终也可能在 V5 中迁移到新标准)
Please have a look at how JSR 363 RI does this (the successor to 275 which was implemented by JScience 4)
https://github.com/unitsofmeasurement/unit-ri/blob/master/src/main/java/tec/units/ri/format/SimpleUnitFormat.java
The default flavor of SimpleUnitFormat supports UTF-8, while ASCII is for limited environments or devices that may have no GUI or limited character sets:
DEFAULT.label(MetricPrefix.MICRO(Units.LITRE), "µl");
ASCII.label(MetricPrefix.MICRO(Units.LITRE), "microL");
Note, the label() method will be introduced to JSR 363 API in the next candidate release for Public Draft. Currently it's part of the RI (https://github.com/unitsofmeasurement/unit-ri, not JScience, though it may eventually migrate to the new standard, too in V5)