JSR 363 adds new units

I am using the reference implementation of JSR 363: API Units from maven (tec.units: unit-ri).

Now I have to add a few units, such as a teaspoon, fl oz, etc.

Im extends the Units class to add a new block as follows:

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

This seems to work for conversion, but "tsp" is not parsed, so how do I add it to the parser?

And I had problems adding Fahrenheit, for example: T (° F) = T (K) × 9/5 - 459.67

How to do this with converters, or do I need to expand UnitConverter and create my own?

+6
source share
2 answers

Although you can define your own block, generic modules such as TEASPOON or Fluid Ounce are already available in extension modules for JSR 363, for example https://github.com/unitsofmeasurement/uom-systems

https://github.com/unitsofmeasurement/uom-systems/tree/master/common for an RI-based library. Fahrenheit also exists.

All of these systems or the “full SI” system are available on the JCenter public repo. We also plan to synchronize it with MavenCentral in the near future, but you can use it in the same way as JCenter if you add its repository definition to the Maven build files (or Gradle, etc.).

0
source

Thanks for the mention. If you use SimpleUnitFormat (now leave Locale aside), you might lose the label () expression in the right places.

You have a GitHub account, and then please copy it to https://github.com/unitsofmeasurement/uom-systems/issues and we will look at the problem as soon as possible. Or write PR.

0
source

All Articles