JScience v4.3

javax.measure
Class DecimalMeasure<Q extends Quantity>

java.lang.Object
  extended by javax.measure.Measure<java.math.BigDecimal,Q>
      extended by javax.measure.DecimalMeasure<Q>
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Measurable<Q>>, Measurable<Q>

public class DecimalMeasure<Q extends Quantity>
extends Measure<java.math.BigDecimal,Q>

This class represents a measure whose value is an arbitrary-precision decimal number.

When converting, applications may supply the java.math.Context:

         DecimalMeasure<Velocity> c = DecimalMeasure.valueOf("299792458 m/s");
         DecimalMeasure<Velocity> milesPerHour = c.to(MILES_PER_HOUR, MathContext.DECIMAL128);
         System.out.println(milesPerHour);
         
         > 670616629.3843951324266284896206156 mph
     

Version:
4.3, October 3, 2007
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Constructor Summary
DecimalMeasure(java.math.BigDecimal value, Unit<Q> unit)
          Creates a decimal measure for the specified number stated in the specified unit.
 
Method Summary
 double doubleValue(Unit<Q> unit)
          Returns the value of this measure stated in the specified unit as a double.
 Unit<Q> getUnit()
          Returns the measurement unit of this measure.
 java.math.BigDecimal getValue()
          Returns the measurement value of this measure.
 DecimalMeasure<Q> to(Unit<Q> unit)
          Returns the decimal measure equivalent to this measure but stated in the specified unit.
 DecimalMeasure<Q> to(Unit<Q> unit, java.math.MathContext mathContext)
          Returns the decimal measure equivalent to this measure but stated in the specified unit, the conversion is performed using the specified math context.
static
<Q extends Quantity>
DecimalMeasure<Q>
valueOf(java.math.BigDecimal decimal, Unit<Q> unit)
          Returns the decimal measure for the specified number stated in the specified unit.
static
<Q extends Quantity>
DecimalMeasure<Q>
valueOf(java.lang.CharSequence csq)
          Returns the decimal measure for the specified textual representation.
 
Methods inherited from class javax.measure.Measure
compareTo, equals, floatValue, hashCode, intValue, longValue, toString, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DecimalMeasure

public DecimalMeasure(java.math.BigDecimal value,
                      Unit<Q> unit)
Creates a decimal measure for the specified number stated in the specified unit.

Method Detail

valueOf

public static <Q extends Quantity> DecimalMeasure<Q> valueOf(java.math.BigDecimal decimal,
                                                             Unit<Q> unit)
Returns the decimal measure for the specified number stated in the specified unit.

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

valueOf

public static <Q extends Quantity> DecimalMeasure<Q> valueOf(java.lang.CharSequence csq)
Returns the decimal measure for the specified textual representation. This method first reads the BigDecimal value, then the unit if any (value and unit should be separated by white spaces).

Parameters:
csq - the decimal measure representation (including unit if any).
Throws:
java.lang.NumberFormatException - if the specified character sequence is not a valid representation of decimal measure.

getUnit

public Unit<Q> getUnit()
Description copied from class: Measure
Returns the measurement unit of this measure.

Specified by:
getUnit in class Measure<java.math.BigDecimal,Q extends Quantity>
Returns:
the measurement unit.

getValue

public java.math.BigDecimal getValue()
Description copied from class: Measure
Returns the measurement value of this measure.

Specified by:
getValue in class Measure<java.math.BigDecimal,Q extends Quantity>
Returns:
the measurement value.

to

public DecimalMeasure<Q> to(Unit<Q> unit)
Returns the decimal measure equivalent to this measure but stated in the specified unit. This method will raise an ArithmeticException if the resulting measure does not have a terminating decimal expansion.

Specified by:
to in class Measure<java.math.BigDecimal,Q extends Quantity>
Parameters:
unit - the new measurement unit.
Returns:
the measure stated in the specified unit.
Throws:
java.lang.ArithmeticException - if the converted measure value does not have a terminating decimal expansion
See Also:
to(Unit, MathContext)

to

public DecimalMeasure<Q> to(Unit<Q> unit,
                            java.math.MathContext mathContext)
Returns the decimal measure equivalent to this measure but stated in the specified unit, the conversion is performed using the specified math context.

Parameters:
unit - the new measurement unit.
mathContext - the mathContext used to convert BigDecimal values or null if none.
Returns:
the measure stated in the specified unit.
Throws:
java.lang.ArithmeticException - if the result is inexact but the rounding mode is MathContext.UNNECESSARY or mathContext.precision == 0 and the quotient has a non-terminating decimal expansion.

doubleValue

public double doubleValue(Unit<Q> unit)
Description copied from class: Measure
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>
Specified by:
doubleValue in class Measure<java.math.BigDecimal,Q extends Quantity>
Parameters:
unit - the unit in which this measure is stated.
Returns:
the numeric value after conversion to type double.

JScience v4.3

Copyright © 2006 JScience.