Interface Measurable<Q extends Quantity>
-
- All Superinterfaces:
- java.lang.Comparable<Measurable<Q>>
- All Known Implementing Classes:
- Altitude, Amount, DecimalMeasure, Height, Measure, Time, VectorMeasure
public interface Measurable<Q extends Quantity> extends java.lang.Comparable<Measurable<Q>>
This interface represents the measurable, countable, or comparable property or aspect of a thing.
Implementing instances are typically the result of a measurement:
They can also be created from custom classes:Measurable<Mass> weight = Measure.valueOf(180.0, POUND);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. ... }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description doubledoubleValue(Unit<Q> unit)Returns the value of this measurable stated in the specified unit as adouble.longlongValue(Unit<Q> unit)Returns the estimated integral value of this measurable stated in the specified unit as along.
-
-
-
Method Detail
-
doubleValue
double doubleValue(Unit<Q> unit)
Returns the value of this measurable stated in the specified unit as adouble. If the measurable has too great a magnitude to be represented as adouble, it will be converted toDouble.NEGATIVE_INFINITYorDouble.POSITIVE_INFINITYas appropriate.- Parameters:
unit- the unit in which this measurable value is stated.- Returns:
- the numeric value after conversion to type
double.
-
longValue
long longValue(Unit<Q> unit) throws java.lang.ArithmeticException
Returns the estimated integral value of this measurable stated in the specified unit as along.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).- Parameters:
unit- the unit in which the measurable value is stated.- Returns:
- the numeric value after conversion to type
long. - Throws:
java.lang.ArithmeticException- if this quantity cannot be represented as alongnumber in the specified unit.
-
-
DMelt 3.0 © DataMelt by jWork.ORG