Seshat

Seshat is a Java library implementing the Units of Measurement API defined by JSR-363. Seshat is a subset of Apache Spatial Information System (SIS) library keeping only the classes required for JSR-363, with geospatial-specific functionalities omitted. Seshat supports parsing and formatting of unit symbols, together with arithmetic operations on units and on quantities. The JAR file size is 141 kb and the public API is made of 5 classes (not counting JSR-363 interfaces).

Examples

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.

Download with Maven

Latest release can be used in a Maven project with following configuration:

<project>
  <dependencies>
    <dependency>
      <groupId>tech.uom</groupId>
      <artifactId>seshat</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>bintray-unitsofmeasurement-maven</id>
      <name>bintray</name>
      <url>https://dl.bintray.com/unitsofmeasurement/maven</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
</project>