measure
is a Kotlin library for working with units of measurement that are - for example - used in the power system sector.
Projects often need a way to express different quantities. For example, building software for electric grids one encounters quantities like power, energy, amperage etcetera.
When one choses to represent this quantities as BigDecimal
, one needs to be very vigilant when calculating with these quantities. It is easy to add power and energy when they both are represented as a BigDecimal
, even though it does not make sense on physical grounds.
Rather, one would represents quantities as a multiple of a unit of measurement. This project provides exactly that.
In using measure library there are two parts. The generic Measure
and Units
provided by the measure library, and the specific units that your project are interested in.
val power: Measure<Power> = 10 * kiloWatt
val duration: Measure<Time> = 15 * minutes
val energy: Measure<Energy> = power * duration
assertThat(energy `as` megaJoule).equals(9 * megaJoule)
The code above demonstrates a fully annotated calculation with quantities. Often times the compiler can infer the corresponding types.
This project is written in Kotlin and uses Gradle as a build tool. To see which tasks are available run
./gradlew tasks
The code found in the measure
module is generated from a model. The model is a System
which describes units and their multiplications. An application can read a representation of a system and output the source.
If one wants to add a specific unit one can add it to the units as found in the resources of the measure-generator
module.
If the functionality of Measure
should change one should make the intended changes in the measure.vtl
template or its companion specific.vtl
that describes how specific units like power, energy or time.
This project is licensed under the Mozilla Public License, version 2.0 - see LICENSE for details.
This project includes third-party libraries, which are licensed under their own respective Open-Source licenses. SPDX-License-Identifier headers are used to show which license is applicable. The concerning license files can be found in the LICENSES directory.
Please read CODE_OF_CONDUCT and CONTRIBUTING for details on the process for submitting pull requests to us.
Please read SUPPORT for how to connect and get into contact with the Measure project.