|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.rubecula.util.Item
com.rubecula.jquantity.BaseNumber
com.rubecula.jquantity.MutableNumber
Abstract class from which to derive other concrete classes of mutable numbers.
Objects of this class can be given identifiers,
are changeable under standard arithmetic
operators, and can be cloned and presented.
Although objects of this class are constructed mutable, individual
instances can be made immutable via the method setConstant().
This allows "constant" values to be created for the class which will be
protected against mutation.
Field Summary | |
private boolean |
_Constant
This instance field signifies if this instance of MutableNumber has been designated a constant. |
private java.lang.String |
_Identifier
The string which will be used to identify this object in audit trails and for debugging. |
static BaseNumber |
$__1
The constant value: -1 |
static BaseNumber |
$0
The constant value: 0 |
static BaseNumber |
$1
The constant value: 1 |
static BaseNumber |
$10
The constant value: 10 |
static BaseNumber |
$2
The constant value: 2 |
static BaseNumber |
$3
The constant value: 3 |
private static int |
$ADD
|
private static int |
$MULTIPLY
|
private static int |
$RAISETOPOWER
|
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 | |
MutableNumber()
|
Method Summary | |
protected void |
assertMutable()
This method tests whether this particular instance is mutable, i.e. it has not been designated a constant. |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
java.lang.String |
defaultIdentifier()
|
protected abstract void |
factor(Integral divisor)
MUTATING METHOD: Replaces value with (this / divisor). |
protected BaseNumber |
factored(Integral factor)
Method to divide this exactly by factor and return the quotient as the result. |
void |
forcePositive()
MUTATING Instance method to force the value to be positive, i.e. |
java.lang.String |
getIdentifier()
Method to get the specific identifier for an object. |
java.lang.String |
getIdentifier(boolean acceptDefault)
Method to get the specific identifier for an object. |
boolean |
isLong()
Method to determine if a value is integral and within range of long. |
boolean |
isMutable()
This method indicates whether this particular instance is mutable, i.e. it has not been designated a constant. |
private BaseNumber |
opDyadic(int operator,
BaseNumber operand)
Method to operate on this number and operand according to operator. |
private BaseNumber |
opDyadicNoRecurse(int operator,
BaseNumber operand)
Method to add addend to this and return their sum as the result. |
protected BaseNumber |
product(BaseNumber multiplicand)
Method to multiply multiplicand to this and return their product as the result. |
Mutable |
setConstant()
This method sets this instance to be a constant, i.e. immutable. |
void |
setIdentifier(java.lang.String identifier)
Method to set a specific identifier to an object. |
protected void |
setIdentifierPost(java.lang.String suffix)
Method to form a new identifier for an object by appending string and wrapping. |
protected void |
setIdentifierPre(java.lang.String prefix)
Method to form a new identifier for an object by prepending string and wrapping. |
protected void |
setIdentifierPrePost(java.lang.String prefix,
java.lang.String suffix)
Method to form a new identifier for an object by prepending one string, appending another then wrapping. |
protected BaseNumber |
sum(BaseNumber addend)
Method to add addend to this and return their sum as the result. |
protected void |
test(java.io.PrintStream out,
long check,
java.lang.String label)
Convenience method for auditing/checking a MutableNumber against a long. |
Integral |
toIntegral()
Method to present a MutableNumber as an Integral number. |
Methods inherited from class com.rubecula.jquantity.BaseNumber |
abs, bestModel, BestModel, byteValue, characteristic, Characteristic, difference, doubleValue, floatValue, getBound, getBoundAbs, getModel, impartFuzziness, intValue, isEqual, isExact, isUncertain, isZero, longValue, minus, pow, scaled, shortValue, valueOf, valueOf, valueOfLog10 |
Methods inherited from class com.rubecula.util.Item |
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, toString, Wrap |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.rubecula.jquantity.Arithmutable |
add, multiply, negate, raiseToPower, scale |
Methods inherited from interface com.rubecula.jquantity.Arithmetical |
isInfinite, isInteger, isUnity, signum |
Methods inherited from interface com.rubecula.util.Auditable |
audit, audit, audit |
Methods inherited from interface com.rubecula.util.Presentable |
makePresentableInstance, present |
Field Detail |
public static final BaseNumber $0
public static final BaseNumber $1
public static final BaseNumber $2
public static final BaseNumber $3
public static final BaseNumber $10
public static final BaseNumber $__1
private static final int $ADD
private static final int $MULTIPLY
private static final int $RAISETOPOWER
private java.lang.String _Identifier
private boolean _Constant
Constructor Detail |
public MutableNumber()
Method Detail |
public java.lang.Object clone()
java.lang.Exception
- : not Cloneable (should be impossible)Cloneable
protected BaseNumber sum(BaseNumber addend) throws InvalidOperandException
opDyadicNoRecurse(int, BaseNumber)
with arguments
$ADD
and addend.
sum
in class BaseNumber
addend
- the number to add to this.
InvalidOperandException
- operands are not compatible for the
sum operation.protected BaseNumber product(BaseNumber multiplicand) throws InvalidOperandException
Method to multiply multiplicand to 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.
IF this.product(multiplicand) cannot be evaluated;
AND IF multiplicand is an instance of this
(and therefore also of MutableNumber);
THEN we can try to evaluate multiplicand.product(this).
The actual implementation of the sum is performed using method
opDyadicNoRecurse(int, BaseNumber)
,
which in turn utilizes Arithmutable.multiply(BaseNumber)
.
product
in class BaseNumber
multiplicand
- the number to add to this.
InvalidOperandException
- operands are not compatible for the
product operation.private BaseNumber opDyadic(int operator, BaseNumber operand) throws InvalidOperandException
operator
- in integer representing the operator:
$ADD
or $MULTIPLY
.operand
- the number to add to this.
InvalidOperandException
- operands are not compatible for the
operation.opDyadicNoRecurse(int, BaseNumber)
private BaseNumber opDyadicNoRecurse(int operator, BaseNumber operand) throws InvalidOperandException
operator
- in integer representing the operator: $ADD or $MULTIPLYoperand
- the number to operate on this.
InvalidOperandException
- operands are not compatible for the
operation.public boolean isLong()
public void forcePositive()
forcePositive
in interface Arithmutable
public Integral toIntegral()
public void setIdentifier(java.lang.String identifier)
setIdentifier
in interface Nameable
identifier
- the identifier to associate with the objectpublic java.lang.String getIdentifier()
getIdentifier
in interface Identifiable
public java.lang.String getIdentifier(boolean acceptDefault)
acceptDefault
- true if caller is willing to accept a generated identifier.
public java.lang.String defaultIdentifier()
protected abstract void factor(Integral divisor)
divisor
- value by which this WholeNumber is to be divided.protected BaseNumber factored(Integral factor)
factor
- the number to divide into this.
// TODO We cannot update the estimate here, since MutableNumber doesn't
implement Estimable.
I suppose we could do it if result is instanceof Estimable.
protected void setIdentifierPost(java.lang.String suffix)
suffix
- the identifier to append to object identifierprotected void setIdentifierPre(java.lang.String prefix)
prefix
- the identifier to prepend to object identifierprotected void setIdentifierPrePost(java.lang.String prefix, java.lang.String suffix)
prefix
- the identifier to prepend to object identifiersuffix
- the identifier to append to object identifierprotected void test(java.io.PrintStream out, long check, java.lang.String label)
out
- the output stream.check
- the number to compare against.label
- the label to print with the audit trals.public Mutable setConstant()
setConstant
in interface Mutable
public boolean isMutable()
isMutable
in interface Mutable
protected void assertMutable()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |