|
| 1 | +--- |
| 2 | +layout: project |
| 3 | +title: Units of Measurement |
| 4 | +description: Orbit Exploration Toolkit |
| 5 | +img: /img/logo-uom.png |
| 6 | +link: https://github.com/netomi/uom |
| 7 | +role: owner |
| 8 | +license: Apache license 2.0 |
| 9 | +category: scientific |
| 10 | +tags: java scientific_computing |
| 11 | +--- |
| 12 | + |
| 13 | +This library is my take on JSR-385 to provide a useful API for representing physical measurements and perform |
| 14 | +conversions between different units. |
| 15 | + |
| 16 | +Its not a reference implementation of the Units of Measurement API due to technical limitations of the latter one. |
| 17 | +Instead it takes many of the concepts of the released API and builds a full-fledged units of measurement library around |
| 18 | +them to be able to represent physical measurements in different units with arbitrary precision. |
| 19 | + |
| 20 | +The design goal of the library is to include: |
| 21 | + |
| 22 | +* fully typed quantities: |
| 23 | +{% highlight java %} |
| 24 | +Length l1 = Length.of(1, SI.METER); |
| 25 | +Length l2 = Length.ofMeter(2); |
| 26 | +{% endhighlight %} |
| 27 | + |
| 28 | +* transparent support for double and arbitrary decimal precision quantities (using BigDecimal): |
| 29 | +{% highlight java %} |
| 30 | +Length doubleLength = Quantities.createQuantity(1, SI.METER, Length.class); |
| 31 | +Length decimalLength = Quantities.createQuantity(BigDecimal.ONE, Imperial.YARD, Length.class); |
| 32 | + |
| 33 | +Length l3 = l1.add(l2); |
| 34 | +{% endhighlight %} |
| 35 | + |
| 36 | +* support for generic quantities: |
| 37 | +{% highlight java %} |
| 38 | +Quantity<Speed> speed = Quantities.createGeneric(1, SI.METER_PER_SECOND); |
| 39 | + |
| 40 | +System.out.println(speed.add(Speed.ofMeterPerSecond(2))); // -> prints 3 m/s |
| 41 | +{% endhighlight %} |
| 42 | + |
| 43 | +* support for quantity factories: |
| 44 | +{% highlight java %} |
| 45 | +QuantityFactory<Length> factory = DoubleQuantity.factory(Length.class); |
| 46 | + |
| 47 | +Length l1 = factory.create(1, SI.METRE); |
| 48 | + |
| 49 | +// default factories can be replaced |
| 50 | +// use decimal precision with MathContext DECIMAL128 for every quantity of type Length: |
| 51 | +Quantities.registerQuantityFactory(Length.class, DecimalQuantity.factory(MathContext.DECIMAL128, Length.class)); |
| 52 | + |
| 53 | +// quantity factories with pooling behavior can be registered |
| 54 | +QuantityFactory<Length> myPoolFactory = ...; |
| 55 | +Quantities.registerQuantityFactory(Length.class, myPoolFactory); |
| 56 | +{% endhighlight %} |
| 57 | + |
| 58 | +* support for the standard unit manipulations as defined by [JSR-385](https://www.jcp.org/en/jsr/detail?id=385) et al |
| 59 | +* support for as many units as possible, the amazing [GNU units](https://www.gnu.org/software/units/) library is the reference to compare to |
0 commit comments