|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Measurable<Q extends Quantity>
This interface represents the measurable, countable, or comparable property or aspect of a thing.
Measurable instances are for the most part scalar quantities.
Non-scalar quantities are nevertheless allowed as long as an aggregate
value makes sense.
class Delay implements Measurable<Duration> {
private final double seconds; // Implicit internal unit.
public Delay(double value, Unit<Duration> unit) {
seconds = unit.getConverterTo(SI.SECOND).convert(value);
}
public double doubleValue(Unit<Duration> unit) {
return SI.SECOND.getConverterTo(unit).convert(seconds);
}
...
}
Thread.wait(new Delay(24, NonSI.HOUR)); // Assuming Thread.wait(Measurable<Duration>) method.
class Velocity3D implements Measurable<Velocity> {
private double x, y, z; // Meters per second.
public double doubleValue(Unit<Velocity> unit) { // Returns the vector norm.
double meterPerSecond = Math.sqrt(x * x + y * y + z * z);
return SI.METER_PER_SECOND.getConverterTo(unit).convert(meterPerSecond);
}
...
}
class ComplexCurrent implements extends Measurable<ElectricCurrent> {
private Complex amperes;
public double doubleValue(Unit<ElectricCurrent> unit) { // Returns the magnitude.
return AMPERE.getConverterTo(unit).convert(amperes.magnitude());
}
...
public Complex complexValue(Unit<ElectricCurrent> unit) { ... }
}
For convenience, measurable instances of any type can be created
using the Measure factory methods.
Thread.wait(Measure.valueOf(24, NonSI.HOUR));
| Method Summary | |
|---|---|
java.math.BigDecimal |
decimalValue(Unit<Q> unit,
java.math.MathContext ctx)
Returns the BigDecimal value of this measurable when
stated in the specified unit. |
double |
doubleValue(Unit<Q> unit)
Returns the double value of this measurable
when stated in the specified unit. |
float |
floatValue(Unit<Q> unit)
Returns the float value of this measurable
when stated in the specified unit. |
int |
intValue(Unit<Q> unit)
Returns the integral int value of this measurable when
stated in the specified unit. |
long |
longValue(Unit<Q> unit)
Returns the integral long value of this measurable when
stated in the specified unit. |
| Methods inherited from interface java.lang.Comparable |
|---|
compareTo |
| Method Detail |
|---|
int intValue(Unit<Q> unit)
throws java.lang.ArithmeticException
int value of this measurable when
stated in the specified unit.
Note: This method differs from the Number.intValue()
in the sense that an ArithmeticException is raised instead
of a bit truncation in case of overflow (safety critical).
unit - the unit in which the returned value is stated.
int.
java.lang.ArithmeticException - if this measurable cannot be represented
by a int number in the specified unit.
long longValue(Unit<Q> unit)
throws java.lang.ArithmeticException
long value of this measurable when
stated in the specified unit.
Note: This method differs from the Number.longValue()
in the sense that an ArithmeticException is raised instead
of a bit truncation in case of overflow (safety critical).
unit - the unit in which the returned value is stated.
long.
java.lang.ArithmeticException - if this measurable cannot be represented
by a int number in the specified unit.float floatValue(Unit<Q> unit)
float value of this measurable
when stated in the specified unit. If the measurable has too great of
a magnitude to be represented as a float,
FLOAT.NEGATIVE_INFINITY or
FLOAT.POSITIVE_INFINITY is returned as appropriate.
unit - the unit in which this returned value is stated.
float.double doubleValue(Unit<Q> unit)
double value of this measurable
when stated in the specified unit. If the measurable has too great of
a magnitude to be represented as a double,
Double.NEGATIVE_INFINITY or
Double.POSITIVE_INFINITY is returned as appropriate.
unit - the unit in which this returned value is stated.
double.
java.math.BigDecimal decimalValue(Unit<Q> unit,
java.math.MathContext ctx)
throws java.lang.ArithmeticException
BigDecimal value of this measurable when
stated in the specified unit.
unit - the unit in which the returned value is stated.ctx - the math context being used for conversion.
java.lang.ArithmeticException - if the result is inexact but the
rounding mode is UNNECESSARY or
mathContext.precision == 0 and the quotient has a
non-terminating decimal expansion.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||