Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class nl.coffee.math.AbstractIntegerNumber

java.lang.Object
  |
  +--java.lang.Number
        |
        +--nl.coffee.math.AbstractRealNumber
              |
              +--nl.coffee.math.AbstractRationalNumber
                    |
                    +--nl.coffee.math.AbstractIntegerNumber
Subclasses:
BasicIntegerNumber, LongIntegerNumber

public abstract class AbstractIntegerNumber
extends AbstractRationalNumber
implements IntegerNumber
Abstract base class for IntegerNumber implementations.

Concrete subclasses must at least provide implementations for the following methods:

Subclasses are encouraged to override as many methods as they can in order to optimize the implementation. Those methods marked as final need no further optimization.

Since:
JUMP_1.0
Version:
1.2 199809.24
Author:
Ernst de Haan
See Also:
Serialized Form

Constructor Summary
AbstractIntegerNumber()
          Constructs a new AbstractIntegerNumber.
 
Method Summary
RationalNumber add(RationalNumber n)
           
int compareTo(IntegerNumber n)
           
IntegerNumber dec()
           
RationalNumber divide(RationalNumber n)
           
IntegerNumber fac()
           
IntegerNumber gcd(IntegerNumber n)
           
IntegerNumber getDenominator()
          Returns the denominator of this rational number.
IntegerNumber getNumerator()
          Returns the numerator of this rational number.
int getSign()
          Determines the sign of this number.
int hashCode()
           
IntegerNumber inc()
           
RealNumber invert()
           
boolean isRelativePrime(IntegerNumber n)
           
RationalNumber multiply(RationalNumber n)
           
RealNumber negate()
          Computes -this.
RationalNumber pow(IntegerNumber n)
           
IntegerNumber remainder(IntegerNumber n)
           
RationalNumber subtract(RationalNumber n)
           
IntegerNumber subtract(IntegerNumber n)
           
java.math.BigDecimal toBigDecimal()
          Converts the value of this number to a BigDecimal.
java.math.BigDecimal toBigDecimal(int precision)
          Converts the value of this number to a BigDecimal with the specified precision.
java.math.BigDecimal toBigDecimal(int precision, int roundingMode)
          Converts the value of this number to a BigDecimal with the specified precision and rounding mode.
java.math.BigInteger toBigInteger()
          Converts the value of this number to a BigInteger.
java.lang.String toString()
          Returns a textual representation of this object.
IntegerNumber trunc()
          Rounds to an integer number towards 0.

The implementation of this method in AbstractIntegerNumber returns this.

 
Methods inherited from class nl.coffee.math.AbstractRationalNumber
add, add, compareTo, divide, divide, doubleValue, getSign, invert, multiply, multiply, negate, pow, pow, retryCompare, retryCompare, subtract, subtract, toBigDecimal, toBigDecimal, toString, trunc
 
Methods inherited from class nl.coffee.math.AbstractRealNumber
abs, add, byteValue, compareTo, divide, doubleValue, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, hashCode, intValue, invert, longValue, multiply, negate, pow, retryCompare, shortValue, subtract, toBigDecimal, toBigInteger
 
Methods inherited from class java.lang.Number
byteValue, doubleValue, floatValue, intValue, longValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Constructor Detail

AbstractIntegerNumber

protected AbstractIntegerNumber()
Constructs a new AbstractIntegerNumber.
Method Detail

compareTo

public int compareTo(IntegerNumber n)
             throws java.lang.IllegalArgumentException
Description copied from interface:
 
Specified by:
compareTo in interface IntegerNumber

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractRealNumber

getSign

public abstract int getSign()
Determines the sign of this number. This method returns -1, 0, or 1 as this number is negative, zero, or positive.

The declaration is made abstract, because the implementation in superclass AbstractRationalNumber does not make sense for IntegerNumber implementations.

Returns:
the sign of this number.
Overrides:
getSign in class AbstractRationalNumber

negate

public abstract RealNumber negate()
Computes -this.

The declaration is made abstract, because the implementation in superclass AbstractRationalNumber does not make sense for IntegerNumber implementations.

Returns:
the negative of this.
Overrides:
negate in class AbstractRationalNumber

invert

public RealNumber invert()
                                throws java.lang.ArithmeticException
Overrides:
invert in class AbstractRationalNumber

add

public RationalNumber add(RationalNumber n)
                                 throws java.lang.IllegalArgumentException
Overrides:
add in class AbstractRationalNumber

subtract

public RationalNumber subtract(RationalNumber n)
                                      throws java.lang.IllegalArgumentException
Overrides:
subtract in class AbstractRationalNumber

subtract

public IntegerNumber subtract(IntegerNumber n)
                                     throws java.lang.IllegalArgumentException
Description copied from interface:
Computes this-n, where n is an integer number.
Specified by:
subtract in interface IntegerNumber

multiply

public RationalNumber multiply(RationalNumber n)
                                      throws java.lang.IllegalArgumentException
Overrides:
multiply in class AbstractRationalNumber

divide

public RationalNumber divide(RationalNumber n)
                                    throws java.lang.IllegalArgumentException,
                                           java.lang.ArithmeticException
Overrides:
divide in class AbstractRationalNumber

pow

public RationalNumber pow(IntegerNumber n)
                                 throws java.lang.IllegalArgumentException
Overrides:
pow in class AbstractRationalNumber

getNumerator

public final IntegerNumber getNumerator()
Returns the numerator of this rational number. For an integer number, it is this, the number itself.
Returns:
the numerator, being this.

getDenominator

public final IntegerNumber getDenominator()
Returns the denominator of this rational number. For an integer number, this is allways 1.
Returns:
the denominator, being 1.

dec

public IntegerNumber dec()
Description copied from interface:
Computes this-1.
Specified by:
dec in interface IntegerNumber

inc

public IntegerNumber inc()
Description copied from interface:
Computes this+1.
Specified by:
inc in interface IntegerNumber

fac

public IntegerNumber fac()
                                throws java.lang.IllegalArgumentException
Description copied from interface:
Computes this!. The value of this cannot be negative.
Specified by:
fac in interface IntegerNumber

remainder

public IntegerNumber remainder(IntegerNumber n)
                                      throws java.lang.ArithmeticException,
                                             java.lang.IllegalArgumentException
Description copied from interface:
Computes the remainder of this/n, where n is an integer number.
Specified by:
remainder in interface IntegerNumber

gcd

public IntegerNumber gcd(IntegerNumber n)
                                throws java.lang.IllegalArgumentException
Description copied from interface:
Computes the greatest common divisor of this and n.
Specified by:
gcd in interface IntegerNumber

isRelativePrime

public boolean isRelativePrime(IntegerNumber n)
                       throws java.lang.IllegalArgumentException
Description copied from interface:
Determines if this and n are relative primes.
Specified by:
isRelativePrime in interface IntegerNumber

toString

public java.lang.String toString()
Returns a textual representation of this object.
Returns:
a String of this object.
Overrides:
toString in class AbstractRationalNumber

toBigInteger

public java.math.BigInteger toBigInteger()
Converts the value of this number to a BigInteger.
Specified by:
toBigInteger in interface IntegerNumber
Returns:
a BigInteger with the value of this.
Overrides:
toBigInteger in class AbstractRealNumber

toBigDecimal

public java.math.BigDecimal toBigDecimal()
Converts the value of this number to a BigDecimal. A precision nor a rounding mode need to be specified for integer numbers.
Specified by:
toBigDecimal in interface IntegerNumber
Returns:
a BigDecimal with the exact value of this.

toBigDecimal

public java.math.BigDecimal toBigDecimal(int precision)
                                 throws java.lang.IllegalArgumentException
Converts the value of this number to a BigDecimal with the specified precision. The precision argument is ignored, because no rounding is needed.
Parameters:
precision - the number of digits behind the decimal point.
Returns:
a BigDecimal with the exact value of this.
Throws:
java.lang.IllegalArgumentException - if precision < 0
Overrides:
toBigDecimal in class AbstractRationalNumber

toBigDecimal

public java.math.BigDecimal toBigDecimal(int precision,
                               int roundingMode)
Converts the value of this number to a BigDecimal with the specified precision and rounding mode. The precision and roundingMode arguments are ignored, because no rounding is needed.
Parameters:
precision - the number of digits behind the decimal point.
roundingMode - the rounding mode to use, one of the modes defined in class BigDecimal.
Returns:
a BigDecimal with the rounded value of this.
Throws:
java.lang.IllegalArgumentException - if one of the following applies:
  1. precision < 0
  2. roundingMode does not have a valid value
Overrides:
toBigDecimal in class AbstractRationalNumber

trunc

public final IntegerNumber trunc()
Rounds to an integer number towards 0.

The implementation of this method in AbstractIntegerNumber returns this.

Returns:
this number truncated to an integer.
Overrides:
trunc in class AbstractRationalNumber

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD