Seshat is a Java library implementing the Units of Measurement API defined by JSR-385. Seshat is a subset of Apache Spatial Information System (SIS) library keeping only the classes required for JSR-385 implementation. Seshat supports parsing and formatting of unit symbols, together with arithmetic operations on units and on quantities. The JAR file size is 124 kb and the public API is made of 6 classes (not counting JSR-385 interfaces).
A set of predefined units constants is provided in the
Units
class.
Using the PASCAL
constants, one can easily create a kilopascal unit.
Note that the "kPa" symbol is inferred automatically:
Unit<Pressure> kilopascal = Units.PASCAL.multiply(1000); System.out.println(kilopascal); // print "kPa"
More complex operations can be applied. in many cases, Seshat can still detect automatically the resulting unit symbol and quantity type:
Force force = Quantities.create(4, Units.NEWTON); Length distance = Quantities.create(6, Units.MILLIMETRE); Time duration = Quantities.create(3, Units.SECOND); Quantity<?> power = force.multiply(distance).divide(duration); System.out.println(power); // print "8 mW" Power asTypeSafe = (Power) power; // This cast is allowed in Seshat
Parsing and formatting use Unicode symbols by default, as in µg/m². Parenthesis are recognized at parsing time and used for denominators at formatting time, as in kg/(m²⋅s). While uncommon, Seshat accepts fractional powers as in m^⅔. Some sentences like "100 feet", "square metre" and "degree Kelvin" are also recognized at parsing time.
In Seshat 1.3, the transition from JSR-363 to JSR-385 is not yet completed. The following features are new in JSR-385 and are either not yet implemented or are only partially supported in Seshat:
Unit.prefix(Prefix)
applies the scale factor but ignores the prefix symbol.
Note however that in many cases, Seshat infers the symbol automatically.QuantityFactory.create(Number, Unit<Q>, Scale)
currently accepts
only Scale.ABSOLUTE
.Latest release can be used in a Maven project with following configuration:
<project> <dependencies> <dependency> <groupId>tech.uom</groupId> <artifactId>seshat</artifactId> <version>1.3</version> </dependency> </dependencies> </project>