Quantities is a Java library designed to handle values in combination with units and, in contrast to (all?) other quantity handling libraries, coordinate systems (including curvilinear, non-orthogonal ones). This allows for richer metadata, while degrading gracefully if not all metadata is provided explicitly. All of the implementations are immutable and null-hostile.
Some of the supported features include:
- Support for scalar and vector fields. For example
var scalarField = new ScalarField<Double>("magnitude of B", val -> 2 * val, new CartesianCoordinates(1), new CartesianCoordinates(1)); var q0d = new Quantity0D(12, Unit.of("mm")); assertArrayEquals(new double[] {0.024}, scalarField.apply(q0d).value());
- Apply simple functions. For example
var quantity = new Quantity0D(-3.0, Unit.of("m")); var quantityWithAppliedFunction = quantity.apply(Math::abs); // value is Math.abs(-3)
- Approach target values by changing unit prefixes on the axes (useful e.g. for autoranging for optimizers). For example
var quantity = new Quantity0D(1.024e6, Unit.of("g")); var quantityApproaching1 = quantity.approach(1); // 1.024 Mg
The artifact can be found at maven central:
<dependency>
<groupId>eu.hoefel</groupId>
<artifactId>quantities</artifactId>
<version>0.10.2</version>
</dependency>
Quantities is designed to work with Java 17+.