javax.measure.converter
Class RationalConverter

java.lang.Object
  extended by javax.measure.converter.UnitConverter
      extended by javax.measure.converter.LinearConverter
          extended by javax.measure.converter.RationalConverter
All Implemented Interfaces:
java.io.Serializable

public final class RationalConverter
extends LinearConverter

This class represents a converter multiplying numeric values by an exact scaling factor (represented as the quotient of two BigInteger numbers).

Instances of this class are immutable.

Version:
1.0, April 15, 2009
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.measure.converter.UnitConverter
IDENTITY
 
Constructor Summary
RationalConverter(java.math.BigInteger dividend, java.math.BigInteger divisor)
          Creates a rational converter with the specified dividend and divisor.
 
Method Summary
 UnitConverter concatenate(UnitConverter converter)
          Concatenates this converter with another converter.
 java.math.BigDecimal convert(java.math.BigDecimal value, java.math.MathContext ctx)
          Converts a BigDecimal value.
 double convert(double value)
          Converts a double value.
 boolean equals(java.lang.Object obj)
          Indicates whether this converter is considered to be the the same as the one specified.
 java.math.BigInteger getDividend()
          Returns the integer dividend for this rational converter.
 java.math.BigInteger getDivisor()
          Returns the integer (positive) divisor for this rational converter.
 int hashCode()
          Returns a hash code value for this converter.
 RationalConverter inverse()
          Returns the inverse of this converter.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RationalConverter

public RationalConverter(java.math.BigInteger dividend,
                         java.math.BigInteger divisor)
Creates a rational converter with the specified dividend and divisor.

Parameters:
dividend - the dividend.
divisor - the positive divisor.
Throws:
java.lang.IllegalArgumentException - if divisor <= 0
java.lang.IllegalArgumentException - if dividend == divisor
Method Detail

getDividend

public java.math.BigInteger getDividend()
Returns the integer dividend for this rational converter.

Returns:
this converter dividend.

getDivisor

public java.math.BigInteger getDivisor()
Returns the integer (positive) divisor for this rational converter.

Returns:
this converter divisor.

convert

public double convert(double value)
Description copied from class: UnitConverter
Converts a double value.

Specified by:
convert in class UnitConverter
Parameters:
value - the numeric value to convert.
Returns:
the double value after conversion.

convert

public java.math.BigDecimal convert(java.math.BigDecimal value,
                                    java.math.MathContext ctx)
                             throws java.lang.ArithmeticException
Description copied from class: UnitConverter
Converts a BigDecimal value.

Specified by:
convert in class UnitConverter
Parameters:
value - the numeric value to convert.
ctx - the math context being used for conversion.
Returns:
the decimal value after conversion.
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.

concatenate

public UnitConverter concatenate(UnitConverter converter)
Description copied from class: UnitConverter
Concatenates this converter with another converter. The resulting converter is equivalent to first converting by the specified converter, and then converting by this converter.

Note: Implementations must ensure that the UnitConverter.IDENTITY instance is returned if the resulting converter is an identity converter.

Overrides:
concatenate in class LinearConverter
Parameters:
converter - the other converter.
Returns:
the concatenation of this converter with the other converter.

inverse

public RationalConverter inverse()
Description copied from class: UnitConverter
Returns the inverse of this converter. If x is a valid value, then x == inverse().convert(convert(x)) to within the accuracy of computer arithmetic.

Specified by:
inverse in class LinearConverter
Returns:
the inverse of this converter.

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Description copied from class: UnitConverter
Indicates whether this converter is considered to be the the same as the one specified.

Specified by:
equals in class UnitConverter
Parameters:
obj - the converter with which to compare.
Returns:
true if the specified object is a converter considered equals to this converter;false otherwise.

hashCode

public int hashCode()
Description copied from class: UnitConverter
Returns a hash code value for this converter. Equals object have equal hash codes.

Specified by:
hashCode in class UnitConverter
Returns:
this converter hash code value.
See Also:
UnitConverter.equals(java.lang.Object)


Copyright © 2009 JScience. All Rights Reserved.