Mass,
time, distance, heat, and angular separation are among the familiar examples
of quantitative properties.
Unit<Mass> pound = ... Quantity<Length> size = ... Sensor<Temperature>
thermometer = ... Vector3D<Speed> aircraftSpeed = ...
Quantity
instances. All implementations shall produce equivalent results for
the same operation applied on equivalent quantities. Two quantities are
equivalent if, after conversion to the same unit of measurement, they have
the same numerical value (ignoring rounding errors). For example 2000 metres
is equivalent to 2 km, but 2°C is not equivalent to 2 K; it is equivalent to
275.15 K instead. Above requirement applied to addition means that 2°C + 2 K
shall be equivalent to 275.15 K + 2 K.
All operations shall preserve the basic laws of algebra, in particular commutativity of addition and multiplication (A + B = B + A) and associativity of addition and multiplication (A + B) + C = A + (B + C). In order to preserve those algebra laws, this specification requires all arithmetic operations to execute as is all operands were converted to system unit before the operation is carried out, and the result converted back to any compatible unit at implementation choice. For example 4 cm + 1 inch shall produce any result equivalent to 0.04 m + 0.0254 m.
Implementations are allowed to avoid conversion to system unit if the result is guaranteed to be equivalent. This is often the case when the conversion between quantity unit and system unit is only a scale factor. However this is not the case for conversions applying an offset or more complex formula. For example 2°C + 1°C = 274.15°C, not 3°C. This counter-intuitive result is essential for preserving algebra laws like associativity, and is also the expected result from a thermodynamic point of view.
Comparable.Unit, Wikipedia: Quantity, Martin Fowler - Quantity
| Modifier and Type | Class and Description |
|---|---|
| public static enum | Quantity.Scale
The scale of a |
| Modifier and Type | Method and Description |
|---|---|
| public Quantity | |
| public < The type of the quantity. T extends Quantity | Returns: this quantity parameterized with the specified type.the quantity class identifying the nature of the quantity. type)Casts this quantity to a parameterized unit of specified nature or throw a
|
| public Quantity | |
| public Quantity | |
| public Quantity. | Returns: the scale, if it's an absolute or relative quantity.Returns the |
| public Unit | |
| public Number | |
| public Quantity | Returns: reciprocalQuantityReturns a |
| public boolean | Returns: true if that ≡ this.the that)quantity<Q> to be compared with this instance.Compares two instances of |
| public Quantity | |
| public Quantity | |
| public Quantity | |
| public Quantity | |
| public Quantity | |
| public default Quantity | Returns: this quantity or a new quantity equivalent to this quantity stated in SI units.Convenient method equivalent to |
| add | back to summary |
|---|---|
| public Quantity Returns the sum of this | |
| asType | back to summary |
|---|---|
| public <T extends Quantity Casts this quantity to a parameterized unit of specified nature or throw a
| |
| divide | back to summary |
|---|---|
| public Quantity Returns the quotient of this
| |
| divide | back to summary |
|---|---|
| public Quantity Returns the quotient of this | |
| getScale | back to summary |
|---|---|
| public Quantity. Returns the
| |
| getUnit | back to summary |
|---|---|
| public Unit Returns the unit of this
| |
| getValue | back to summary |
|---|---|
| public Number getValue() Returns the value of this
| |
| inverse | back to summary |
|---|---|
| public Quantity Returns a
| |
| isEquivalentTo | back to summary |
|---|---|
| public boolean isEquivalentTo(Quantity<Q> that) Compares two instances of
| |
| multiply | back to summary |
|---|---|
| public Quantity Returns the product of this
| |
| multiply | back to summary |
|---|---|
| public Quantity Returns the product of this | |
| negate | back to summary |
|---|---|
| public Quantity Returns a
| |
| subtract | back to summary |
|---|---|
| public Quantity Returns the difference between this | |
| to | back to summary |
|---|---|
| public Quantity Returns this
| |
| toSystemUnit | back to summary |
|---|---|
| public default Quantity Convenient method equivalent to
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final Quantity. | ABSOLUTE
Absolute scale |
| public static final Quantity. | RELATIVE
Relative scale |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Quantity. | |
| public static Quantity. |
| ABSOLUTE | back to summary |
|---|---|
| public static final Quantity. Absolute scale
| |
| RELATIVE | back to summary |
|---|---|
| public static final Quantity. Relative scale | |
| Scale | back to summary |
|---|---|
| private Scale() | |
| valueOf | back to summary |
|---|---|
| public static Quantity. | |
| values | back to summary |
|---|---|
| public static Quantity. | |