Class Measure<V,Q extends Quantity>
- All Implemented Interfaces:
Serializable,Comparable<Measurable<Q>>,Measurable<Q>
- Direct Known Subclasses:
DecimalMeasure,VectorMeasure
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(Measurable<Q> that) Compares this measure to the specified measurable quantity.abstract doubledoubleValue(Unit<Q> unit) Returns the value of this measure stated in the specified unit as adouble.booleanCompares this measure against the specified object for strict equality (same unit and amount).floatfloatValue(Unit<Q> unit) Returns the value of this measure stated in the specified unit as afloat.getUnit()Returns the measurement unit of this measure.abstract VgetValue()Returns the measurement value of this measure.inthashCode()Returns the hash code for this scalar.intReturns the estimated integral value of this measure stated in the specified unit as aint.longReturns the estimated integral value of this measure stated in the specified unit as along.Returns the measure equivalent to this measure but stated in the specified unit.toString()Returns theStringrepresentation of this measure The string produced for a given measure is always the same; it is not affected by locale.Deprecated.Returns the scalar measure for the specifieddoublestated in the specified unit.Returns the scalar measure for the specifiedfloatstated in the specified unit.Returns the scalar measure for the specifiedintstated in the specified unit.Returns the scalar measure for the specifieddoublestated in the specified unit.static <Q extends Quantity>
Measure<BigDecimal,Q> valueOf(BigDecimal decimal, Unit<Q> unit) Deprecated.DecimalMeasureshould be used directly.static <Q extends Quantity>
Measure<BigDecimal,Q> valueOf(BigDecimal decimal, Unit<Q> unit, MathContext mathContext) Deprecated.
-
Constructor Details
-
Measure
protected Measure()Default constructor.
-
-
Method Details
-
valueOf
Returns the scalar measure for the specifieddoublestated in the specified unit.- Parameters:
doubleValue- the measurement value.unit- the measurement unit.
-
valueOf
Returns the scalar measure for the specifieddoublestated in the specified unit.- Parameters:
longValue- the measurement value.unit- the measurement unit.
-
valueOf
Returns the scalar measure for the specifiedfloatstated in the specified unit.- Parameters:
floatValue- the measurement value.unit- the measurement unit.
-
valueOf
Returns the scalar measure for the specifiedintstated in the specified unit.- Parameters:
intValue- the measurement value.unit- the measurement unit.
-
getValue
Returns the measurement value of this measure.- Returns:
- the measurement value.
-
getUnit
Returns the measurement unit of this measure.- Returns:
- the measurement unit.
-
to
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
Returns the value of this measure stated in the specified unit as adouble. If the measure has too great a magnitude to be represented as adouble, it will be converted toDouble.NEGATIVE_INFINITYorDouble.POSITIVE_INFINITYas appropriate.- Specified by:
doubleValuein interfaceMeasurable<V>- Parameters:
unit- the unit in which this measure is stated.- Returns:
- the numeric value after conversion to type
double.
-
longValue
Returns the estimated integral value of this measure 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).- Specified by:
longValuein interfaceMeasurable<V>- Parameters:
unit- the unit in which the measurable value is stated.- Returns:
- the numeric value after conversion to type
long. - Throws:
ArithmeticException- if this quantity cannot be represented as alongnumber in the specified unit.
-
floatValue
Returns the value of this measure stated in the specified unit as afloat. If the measure has too great a magnitude to be represented as afloat, it will be converted toFloat.NEGATIVE_INFINITYorFloat.POSITIVE_INFINITYas appropriate.- Parameters:
unit- the unit in which the measure is stated.- Returns:
- the numeric value after conversion to type
float.
-
intValue
Returns the estimated integral value of this measure stated in the specified unit as aint.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:
ArithmeticException- if this quantity cannot be represented as aintnumber in the specified unit.
-
equals
Compares this measure against the specified object for strict equality (same unit and amount). To compare measures stated using different units thecompareTo(javax.measure.Measurable<Q>)method should be used. -
hashCode
public int hashCode()Returns the hash code for this scalar. -
toString
Returns theStringrepresentation 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 theMeasureFormatclass and its subclasses. -
compareTo
Compares this measure to the specified measurable quantity. This method compares theMeasurable.doubleValue(Unit)of both this measure and the specified measurable stated in the same unit (this measure'sunit).- Specified by:
compareToin interfaceComparable<V>- 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
Deprecated.DecimalMeasureshould be used directly. -
valueOf
public static <Q extends Quantity> Measure<BigDecimal,Q> valueOf(BigDecimal decimal, Unit<Q> unit, MathContext mathContext) Deprecated. -
valueOf
Deprecated.VectorMeasureshould be used directly.
-
VectorMeasureshould be used directly.