com.rubecula.jquantity
Class FuzzInt

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.BaseNumber
          extended bycom.rubecula.jquantity.MutableNumber
              extended bycom.rubecula.jquantity.WholeNumber
                  extended bycom.rubecula.jquantity.FuzzInt
All Implemented Interfaces:
Arithmetical, Arithmutable, Auditable, java.lang.Cloneable, java.lang.Comparable, Estimable, Fuzzy, FuzzyMutable, Identifiable, Integral, Millable, Mutable, Nameable, 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.

Since:
V_0_1
Version:
$Revision: 1.17 $
Author:
Robin Hillyard

Nested Class Summary
(package private)  class FuzzInt.FuzzIntException
           
 
Nested classes inherited from class com.rubecula.jquantity.WholeNumber
WholeNumber.WholeNumberException
 
Field Summary
private  double _Bound
          _Bound is the estimate of the size order of any error in the value itself (according to the model), expressed relative value of this.
private  int _Model
          _Model is the distribution model of possible errors in the value itself.
 
Fields inherited from class com.rubecula.jquantity.WholeNumber
$1, $10, $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
(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.
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.
 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.
(package private)  void setAbsError(double absBound, int model)
          MUTATING Instance method to set the abs error and model appropriately.
 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. // TODO Move this from here to the protected class-specific methods (it is not part of FuzzyMutable).
private  void setExact()
           
 void setModel(int model)
          Method to set the error distribution model;
 java.math.BigInteger toBigInteger(boolean strict)
          Convert this into a BigInteger.
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, compareTo, divide, 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
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, getBoundAbs, impartFuzziness, isEqual, 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.Mutable
isMutable, setConstant
 
Methods inherited from interface com.rubecula.jquantity.Integral
isZero
 
Methods inherited from interface com.rubecula.util.Auditable
audit, audit
 
Methods inherited from interface com.rubecula.util.Identifiable
getIdentifier
 

Field Detail

_Bound

private double _Bound
_Bound is the estimate of the size order of any error in the value itself (according to the model), expressed relative value of this.


_Model

private int _Model
_Model is the distribution model of possible errors in the value itself. The size of the errors is controlled by _Bound.

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

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
WholeNumberException - WholeNumber.factor: x should be positive

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)
              throws InvalidOperandException
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.
Throws:
InvalidOperandException

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.

setBoundAbs

protected void setBoundAbs(double bound)
Method to set the absolute bound of fuzzy value. // TODO Move this from here to the protected class-specific methods (it is not part of FuzzyMutable).

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.

toBigInteger

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

Parameters:
strict - if true, then this must be exact, otherwise we just return the equivalent big integer.
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
Overrides:
audit in class WholeNumber
Parameters:
label - the label to associate with the data
Returns:
the detailed string.

setAbsError

void setAbsError(double absBound,
                 int model)
MUTATING Instance method to set the abs error and model appropriately. NOTE: this is a package-protected method. It should only be invoked from this class or Rational.

Parameters:
absBound - the absolute error bound.
model - the error model.

setExact

private void setExact()

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.