Package javax.measure
Provides strongly typed measurements to enforce compile-time check of parameters consistency and avoid interface errors.
Let's take the following example:[code]
class Person {
void setWeight(double weight);
}[/code]
Should the weight be in pound, kilogram ??
Using measures there is no room for error:[code]
class Person {
void setWeight(Measurable
Users may create their own Measurable
implementation:[code]
public class Period implements Measurable
Users may also combine a definite amount (scalar, vector, collection, etc.)
to a unit and make it a Measure
(and
a Measurable
instance). For example:
[code]
// Scalar measurement (numerical).
person.setWeight(Measure.valueOf(180.0, POUND)); // Measure<Double, Mass>
timer.setPeriod(Measure.valueOf(20, MILLI(SECOND)); // Measure<Integer, Duration>
circuit.setCurrent(Measure.valueOf(Complex.valueOf(2, -3), AMPERE); // (2 - 3i) A
bottle.setPression(Measure.valueOf(Rational.valueOf(20, 100), ATMOSPHERE)); // (20/100) Atm
// Vector measurement.
abstract class MeasureVector<E, Q extends Quantity> extends Measure<E[], Q> {
... // doubleValue(Unit) returns vector norm.
}
MeasureVector<Double, Velocity> v = MeasureVector.valueOf(METRE_PER_SECOND, 1.0, 2.0, 3.0);
plane.setVelocity(v);
// Statistical measurement.
class Average extends Measure<double[], Q>{
... // doubleValue(Unit) returns average value.
}
sea.setTemperature(Average.valueOf(new double[] { 33.4, 44.55, 32.33} , CELCIUS));
// Measurement with uncertainty (and additional operations).
public class Amount
extends Measurable
{
public Amount(double value, double error, Unit
unit) { ... }
public Amount
plus(Amount
that) {...}
public Amount<?> times(Amount<?> that) {...}
... // doubleValue(Unit) returns estimated value.
}
[/code]
-
ClassDescriptionDecimalMeasure<Q extends Quantity>This class represents a measure whose value is an arbitrary-precision decimal number.Measurable<Q extends Quantity>This interface represents the measurable, countable, or comparable property or aspect of a thing.This class represents the result of a measurement stated in a known unit.This class provides the interface for formatting and parsing
measures
.VectorMeasure<Q extends Quantity>This class represents a measurement vector of two or more dimensions.