javax.measure
public interface Measurable<Q extends Quantity> extends java.lang.Comparable<Measurable<Q>>
Measurable<Mass> weight = Measure.valueOf(180.0, POUND);They can also be created from custom classes:
class Delay implements Measurable<Duration> { private long nanoSeconds; // Implicit internal unit. public double doubleValue(Unit<Velocity> unit) { ... } public long longValue(Unit<Velocity> unit) { ... } } Thread.wait(new Delay(24, HOUR)); // Assuming Thread.wait(Measurable<Duration>) method.Although measurable instances are for the most part scalar quantities; more complex implementations (e.g. vectors, data set) are allowed as long as an aggregate magnitude can be determined. For example:
class Velocity3D implements Measurable<Velocity> { private double x, y, z; // Meter per seconds. public double doubleValue(Unit<Velocity> unit) { ... } // Returns vector norm. ... } class Sensors<Q extends Quantity> extends Measure<double[], Q> { public doubleValue(Unit<Q> unit) { ... } // Returns median value. ... }
Modifier and Type | Method and Description |
---|---|
Measurable<Q> |
add(Measurable<Q> other)
Adds the other Measurable to this one, returning a Measurable object of the same type as the original.
|
double |
doubleValue(Unit<Q> unit)
Returns the value of this measurable stated in the specified unit as a
double . |
long |
longValue(Unit<Q> unit)
Returns the estimated integral value of this measurable stated in the specified unit as a
long . |
double doubleValue(Unit<Q> unit)
double
. If the measurable has
too great a magnitude to be represented as a double
, it will be converted to
Double.NEGATIVE_INFINITY
or Double.POSITIVE_INFINITY
as appropriate.unit
- the unit in which this measurable value is stated.double
.long longValue(Unit<Q> unit) throws java.lang.ArithmeticException
long
.
Note: This method differs from the Number.longValue()
in the sense that the closest integer value is
returned and an ArithmeticException is raised instead of a bit truncation in case of overflow (safety critical).
unit
- the unit in which the measurable value is stated.long
.java.lang.ArithmeticException
- if this quantity cannot be represented as a long
number in the specified unit.Measurable<Q> add(Measurable<Q> other)
other
- The measurable that should be added to this one.