com.rubecula.jquantity
Class WholeNumber

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.BaseNumber
          extended bycom.rubecula.jquantity.MutableNumber
              extended bycom.rubecula.jquantity.WholeNumber
All Implemented Interfaces:
Arithmetical, Arithmutable, Auditable, java.lang.Cloneable, java.lang.Comparable, Estimable, Fuzzy, Identifiable, Integral, Millable, Mutable, Nameable, Presentable, java.io.Serializable
Direct Known Subclasses:
FuzzInt

public class WholeNumber
extends MutableNumber
implements Estimable, Integral

This class is a logical extension of the BigInteger class, but is an actual extension of MutableNumber. It also implements the Estimable and Integral interfaces. The objects of this class are exact integers (without size limitation).

Note that I would have preferred to extend BigInteger rather than referencing it in an instance field but that proved to be impossible because BigInteger does not provide any mutating methods (see Arithmetical for comments on why this matters).

Note also that this is not a perfect extension of BigInteger. In particular, some of the names have changed because the convention used in this package is that a verb name implies a mutating operation, whereas a noun name tends to imply an operation that returns a new object. For example, the equivalent of BigInteger.negate() is WholeNumber.minus(). WholeNumber.negate() is a mutating method, returning void.

Version:
$Revision: 1.24 $ // TODO This class contains several commented-out delegate methods which, if uncommented, would make WholeNumber behave as if it were a BigInteger. They are not strictly necessary so for now, have been commented out.
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
 class WholeNumber.WholeNumberException
           
 
Field Summary
private  double _Estimate
           
private  java.math.BigInteger _Super
          This is a reference to the super instance (a BigInteger) which we would have preferred to simply extend.
static WholeNumber $1
          $1 is the WholeNumber representation of the exact value 1.
static WholeNumber $10
          $10 is the WholeNumber representation of the exact value 10.
static java.math.BigInteger $10B
           
 
Fields inherited from class com.rubecula.jquantity.MutableNumber
$__1, $0, $2, $3
 
Fields inherited from class com.rubecula.jquantity.BaseNumber
 
Fields inherited from class com.rubecula.util.Item
JQUANTITY_TEST
 
Fields inherited from interface com.rubecula.jquantity.Fuzzy
$DistGaussian, $DistInvalid, $DistNone, $DistUniform, $Names
 
Constructor Summary
protected WholeNumber()
          This constructor is here solely for the purpose of working around the fact that interfaces may not define class methods.
  WholeNumber(java.math.BigInteger bigInteger)
          Constructs an identified WholeNumber from a BigInteger.
  WholeNumber(java.math.BigInteger bigInteger, java.lang.String identifier)
          Primary constructor to create a WholeNumber from a BigInteger.
  WholeNumber(IntegerPresentation presentation)
          Constructs a WholeNumber from a NumberPresentation.
  WholeNumber(Integral integer)
          Constructs a WholeNumber from a Manifest using a default Identifier.
  WholeNumber(Integral integer, java.lang.String identifier)
          Constructs a WholeNumber from a Manifest and an identifier.
  WholeNumber(java.lang.String string)
          Constructs a WholeNumber from a String.
 
Method Summary
 void add(BaseNumber that)
          MUTATING Instance method to add another Arithmetical into this object.
 java.lang.String audit(java.lang.String label)
          Method to return a detailed string from an arithmetical object for debugging purposes.
 java.lang.Object clone()
          Creates and returns a deep copy of this object.
 int compareTo(java.math.BigInteger o)
          Compares this WholeNumber with the specified Object o.
 int compareTo(Integral o)
          Compares this WholeNumber with the specified Object o.
 int compareTo(WholeNumber o)
          Compares this WholeNumber with the specified Object o.
 void divide(Integral divisor)
          MUTATING METHOD: Replaces value with (this / divisor).
 java.math.BigInteger[] divideAndRemainder(Integral divisor)
          Returns an array of two BigIntegers containing (this / divisor) followed by (this % divisor).
 double doubleValue()
          Converts this WholeNumber to a double.
 boolean equals(java.lang.Object x)
          Compares this WholeNumber with the specified Object for equality.
protected  void factor(Integral factor)
          MUTATING METHOD: Replaces value with (this / divisor).
 float floatValue()
          Converts this WholeNumber to a float.
 java.math.BigInteger gcd(Integral val)
          Returns a BigInteger whose value is the greatest common divisor of abs(this) and abs(val).
 double getEstimate()
          Method to get the current estimate of an arithmetical value.
protected  java.math.BigInteger getValue()
          Protected method to get the value as a BigInteger.
 int hashCode()
          Returns the hash code for this WholeNumber.
 int intValue()
          Converts this WholeNumber to an int.
 boolean isInfinite()
          Method to determine if an arithmetical object is infinite.
 boolean isInteger()
          Method determines if it is safe and appropriate to convert this arithmetical object into a long.
 boolean isPowerOfTen()
          Method to determine if this is a power of ten and ten only.
 boolean isUnity()
          Method to determine if this arithmetical object has the value of 1.
(package private)  int logTen()
          Method to determine how many times ten divides into this.
 long longValue()
          Converts this WholeNumber to a long.
static void main(java.lang.String[] args)
          Main method for testing this class.
 Presentable makePresentableInstance(Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
 WholeNumber max(WholeNumber val)
          Returns the maximum of this WholeNumber and val.
 WholeNumber min(WholeNumber val)
          Returns the minimum of this WholeNumber and val.
 BaseNumber minus()
          Method to yield a copy of this but with the sign changed.
 void multiply(BaseNumber that)
          MUTATING Instance method to multiply another BaseNumber into this object.
 void negate()
          MUTATING Instance method to negate this.
protected  BaseNumber pow(int power)
          Method to raise this to the power power return the result.
 Presentation present(AttrMap attributes)
          Convert this Presentable object into a Presentation, according to the set of attributes provided.
private  Presentation present(boolean exponential)
          Method to convert this WholeNumber into an equivalent Presentation, using radix 10 and exponential form.
private  Presentation present(int radix)
          Method to convert this WholeNumber into an equivalent Presentation using non-exponential form.
private  Presentation present(int radix, boolean exponential)
          Method to convert this WholeNumber into an equivalent Presentation.
 WholeNumber quotient(Integral that)
          Method to divide a WholeNumber by an Integral number.
 void raiseToPower(int power)
          MUTATING Instance method to raise this to power power.
 void scale(long factor)
          MUTATING Instance method to multiply this by a scale factor.
protected  BaseNumber scaled(long multiplicand)
          Method to multiply multiplicand by this and return their product as the result.
private  void setValue(java.math.BigInteger value)
          MUTATING method to set a new value.
 int signum()
          Method to find the sign of the magnitude of this arithmetical object.
 void subtract(WholeNumber subtrahend)
          MUTATING METHOD: Replaces value with (this - val).
static WholeNumber TenToPower(int index)
          Factory method to create a WholeNumber equal to ten to the power of index.
 java.math.BigInteger toBigInteger()
          Convert this into a BigInteger.
 java.lang.String toString()
          Returns the decimal String representation of this WholeNumber.
 java.lang.String toString(int radix)
          Returns the String representation of this WholeNumber in the given radix.
 void updateEstimate()
          MUTATING method to update the current estimate.
static WholeNumber valueOf(BaseNumber number)
          Factory method to create a WholeNumber from an instance of BaseNumber, which is also Integral.
static WholeNumber valueOf(Integral number)
          Factory method to create a WholeNumber from an instance of Integral, such as a Manifest, which is not a BaseNumber.
static WholeNumber valueOf(java.lang.String string, int radix)
          Factory method to create a WholeNumber from a string, and being interpreted in base radix.
(package private) static WholeNumber valueOfExponent(int exponent)
          Factory method to create a Rational which is equal to 10^exponent.
(package private) static WholeNumber valueOfExponent(int exponent, int radix)
          Factory method to create a WholeNumber which is equal to radix^exponent.
(package private) static WholeNumber valueOfExponent(java.lang.String exponentStr, int radix)
          Factory method to create a Rational which is equal to the multiplier represented by an exponent string.
 
Methods inherited from class com.rubecula.jquantity.MutableNumber
assertMutable, defaultIdentifier, factored, forcePositive, getIdentifier, getIdentifier, isLong, isMutable, product, setConstant, setIdentifier, setIdentifierPost, setIdentifierPre, setIdentifierPrePost, sum, test, toIntegral
 
Methods inherited from class com.rubecula.jquantity.BaseNumber
abs, bestModel, BestModel, byteValue, characteristic, Characteristic, difference, getBound, getBoundAbs, getModel, impartFuzziness, isEqual, isExact, isUncertain, isZero, shortValue, valueOf, valueOf, valueOfLog10
 
Methods inherited from class com.rubecula.util.Item
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, Wrap
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.jquantity.Integral
isExact, isZero
 
Methods inherited from interface com.rubecula.util.Auditable
audit, audit
 
Methods inherited from interface com.rubecula.util.Identifiable
getIdentifier
 

Field Detail

$1

public static final WholeNumber $1
$1 is the WholeNumber representation of the exact value 1.


$10B

public static final java.math.BigInteger $10B

$10

public static final WholeNumber $10
$10 is the WholeNumber representation of the exact value 10.
Note: this is needed to override MutableNumber.$10 for use in TenToPower(int).


_Estimate

private double _Estimate

_Super

private java.math.BigInteger _Super
This is a reference to the super instance (a BigInteger) which we would have preferred to simply extend. That proved impossible when it turned out that BigInteger neither supports any mutating methods, not does it expose the methods or fields which would allow the implementation of such mutating methods in a superclass.

Constructor Detail

WholeNumber

public WholeNumber(java.math.BigInteger bigInteger,
                   java.lang.String identifier)
            throws WholeNumber.WholeNumberException
Primary constructor to create a WholeNumber from a BigInteger. Identification depends on the value of identifier.
Note that all constructors must either use this constructor or must ensure that _Super is set to a non-null value (there are no assertions in the rest of the code to ensure this condition, and if it is not met, null pointer exceptions will be thrown).

Parameters:
bigInteger - the value to widen (must be non-null).
identifier - the identifier for this WholeNumber (may be null).
Throws:
WholeNumber.WholeNumberException - WholeNumber(x): null argument.

WholeNumber

public WholeNumber(java.math.BigInteger bigInteger)
Constructs an identified WholeNumber from a BigInteger.

Parameters:
bigInteger - the value of copy.

WholeNumber

public WholeNumber(IntegerPresentation presentation)
Constructs a WholeNumber from a NumberPresentation.

Parameters:
presentation - the string form to use.

WholeNumber

public WholeNumber(java.lang.String string)
            throws PresentationException
Constructs a WholeNumber from a String. The string is first turned into a IntegerPresentation and then passed to the appropriate constructor.

Parameters:
string - a String in the form required by IntegerPresentation.
Throws:
PresentationException - when string cannot be parsed.

WholeNumber

public WholeNumber(Integral integer,
                   java.lang.String identifier)
Constructs a WholeNumber from a Manifest and an identifier.

Parameters:
integer - the Manifest (pure constant number) from which this WholeNumber will be widened. Must be non-null otherwise a NullPointerException will be thrown.
identifier - the identifier for this WholeNumber (may be null).

WholeNumber

public WholeNumber(Integral integer)
Constructs a WholeNumber from a Manifest using a default Identifier.

Parameters:
integer - the Manifest (pure constant number) from which this WholeNumber will be widened. Must be non-null otherwise a NullPointerException will be thrown.

WholeNumber

protected WholeNumber()
This constructor is here solely for the purpose of working around the fact that interfaces may not define class methods. Why?? Anyway, because Presentable defines an (instance) method: valueOf(Presentation), we must be able to create an arbitrary instance of WholeNumber on which to invoke the valueOf method.
Yields a WholeNumber whose value is 0.

Method Detail

valueOf

public static WholeNumber valueOf(BaseNumber number)
Factory method to create a WholeNumber from an instance of BaseNumber, which is also Integral. Note that if x is a WholeNumber, then the argument itself will be returned (i.e. it is NOT equivalent to clone()).
If number is not a WholeNumber but is Integral, it is passed for processing to valueOf(Integral).

Parameters:
number - the BaseNumber to be widened into WholeNumber and which must be an Integral object.
Returns:
the widened value.
Throws:
JQuantityException - number is not Integral.

valueOf

public static WholeNumber valueOf(Integral number)
Factory method to create a WholeNumber from an instance of Integral, such as a Manifest, which is not a BaseNumber.
To create the new object, the following constructor is used: WholeNumber(BigInteger,String) with the two arguments given as: Integral.toBigInteger() and Identifiable.getIdentifier() both applied to number.

Parameters:
number - the value to be widened into WholeNumber.
Returns:
the widened value.

valueOf

public static WholeNumber valueOf(java.lang.String string,
                                  int radix)
Factory method to create a WholeNumber from a string, and being interpreted in base radix.

Parameters:
string - the value to be parsed into WholeNumber.
radix - the radix with which the string is to be interpreted.
Returns:
the parsed value.
See Also:
WholeNumber(BigInteger), BigInteger.BigInteger(java.lang.String, int)

TenToPower

public static WholeNumber TenToPower(int index)
Factory method to create a WholeNumber equal to ten to the power of index.

Parameters:
index - the exponent of ten.
Returns:
$10 to the power of index using method pow(int)

valueOfExponent

static WholeNumber valueOfExponent(int exponent,
                                   int radix)
Factory method to create a WholeNumber which is equal to radix^exponent.

Parameters:
exponent - the power to which radix is to be raised.
radix - the base of the number system.
Returns:
radix^exponent.
Throws:
JQuantityException - if exponent is less than zero.
See Also:
BigInteger.valueOf(long), BigInteger.pow(int), Math.abs(int), WholeNumber(BigInteger)

valueOfExponent

static WholeNumber valueOfExponent(int exponent)
Factory method to create a Rational which is equal to 10^exponent.

Parameters:
exponent - the power to which radix is to be raised.
Returns:
10^exponent using either of the following methods: if exponent is non-negative, then TenToPower(int), else valueOfExponent(int,int) with the second argument of 10.

valueOfExponent

static WholeNumber valueOfExponent(java.lang.String exponentStr,
                                   int radix)
Factory method to create a Rational which is equal to the multiplier represented by an exponent string.

Parameters:
exponentStr - the power to which radix is to be raised, as a string.
radix - the base of the number system in which exponentStr is to be interpreted and also the number to be raised by the appropriate power.
Returns:
exponentStr as a multiplier using one of the following: if exponentStr is null, empty or "0", then return $1 else get the exponent as an int using Integer.parseInt(java.lang.String, int) and then pass it, with the radix, into valueOfExponent(int,int).
Throws:
JQuantityException - WholeNumber.exponent: invalid exponent string: exponentStr for radix: radix.

main

public static void main(java.lang.String[] args)
Main method for testing this class.

Parameters:
args - the command line options.

intValue

public int intValue()
Converts this WholeNumber to an int. Standard narrowing primitive conversion as defined in The Java Language Specification: if this WholeNumber is too big to fit in an int, only the low-order 32 bits are returned.

Specified by:
intValue in interface Integral
Specified by:
intValue in class BaseNumber
Returns:
this WholeNumber converted to an int.

longValue

public long longValue()
Converts this WholeNumber to a long. Standard narrowing primitive conversion as defined in The Java Language Specification: if this WholeNumber is too big to fit in a long, only the low-order 64 bits are returned.

Specified by:
longValue in interface Integral
Specified by:
longValue in class BaseNumber
Returns:
this WholeNumber converted to a long.

floatValue

public float floatValue()
Converts this WholeNumber to a float. Similar to the double-to-float narrowing primitive conversion defined in The Java Language Specification: if this WholeNumber has too great a magnitude to represent as a float, it will be converted to infinity or negative infinity, as appropriate.

Specified by:
floatValue in class BaseNumber
Returns:
this WholeNumber converted to a float.

doubleValue

public double doubleValue()
Converts this WholeNumber to a double. Similar to the double-to-float narrowing primitive conversion defined in The Java Language Specification: if this WholeNumber has too great a magnitude to represent as a double, it will be converted to infinity or negative infinity, as appropriate.

Specified by:
doubleValue in class BaseNumber
Returns:
this WholeNumber converted to a double.

clone

public java.lang.Object clone()
Creates and returns a deep copy of this object.

Overrides:
clone in class MutableNumber
Returns:
a clone of this instance.
Throws:
WholeNumber.WholeNumberException - : WholeNumber not Cloneable (should be impossible)
See Also:
Cloneable

isInfinite

public boolean isInfinite()
Method to determine if an arithmetical object is infinite.

Specified by:
isInfinite in interface Arithmetical
Returns:
true if object is infinite in value.

isInteger

public boolean isInteger()
Method determines if it is safe and appropriate to convert this arithmetical object into a long.

Specified by:
isInteger in interface Arithmetical
Returns:
true if longVal() would yield an equivalent value.

isUnity

public boolean isUnity()
Method to determine if this arithmetical object has the value of 1.

Specified by:
isUnity in interface Arithmetical
Returns:
true if value is 1.

signum

public int signum()
Method to find the sign of the magnitude of this arithmetical object.

Specified by:
signum in interface Arithmetical
Returns:
0 if value is 0; 1 if value is positive; -1 if value is negative.

raiseToPower

public void raiseToPower(int power)
MUTATING Instance method to raise this to power power.

Specified by:
raiseToPower in interface Arithmutable
Parameters:
power - the number of times this should be multiplied by itself.
See Also:
BigInteger.pow(int)

scale

public void scale(long factor)
MUTATING Instance method to multiply this by a scale factor. Note that under this operation, the scaling (multiplication) is always directly on the value in this regardless of type. So for example, if this is an instance of Value of type Log, then the effect of a scale by rwo will be to square the effective value.

Specified by:
scale in interface Arithmutable
Parameters:
factor - the scale factor.

negate

public void negate()
MUTATING Instance method to negate this.

Specified by:
negate in interface Arithmutable

add

public void add(BaseNumber that)
MUTATING Instance method to add another Arithmetical into this object.

Specified by:
add in interface Arithmutable
Parameters:
that - the addend.

multiply

public void multiply(BaseNumber that)
              throws InvalidOperandException
MUTATING Instance method to multiply another BaseNumber into this object.

Specified by:
multiply in interface Arithmutable
Parameters:
that - the multiplicand.
Throws:
InvalidOperandException

updateEstimate

public void updateEstimate()
MUTATING method to update the current estimate.

Specified by:
updateEstimate in interface Estimable

getEstimate

public double getEstimate()
Method to get the current estimate of an arithmetical value.

Specified by:
getEstimate in interface Estimable
Returns:
the current estimate.

toBigInteger

public java.math.BigInteger toBigInteger()
Convert this into a BigInteger.

Specified by:
toBigInteger in interface Integral
Returns:
the BigInteger equivalent of this.

audit

public java.lang.String audit(java.lang.String label)
Method to return a detailed string from an arithmetical object for debugging purposes.

Specified by:
audit in interface Auditable
Parameters:
label - the label to associate with the data
Returns:
the detailed string.

compareTo

public int compareTo(java.math.BigInteger o)
Compares this WholeNumber with the specified Object o. If o is a BigInteger, the result is equal to getValue().BigInteger.compareTo(Object); else if o is Integral, the result is equal to Item.compareTo(Object) using Integral.toBigInteger() as the argument; else if o is Integer or Long, the result is equal to Item.compareTo(Object) using Manifest.Manifest(long) with Number.longValue() as the argument; otherwise a WholeNumberException is thrown.

Parameters:
o - BigInteger to which this WholeNumber is to be compared.
Returns:
a negative number, zero, or a positive number as this WholeNumber is numerically less than, equal to, or greater than o, which must be a WholeNumber.
Throws:
WholeNumber.WholeNumberException - Cannot compare with object of class: class.
Since:
1.2
See Also:
Comparable

compareTo

public int compareTo(Integral o)
Compares this WholeNumber with the specified Object o. If o is a BigInteger, the result is equal to getValue().BigInteger.compareTo(Object); else if o is Integral, the result is equal to Item.compareTo(Object) using Integral.toBigInteger() as the argument; else if o is Integer or Long, the result is equal to Item.compareTo(Object) using Manifest.Manifest(long) with Number.longValue() as the argument; otherwise a WholeNumberException is thrown.

Parameters:
o - Integral to which this WholeNumber is to be compared.
Returns:
a negative number, zero, or a positive number as this WholeNumber is numerically less than, equal to, or greater than o, which must be a WholeNumber.
Throws:
WholeNumber.WholeNumberException - Cannot compare with object of class: class.
Since:
1.2
See Also:
Comparable

compareTo

public int compareTo(WholeNumber o)
Compares this WholeNumber with the specified Object o. If o is a BigInteger, the result is equal to getValue().BigInteger.compareTo(Object); else if o is Integral, the result is equal to Item.compareTo(Object) using Integral.toBigInteger() as the argument; else if o is Integer or Long, the result is equal to Item.compareTo(Object) using Manifest.Manifest(long) with Number.longValue() as the argument; otherwise a WholeNumberException is thrown.

Parameters:
o - Integral to which this WholeNumber is to be compared.
Returns:
a negative number, zero, or a positive number as this WholeNumber is numerically less than, equal to, or greater than o, which must be a WholeNumber.
Throws:
WholeNumber.WholeNumberException - Cannot compare with object of class: class.
Since:
1.2
See Also:
Comparable

makePresentableInstance

public Presentable makePresentableInstance(Presentation presentation)
                                    throws PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Specified by:
makePresentableInstance in interface Presentable
Parameters:
presentation - a presentation of a number which you want to convert into a number.
Returns:
a number in the form of a Presentable.
Throws:
PresentationException - if presentation cannot be parsed appropriately.

present

public Presentation present(AttrMap attributes)
                     throws PresentationException
Convert this Presentable object into a Presentation, according to the set of attributes provided.

Specified by:
present in interface Presentable
Parameters:
attributes - the map of attributes required for the presentation.
Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - when string cannot be parsed.

minus

public BaseNumber minus()
Method to yield a copy of this but with the sign changed. (Required to fulfill contract defined by BaseNumber).

Specified by:
minus in interface Integral
Specified by:
minus in class BaseNumber
Returns:
negative version of this.

scaled

protected BaseNumber scaled(long multiplicand)
Method to multiply multiplicand by this and return their product as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.

Specified by:
scaled in class BaseNumber
Parameters:
multiplicand - the number to multiply this by.
Returns:
the product of this and multiplicand (a WholeNumber).

pow

protected BaseNumber pow(int power)
Method to raise this to the power power return the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.
The result might not be a new object.

Specified by:
pow in class BaseNumber
Parameters:
power - the exponent for this.
Returns:
the value of this raised to the power power.

factor

protected void factor(Integral factor)
MUTATING METHOD: Replaces value with (this / divisor).
This method allows for division by a non-Divisible divisor. In some implementations, an exception will be thrown if the quotient cannot be expressed (for example it is non-integral for a WholeNumber).
This method differs from divide in that here, x must be an exact positive factor of this otherwise an exception will be thrown.

Specified by:
factor in class MutableNumber
Parameters:
factor - value by which this WholeNumber is to be divided.
Throws:
WholeNumberException: - WholeNumber.factor: factor is not a factor
WholeNumberException: - WholeNumber.factor: factor should be positive

quotient

public WholeNumber quotient(Integral that)
Method to divide a WholeNumber by an Integral number.

Parameters:
that - WholeNumber (or WholeNumber): the divisor (denominator).
Returns:
the quotient of this over that.

subtract

public void subtract(WholeNumber subtrahend)
MUTATING METHOD: Replaces value with (this - val).

Parameters:
subtrahend - value to be subtracted from this WholeNumber.

divide

public void divide(Integral divisor)
MUTATING METHOD: Replaces value with (this / divisor).

Parameters:
divisor - value by which this WholeNumber is to be divided.
Throws:
java.lang.ArithmeticException - divisor==0

divideAndRemainder

public java.math.BigInteger[] divideAndRemainder(Integral divisor)
Returns an array of two BigIntegers containing (this / divisor) followed by (this % divisor).

Parameters:
divisor - value by which this WholeNumber is to be divided, and the remainder computed.
Returns:
an array of two BigIntegers: the quotient (this / divisor) is the initial element, and the remainder (this % divisor) is the final element.
Throws:
java.lang.ArithmeticException - val==0

gcd

public java.math.BigInteger gcd(Integral val)
Returns a BigInteger whose value is the greatest common divisor of abs(this) and abs(val). Returns 0 if this==0 && val==0.

Parameters:
val - value with with the GCD is to be computed.
Returns:
GCD(abs(this), abs(val))

equals

public boolean equals(java.lang.Object x)
Compares this WholeNumber with the specified Object for equality.

Parameters:
x - Object to which this WholeNumber is to be compared.
Returns:
true if and only if the specified Object is a WholeNumber whose value is numerically equal to this WholeNumber.

min

public WholeNumber min(WholeNumber val)
Returns the minimum of this WholeNumber and val.

Parameters:
val - value with with the minimum is to be computed.
Returns:
the WholeNumber whose value is the lesser of this WholeNumber and val. If they are equal, either may be returned.

max

public WholeNumber max(WholeNumber val)
Returns the maximum of this WholeNumber and val.

Parameters:
val - value with with the maximum is to be computed.
Returns:
the WholeNumber whose value is the greater of this and val. If they are equal, either may be returned.

hashCode

public int hashCode()
Returns the hash code for this WholeNumber.

Returns:
hash code for this WholeNumber.

toString

public java.lang.String toString(int radix)
Returns the String representation of this WholeNumber in the given radix. If the radix is outside the range from Character.MIN_RADIX (2) to Character.MAX_RADIX (36) inclusive, it will default to 10 (as is the case for Integer.toString). The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String, int) constructor.)

Parameters:
radix - radix of the String representation.
Returns:
String representation of this WholeNumber in the given radix.
See Also:
Integer.toString(), Character.forDigit(int, int), getValue(), toString(int)

toString

public java.lang.String toString()
Returns the decimal String representation of this WholeNumber. The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String) constructor, and allows for String concatenation with Java's + operator.)

Overrides:
toString in class Item
Returns:
decimal String representation of this WholeNumber.
See Also:
Character.forDigit(int, int), WholeNumber(java.lang.String)

getValue

protected final java.math.BigInteger getValue()
Protected method to get the value as a BigInteger.
Note that this method differs from toBigInteger() in that the latter will throw an exception if this is not exact.
All accessor references are implemented by invoking getValue(), and all mutator references are implemented by invoking setValue(BigInteger).

Returns:
the current value as a BigInteger.

logTen

final int logTen()
Method to determine how many times ten divides into this.
WARNING: do not be confused by the name of this method. It does not function as the customary meaning of log10. In fact, this method yields the number of trailing zeroes in this. Therefore, log10 and logTen will only be equal if isPowerOfTen() is true.

Returns:
0 if this is not a multiple of ten, otherwise, 1 + quotient .logTen()where quotient is a WholeNumber whose value is this/$10.

isPowerOfTen

public boolean isPowerOfTen()
Method to determine if this is a power of ten and ten only.

Specified by:
isPowerOfTen in interface Integral
Returns:
true if this can be successively divided exactly by ten until 1 is the only remaining factor.

present

private Presentation present(int radix,
                             boolean exponential)
                      throws PresentationException
Method to convert this WholeNumber into an equivalent Presentation.

Parameters:
radix - the radix in which the presentation will be made.
exponential - true if the number is to be presented in the form xEn.
Returns:
a NumberPresentation which is equivalent value-wise to this.
Throws:
PresentationException - when string cannot be parsed.

present

private Presentation present(int radix)
                      throws PresentationException
Method to convert this WholeNumber into an equivalent Presentation using non-exponential form.

Parameters:
radix - the radix in which the presentation will be made.
Returns:
a NumberPresentation which is equivalent value-wise to this.
Throws:
PresentationException - when string cannot be parsed.

present

private Presentation present(boolean exponential)
                      throws PresentationException
Method to convert this WholeNumber into an equivalent Presentation, using radix 10 and exponential form.

Parameters:
exponential - true if the number is to be presented in the form xEn.
Returns:
a NumberPresentation which is equivalent value-wise to this.
Throws:
PresentationException - when string cannot be parsed.

setValue

private final void setValue(java.math.BigInteger value)
MUTATING method to set a new value.

Parameters:
value - the BigInteger which is to be the value of this WholeNumber from now on. In addition, updateEstimate()is called.