javax.measure
Class Measure<V,Q extends Quantity>

java.lang.Object
  extended by javax.measure.Measure<V,Q>
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Measurable<Q>>, Measurable<Q>
Direct Known Subclasses:
DecimalMeasure, VectorMeasure

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).

See Also:
Serialized Form

Constructor Summary
protected Measure()
          Default constructor.
 
Method Summary
 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 strict equality (same unit and amount).
 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>
Measure<java.math.BigDecimal,Q>
valueOf(java.math.BigDecimal decimal, Unit<Q> unit)
          Deprecated. DecimalMeasure should be used directly.
static
<Q extends Quantity>
Measure<java.math.BigDecimal,Q>
valueOf(java.math.BigDecimal decimal, Unit<Q> unit, java.math.MathContext mathContext)
          Deprecated. DecimalMeasure should be used directly and MathContext specified explicitly when converting.
static
<Q extends Quantity>
Measure<double[],Q>
valueOf(double[] components, Unit<Q> unit)
          Deprecated. VectorMeasure should be used directly.
static
<Q extends Quantity>
Measure<java.lang.Double,Q>
valueOf(double doubleValue, Unit<Q> unit)
          Returns the scalar measure for the specified double stated in the specified unit.
static
<Q extends Quantity>
Measure<java.lang.Float,Q>
valueOf(float floatValue, Unit<Q> unit)
          Returns the scalar measure for the specified float stated in the specified unit.
static
<Q extends Quantity>
Measure<java.lang.Integer,Q>
valueOf(int intValue, Unit<Q> unit)
          Returns the scalar measure for the specified int stated in the specified unit.
static
<Q extends Quantity>
Measure<java.lang.Long,Q>
valueOf(long longValue, Unit<Q> unit)
          Returns the scalar measure for the specified double stated in the specified unit.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Measure

protected Measure()
Default constructor.

Method Detail

valueOf

public static <Q extends Quantity> Measure<java.lang.Double,Q> valueOf(double doubleValue,
                                                                       Unit<Q> unit)
Returns the scalar measure for the specified double stated in the specified unit.

Parameters:
doubleValue - the measurement value.
unit - the measurement unit.

valueOf

public static <Q extends Quantity> Measure<java.lang.Long,Q> valueOf(long longValue,
                                                                     Unit<Q> unit)
Returns the scalar measure for the specified double stated in the specified unit.

Parameters:
longValue - the measurement value.
unit - the measurement unit.

valueOf

public static <Q extends Quantity> Measure<java.lang.Float,Q> valueOf(float floatValue,
                                                                      Unit<Q> unit)
Returns the scalar measure for the specified float stated in the specified unit.

Parameters:
floatValue - the measurement value.
unit - the measurement unit.

valueOf

public static <Q extends Quantity> Measure<java.lang.Integer,Q> valueOf(int intValue,
                                                                        Unit<Q> unit)
Returns the scalar measure for the specified int stated in the specified unit.

Parameters:
intValue - the measurement value.
unit - the measurement unit.

getValue

public abstract V getValue()
Returns the measurement value of this measure.

Returns:
the measurement value.

getUnit

public abstract Unit<Q> getUnit()
Returns the measurement unit of this measure.

Returns:
the measurement unit.

to

public abstract Measure<V,Q> to(Unit<Q> unit)
Returns the measure equivalent to this measure but stated in the specified unit. This method may result in lost of precision (e.g. measure of integral value).

Parameters:
unit - the new measurement unit.
Returns:
the measure stated in the specified unit.

doubleValue

public abstract double doubleValue(Unit<Q> unit)
Returns the value of this measure stated in the specified unit as a 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.

Specified by:
doubleValue in interface Measurable<Q extends Quantity>
Parameters:
unit - the unit in which this measure is stated.
Returns:
the numeric value after conversion to type double.

longValue

public long longValue(Unit<Q> unit)
               throws java.lang.ArithmeticException
Returns the estimated integral value of this measure stated in the specified unit as a 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).

Specified by:
longValue in interface Measurable<Q extends Quantity>
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 a long number in the specified unit.

floatValue

public float floatValue(Unit<Q> unit)
Returns the value of this measure stated in the specified unit as a 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.

Parameters:
unit - the unit in which the measure is stated.
Returns:
the numeric value after conversion to type float.

intValue

public int intValue(Unit<Q> unit)
Returns the estimated integral value of this measure stated in the specified unit as a 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).

Parameters:
unit - the unit in which the measurable value is stated.
Returns:
the numeric value after conversion to type int.
Throws:
java.lang.ArithmeticException - if this quantity cannot be represented as a int number in the specified unit.

equals

public boolean equals(java.lang.Object obj)
Compares this measure against the specified object for strict equality (same unit and amount). To compare measures stated using different units the compareTo(javax.measure.Measurable) method should be used.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with.
Returns:
true if both objects are identical (same unit and same amount); false otherwise.

hashCode

public int hashCode()
Returns the hash code for this scalar.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value.

toString

public 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. 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.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this measure.

compareTo

public int compareTo(Measurable<Q> that)
Compares this measure to the specified measurable quantity. This method compares the Measurable.doubleValue(Unit) of both this measure and the specified measurable stated in the same unit (this measure's unit).

Specified by:
compareTo in interface java.lang.Comparable<Measurable<Q extends Quantity>>
Returns:
a negative integer, zero, or a positive integer as this measure is less than, equal to, or greater than the specified measurable quantity.

valueOf

public static <Q extends Quantity> Measure<java.math.BigDecimal,Q> valueOf(java.math.BigDecimal decimal,
                                                                           Unit<Q> unit)
Deprecated. DecimalMeasure should be used directly.


valueOf

public static <Q extends Quantity> Measure<java.math.BigDecimal,Q> valueOf(java.math.BigDecimal decimal,
                                                                           Unit<Q> unit,
                                                                           java.math.MathContext mathContext)
Deprecated. DecimalMeasure should be used directly and MathContext specified explicitly when converting.


valueOf

public static <Q extends Quantity> Measure<double[],Q> valueOf(double[] components,
                                                               Unit<Q> unit)
Deprecated. VectorMeasure should be used directly.