Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSR 363 adding new units

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

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:

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?

And Im having trouble adding Fahrenheit for example: 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?

like image 741
TeKo Avatar asked Dec 01 '15 14:12

TeKo


1 Answers

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

https://github.com/unitsofmeasurement/uom-systems/tree/master/common for the RI-based library. Fahrenheit is also there.

All these systems or the "full SI" system are available on the JCenter public repo. 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.

like image 147
Werner Keil Avatar answered Oct 17 '22 05:10

Werner Keil