javax.measure
public abstract class Measure<V,Q extends Quantity> extends java.lang.Object implements Measurable<Q>, java.io.Serializable
This class represents the result of a measurement stated in a known unit.
There is no constraint upon the measurement value itself: scalars, vectors, or even data sets are valid values as
long as an aggregate magnitude can be determined (see Measurable
).
Modifier | Constructor and Description |
---|---|
protected |
Measure()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Measurable<Q> that)
Compares this measure to the specified measurable quantity.
|
abstract double |
doubleValue(Unit<Q> unit)
Returns the value of this measure stated in the specified unit as a
double . |
boolean |
equals(java.lang.Object obj)
Compares this measure against the specified object for equality.
|
float |
floatValue(Unit<Q> unit)
Returns the value of this measure stated in the specified unit as a
float . |
abstract Unit<Q> |
getUnit()
Returns the measurement unit of this measure.
|
abstract V |
getValue()
Returns the measurement value of this measure.
|
int |
hashCode()
Returns the hash code for this scalar.
|
int |
intValue(Unit<Q> unit)
Returns the estimated integral value of this measure stated in the specified unit as a
int . |
long |
longValue(Unit<Q> unit)
Returns the estimated integral value of this measure stated in the specified unit as a
long . |
abstract Measure<V,Q> |
to(Unit<Q> unit)
Returns the measure equivalent to this measure but stated in the specified unit.
|
java.lang.String |
toString()
Returns the
String representation of this measure The string produced for a given measure is always
the same; it is not affected by locale. |
static <Q extends Quantity> |
valueOf(double doubleValue,
Unit<Q> unit)
Returns the scalar measure for the specified
double stated in the specified unit. |
static <Q extends Quantity> |
valueOf(float floatValue,
Unit<Q> unit)
Returns the scalar measure for the specified
float stated in the specified unit. |
static <Q extends Quantity> |
valueOf(int intValue,
Unit<Q> unit)
Returns the scalar measure for the specified
int stated in the specified unit. |
static <Q extends Quantity> |
valueOf(long longValue,
Unit<Q> unit)
Returns the scalar measure for the specified
double stated in the specified unit. |
static <Q extends Quantity> |
zero(Unit<Q> unit) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add
public static <Q extends Quantity> Measurable<Q> zero(Unit<Q> unit)
public static <Q extends Quantity> Measure<java.lang.Double,Q> valueOf(double doubleValue, Unit<Q> unit)
double
stated in the specified unit.doubleValue
- the measurement value.unit
- the measurement unit.public static <Q extends Quantity> Measure<java.lang.Long,Q> valueOf(long longValue, Unit<Q> unit)
double
stated in the specified unit.longValue
- the measurement value.unit
- the measurement unit.public static <Q extends Quantity> Measure<java.lang.Float,Q> valueOf(float floatValue, Unit<Q> unit)
float
stated in the specified unit.floatValue
- the measurement value.unit
- the measurement unit.public static <Q extends Quantity> Measure<java.lang.Integer,Q> valueOf(int intValue, Unit<Q> unit)
int
stated in the specified unit.intValue
- the measurement value.unit
- the measurement unit.public abstract V getValue()
public abstract Unit<Q> getUnit()
public abstract Measure<V,Q> to(Unit<Q> unit)
unit
- the new measurement unit.public abstract double doubleValue(Unit<Q> unit)
double
. If the measure 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.doubleValue
in interface Measurable<Q extends Quantity>
unit
- the unit in which this measure is stated.double
.public 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).
longValue
in interface Measurable<Q extends Quantity>
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.public float floatValue(Unit<Q> unit)
float
. If the measure has too
great a magnitude to be represented as a float
, it will be converted to
Float.NEGATIVE_INFINITY
or Float.POSITIVE_INFINITY
as appropriate.unit
- the unit in which the measure is stated.float
.public int intValue(Unit<Q> unit)
int
.
Note: This method differs from the Number.intValue()
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.int
.java.lang.ArithmeticException
- if this quantity cannot be represented as a int
number in the specified unit.public boolean equals(java.lang.Object obj)
compareTo(javax.measure.Measurable)
is used to check for equality. Otherwise, false is returned.
This is different from the standard implementation of JScience, which tests for strict equality. This is not
according to the contract of the compareTo(Measurable)
method.equals
in class java.lang.Object
obj
- the object to compare with.true
if both objects are equal; false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
String
representation of this measure The string produced for a given measure is always
the same; it is not affected by locale. This means that it can be used as a canonical string representation for
exchanging data, or as a key for a Hashtable, etc. Locale-sensitive measure formatting and parsing is handled by
the MeasureFormat
class and its subclasses.toString
in class java.lang.Object
public int compareTo(Measurable<Q> that)
Measurable.doubleValue(Unit)
of both this measure and the specified measurable stated in the same unit
(this measure's unit
).compareTo
in interface java.lang.Comparable<Measurable<Q extends Quantity>>