JSR-275 - Measurements and Units Specification

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>

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. This class can represents any kind of measure (scalar, vector, statistical). A factory method for numerical quantities (java.lang.Number) is provided.

Version:
4.0, February 25, 2006
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Constructor Summary
protected Measure(V value, Unit<Q> unit)
          Creates a measure for the specified value stated in the specified unit.
 
Method Summary
 int compareTo(Measurable<Q> that)
          Compares this measure with the one specified independently of the measurement units.
 boolean equals(java.lang.Object obj)
          Compares this measure against the specified object for strict equality (same unit and amount).
 Unit<Q> getUnit()
          Returns the measurement unit of this measure.
 V getValue()
          Returns the measurement value of this measure.
 int hashCode()
          Returns the hash code for this scalar.
 java.lang.String toString()
          Returns the String representation of this measure.
static
<N extends java.lang.Number,Q extends Quantity>
Measure<N,Q>
valueOf(N value, Unit<Q> unit)
          Returns the measure for the specified numerical quantity.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.measure.Measurable
doubleValue, longValue
 

Constructor Detail

Measure

protected Measure(V value,
                  Unit<Q> unit)
Creates a measure for the specified value stated in the specified unit.

Method Detail

valueOf

public static <N extends java.lang.Number,Q extends Quantity> Measure<N,Q> valueOf(N value,
                                                                                   Unit<Q> unit)
Returns the measure for the specified numerical quantity.

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

getValue

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

Returns:
the measurement value.

getUnit

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

Returns:
the measurement unit.

compareTo

public int compareTo(Measurable<Q> that)
Compares this measure with the one specified independently of the measurement units.

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

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.

Overrides:
toString in class java.lang.Object
Returns:
this.getValue() + " " + this.getUnit()

JSR-275 - Measurements and Units Specification

Copyright © 2007 JSR-275