com.rubecula.jquantity
Class FuzzInt

java.lang.Object
  |
  +--java.lang.Number
        |
        +--com.rubecula.jquantity.BaseNumber
              |
              +--com.rubecula.jquantity.MutableNumber
                    |
                    +--com.rubecula.jquantity.WholeNumber
                          |
                          +--com.rubecula.jquantity.FuzzInt
All Implemented Interfaces:
Arithmetical, Arithmutable, Auditable, java.lang.Cloneable, java.lang.Comparable, Estimable, Fuzzy, FuzzyMutable, Identifiable, Integral, Mutable, Presentable, java.io.Serializable

final class FuzzInt
extends WholeNumber
implements FuzzyMutable

This class extends a WholeNumber by adding fuzzy parameters. In particular, the FuzzInt class implements setModel(), setBoundAbs() and setBoundRel().
It might seem odd at first that we have a class for fuzzy integers. How can integers be fuzzy, you might ask? The reason is that when we define a Rational as a ratio of two numbers, we want each of the top and bottom to potentially have its own error bounds and model.

Version:
$Revision: 1.8 $
Author:
Robin Hillyard

Nested Class Summary
(package private)  class FuzzInt.FuzzIntException
           
 
Nested classes inherited from class com.rubecula.jquantity.WholeNumber
WholeNumber.WholeNumberException
 
Field Summary
 
Fields inherited from class com.rubecula.jquantity.WholeNumber
$1, $10
 
Fields inherited from class com.rubecula.jquantity.MutableNumber
$__1, $0, $2, $3
 
Fields inherited from interface com.rubecula.jquantity.Fuzzy
$DistGaussian, $DistInvalid, $DistNone, $DistUniform, $Names
 
Constructor Summary
(package private) FuzzInt()
          Empty constructor.
(package private) FuzzInt(java.math.BigInteger bigInteger)
          Constructor to create an exact FuzzInt from a BigInteger.
(package private) FuzzInt(java.math.BigInteger bigInteger, double bound)
          Constructor to create a FuzzInt from a BigInteger and its bound (a uniform error model is assumed).
(package private) FuzzInt(java.math.BigInteger bigInteger, double bound, int model)
          Primary constructor to create a FuzzInt from a BigInteger, its bound and error model.
(package private) FuzzInt(java.math.BigInteger bigInteger, int model)
          Constructor to create an exact FuzzInt from a BigInteger and its error bound model.
(package private) FuzzInt(Manifest integer)
          Constructor to create an exact FuzzInt from a Manifest.
(package private) FuzzInt(Manifest integer, double bound)
          Constructor to create a FuzzInt from a Manifest and its bound (a uniform error model is assumed).
(package private) FuzzInt(Manifest integer, double bound, int model)
          Constructor to create a FuzzInt from a Manifest and its bound (a uniform error model is assumed).
(package private) FuzzInt(Manifest integer, int model)
          Constructor to create an exact FuzzInt from a Manifest and its error bound model.
(package private) FuzzInt(NumberPresentation presentation)
          Primary Constructor to create a FuzzInt by translating the given NumberPresentation representation of a FuzzInt in the specified radix.
(package private) FuzzInt(java.lang.String string)
          Secondary constructor (translates String into a NumberPresentation and then calls the primary constructor FuzzInt(NumberPresentation)).
  FuzzInt(WholeNumber number)
          Constructor to create an exact FuzzInt from a BigInteger.
 
Method Summary
 void add(BaseNumber that)
          MUTATING Instance method to add another BaseNumber 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 copy of this object.
 int compareTo(FuzzInt val)
          Compares this FuzzInt with the specified WoleNumber.
 int compareTo(Integral o)
          Compares this FuzzInt with the specified Object.
 void divide(Integral divisor)
          MUTATING METHOD: Replaces value with (this / val).
protected  void factor(Integral x)
          MUTATING METHOD: Replaces value with (this / x).
 double getBound()
          Method to get the relative bound of fuzzy value.
 int getModel()
          Method to get the error distribution model.
 boolean isExact()
          Method to return true for this non-fuzzy instance.
static void main(java.lang.String[] args)
          Main method for testing this class.
 void multiply(BaseNumber that)
          MUTATING Instance method to multiply another BaseNumber into this object.
 Presentable parse(Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
protected  BaseNumber pow(Integral 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.
protected  BaseNumber product(BaseNumber multiplicand)
          Method to multiply multiplicand by this and return their product as the result.
 void raiseToPower(int power)
          MUTATING Instance method to raise this to power x.
 void scale(long factor)
          MUTATING Instance method to multiply this by a scale factor.
 void setBound(double bound)
          Method to set the relative bound of fuzzy value.
protected  void setBoundAbs(double bound)
          Method to set the absolute bound of fuzzy value.
 void setModel(int model)
          Method to set the error distribution model;
static FuzzInt valueOf(WholeNumber source)
          Factory method to create a subclass instance of a superclass instance or, if the source is itself a FuzzInt, then to create a clone.
 
Methods inherited from class com.rubecula.jquantity.WholeNumber
compareTo, compareTo, divideAndRemainder, doubleValue, equals, floatValue, gcd, getEstimate, getValue, hashCode, intValue, isInfinite, isInteger, isPowerOfTen, isUnity, logTen, longValue, makePresentableInstance, max, min, minus, negate, pow, quotient, scaled, signum, subtract, TenToPower, toBigInteger, toString, toString, updateEstimate, valueOf, valueOf, valueOf, valueOfExponent, valueOfExponent, valueOfExponent
 
Methods inherited from class com.rubecula.jquantity.MutableNumber
factored, forcePositive, getIdentifier, isLong, setIdentifier, setIdentifierPost, setIdentifierPre, sum, test, toIntegral
 
Methods inherited from class com.rubecula.jquantity.BaseNumber
abs, audit, audit, bestModel, BestModel, Characteristic, compareTo, difference, getBoundAbs, impartFuzziness, isEqual, isUncertain, isZero, present, test, test, valueOfLog10, Wrap
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.jquantity.Integral
isZero
 
Methods inherited from interface com.rubecula.util.Auditable
audit, audit, getIdentifier
 

Constructor Detail

FuzzInt

FuzzInt()
Empty constructor. This is needed for explicit parsing purposes.


FuzzInt

FuzzInt(NumberPresentation presentation)
Primary Constructor to create a FuzzInt by translating the given NumberPresentation representation of a FuzzInt in the specified radix.

Parameters:
presentation - representation of FuzzInt.

FuzzInt

FuzzInt(java.math.BigInteger bigInteger,
        double bound,
        int model)
Primary constructor to create a FuzzInt from a BigInteger, its bound and error model.

Parameters:
bigInteger - the BigInteger we wish to widen into a FuzzInt.
bound - the absolute value of the bounds of the errors on new FuzzInt.
model - the error model for the new FuzzInt.

FuzzInt

FuzzInt(java.lang.String string)
  throws PresentationException
Secondary constructor (translates String into a NumberPresentation and then calls the primary constructor FuzzInt(NumberPresentation)).
Translates the String representation of a FuzzInt in radix 10 to a FuzzInt. The String representation consists of an optional minus sign followed by a sequence of one or more digits in the specified radix. The character-to-digit mapping is provided by Character.digit. Up to the asterisk, the String may not contain any extraneous characters (whitespace, for example).

Parameters:
string - String representation of WholeNumber followed by fuzzy information.
Throws:
java.lang.NumberFormatException - val is not a valid representation of a WholeNumber in the specified radix, or radix is outside the range from Character.MIN_RADIX (2) to Character.MAX_RADIX (36), inclusive.
PresentationException - if unable to parse string.
See Also:
Character.digit(char, int)

FuzzInt

FuzzInt(java.math.BigInteger bigInteger,
        double bound)
Constructor to create a FuzzInt from a BigInteger and its bound (a uniform error model is assumed).

Parameters:
bigInteger - the BigInteger we wish to widen into a FuzzInt.
bound - the absolute value of the bounds of the errors on new FuzzInt.

FuzzInt

FuzzInt(java.math.BigInteger bigInteger,
        int model)
Constructor to create an exact FuzzInt from a BigInteger and its error bound model. The bound is set to zero.

Parameters:
bigInteger - the BigInteger we wish to widen into a FuzzInt.
model - the error model for the new FuzzInt.

FuzzInt

public FuzzInt(WholeNumber number)
Constructor to create an exact FuzzInt from a BigInteger. (a uniform error model is assumed). The bound is set to zero.

Parameters:
number - the WholeNumber we wish to widen into a FuzzInt.

FuzzInt

FuzzInt(java.math.BigInteger bigInteger)
Constructor to create an exact FuzzInt from a BigInteger. (a uniform error model is assumed). The bound is set to zero.

Parameters:
bigInteger - the BigInteger we wish to widen into a FuzzInt.

FuzzInt

FuzzInt(Manifest integer,
        double bound,
        int model)
Constructor to create a FuzzInt from a Manifest and its bound (a uniform error model is assumed).

Parameters:
integer - the Manifest we wish to widen into a FuzzInt.
bound - the absolute value of the bounds of the errors on new FuzzInt.
model - the error model for the new FuzzInt.

FuzzInt

FuzzInt(Manifest integer,
        double bound)
Constructor to create a FuzzInt from a Manifest and its bound (a uniform error model is assumed).

Parameters:
integer - the Manifest we wish to widen into a FuzzInt.
bound - the absolute value of the bounds of the errors on new FuzzInt.

FuzzInt

FuzzInt(Manifest integer,
        int model)
Constructor to create an exact FuzzInt from a Manifest and its error bound model. The bound is set to zero.

Parameters:
integer - the Manifest we wish to widen into a FuzzInt.
model - the error model for the new FuzzInt.

FuzzInt

FuzzInt(Manifest integer)
Constructor to create an exact FuzzInt from a Manifest. (a uniform error model is assumed). The bound is set to zero.

Parameters:
integer - the Manifest we wish to widen into a FuzzInt.
Method Detail

main

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

Parameters:
args - the command line options.

valueOf

public static FuzzInt valueOf(WholeNumber source)
Factory method to create a subclass instance of a superclass instance or, if the source is itself a FuzzInt, then to create a clone.

Parameters:
source - the source value to be "widened".
Returns:
the widened version of source.

parse

public Presentable parse(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.

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

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
Overrides:
present in class WholeNumber
Parameters:
attributes - a map of the attributes desired for this presentation.
Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - if unable to present object with given attributes.

clone

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

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

product

protected BaseNumber product(BaseNumber 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.

Overrides:
product in class WholeNumber
Parameters:
multiplicand - the number to multiply by this.
Returns:
the product of this and multiplicand.

pow

protected BaseNumber pow(Integral 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.

Parameters:
power - the exponent for this.
Returns:
the value of this rraised to the power power.

factor

protected void factor(Integral x)
MUTATING METHOD: Replaces value with (this / x).
This method differs from divide in that here, x must be an exact positive factor of this otherwise an exception will be thrown.

Overrides:
factor in class WholeNumber
Parameters:
x - value by which this WholeNumber is to be divided.
Throws:
WholeNumberException - WholeNumber.factor: x is not a factor

raiseToPower

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

Specified by:
raiseToPower in interface Arithmutable
Overrides:
raiseToPower in class WholeNumber
Parameters:
power - the number of times this should be multiplied by itself.
Throws:
JQuantityException: - non-negative power. (This would cause the operation to yield a non-integer value.)
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
Overrides:
scale in class WholeNumber
Parameters:
factor - the scale factor.

add

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

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

multiply

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

Specified by:
multiply in interface Arithmutable
Overrides:
multiply in class WholeNumber
Parameters:
that - the multiplicand.

divide

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

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

getBound

public double getBound()
Method to get the relative bound of fuzzy value. Override method in BaseNumber.

Specified by:
getBound in interface Fuzzy
Overrides:
getBound in class BaseNumber
Returns:
the relative bound.

getModel

public int getModel()
Method to get the error distribution model. Override method in BaseNumber.

Specified by:
getModel in interface Fuzzy
Overrides:
getModel in class BaseNumber
Returns:
the distribution model. $DistNone, $DistUniform or $DistGaussian.

isExact

public boolean isExact()
Method to return true for this non-fuzzy instance. Override method in BaseNumber.

Specified by:
isExact in interface Fuzzy
Overrides:
isExact in class BaseNumber
Returns:
true if the bounds of this object are NONE or zero.

compareTo

public int compareTo(Integral o)
Compares this FuzzInt with the specified Object. If the Object is a WholeNumber, this method behaves like compareTo(WholeNumber). Otherwise, it throws a ClassCastException (as FuzzInts are comparable only to other FuzzInts or BigIntegers).

Overrides:
compareTo in class WholeNumber
Parameters:
o - Object 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:
FuzzInt.FuzzIntException - FuzzInt.compareTo(object): cannot compare
Since:
1.2
See Also:
compareTo(FuzzInt), Comparable

setBoundAbs

protected void setBoundAbs(double bound)
Method to set the absolute bound of fuzzy value.

Parameters:
bound - the absolute bound.

setBound

public void setBound(double bound)
Method to set the relative bound of fuzzy value.

Specified by:
setBound in interface FuzzyMutable
Parameters:
bound - the relative bound.

setModel

public void setModel(int model)
Method to set the error distribution model;

Specified by:
setModel in interface FuzzyMutable
Parameters:
model - the distribution model: $DistNone, $DistUniform or $DistGaussian.

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
Overrides:
audit in class WholeNumber
Parameters:
label - the label to associate with the data
Returns:
the detailed string.

compareTo

public int compareTo(FuzzInt val)
Compares this FuzzInt with the specified WoleNumber. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.

Parameters:
val - WholeNumber to which this WholeNumber is to be compared.
Returns:
-1, 0 or 1 as this FuzzInt is numerically less than, equal to, or greater than val.