|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.lang.Number
|
+--com.rubecula.jquantity.BaseNumber
Abstract numerical class from which to derive other concrete classes. Objects of this class can be characterized as to their value, can be "audited", that is to say viewed in detail, and can be compared with other objects. Objects of this class "may be" fuzzy - that is they support the Fuzzy interface. Instances of this class can also be "presented", resulting in an instance of Presentation (which in turn can be rendered as a string).
| Field Summary |
| Fields inherited from interface com.rubecula.jquantity.Fuzzy |
$DistGaussian, $DistInvalid, $DistNone, $DistUniform, $Names |
| Constructor Summary | |
BaseNumber()
|
|
| Method Summary | |
protected BaseNumber |
abs()
Method to yield this or a copy with the sign changed, depending whether the value is positive or negative. |
java.lang.String |
audit()
Method to return a detailed (unlabeled) string from an object for debugging purposes. |
void |
audit(java.io.PrintStream out,
java.lang.String label)
Method to output detailed string from an object for debugging purposes. |
int |
bestModel(Fuzzy that)
Method to help in combining distribution models. |
protected static int |
BestModel(int modelX,
int modelY)
Class method to help in combining distribution models. |
(package private) static int |
Characteristic(double x)
Method to yield the characteristic of value x (whether positive or negative). |
int |
compareTo(java.lang.Object that)
This method is the default compareTo method for any objects in the JQuantity package. |
protected BaseNumber |
difference(BaseNumber subtrahend)
Method to yield the difference of this less a BaseNumber (subtrahend). |
double |
getBound()
Method to get the relative bound of this non-fuzzy value; |
double |
getBoundAbs()
Method to get the absolute bound of this non-fuzzy value; |
int |
getModel()
Method to get the error distribution model of this non-fuzzy value. |
Presentation |
impartFuzziness(NumberPresentation presentation)
Method to impart a NumberPresentation presentation with appropriate fuzzy information and ensure that the resulting string value is properly rounded. |
boolean |
isEqual(BaseNumber other)
Method to determine effect equality with another BaseNumber. |
boolean |
isExact()
Method to return true for this non-fuzzy instance. |
boolean |
isUncertain()
Method to determine if this object is of uncertain value due to fuzziness. |
boolean |
isZero()
Method to make standard test against zero. |
protected abstract BaseNumber |
minus()
Method to yield a copy of this but with the sign changed. |
protected abstract BaseNumber |
pow(int power)
Method to raise this to the power power return the result. |
Presentation |
present()
Convert this Presentable object into a Presentation with default attributes. |
protected abstract BaseNumber |
product(BaseNumber multiplicand)
Method to multiply multiplicand by this and return their product as the result. |
protected abstract BaseNumber |
scaled(long factor)
Method to multiply multiplicand by this and return their product as the result. |
protected abstract BaseNumber |
sum(BaseNumber addend)
Method to add addend to this and return their sum as the result. |
protected void |
test(java.io.PrintStream out,
BaseNumber check)
|
protected void |
test(java.io.PrintStream out,
BaseNumber check,
java.lang.String label)
|
java.lang.String |
toString()
This is the default toString method for all BaseNumbers. |
(package private) static double |
valueOfLog10(double x)
|
protected static java.lang.String |
Wrap(java.lang.String string)
Class method to wrap a string in "<" and ">". |
| 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, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.rubecula.util.Presentable |
makePresentableInstance, present |
| Methods inherited from interface com.rubecula.jquantity.Arithmetical |
isInfinite, isInteger, isUnity, signum |
| Methods inherited from interface com.rubecula.util.Auditable |
audit, getIdentifier |
| Constructor Detail |
public BaseNumber()
| Method Detail |
protected static java.lang.String Wrap(java.lang.String string)
string - the string to be wrapped.
protected static int BestModel(int modelX,
int modelY)
modelX - the first model to combine.modelY - the second model to combine.
protected abstract BaseNumber minus()
Method to yield a copy of this but with the sign changed.
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.
Note that this method is parallel but not congruent with the method of the same name defined in the Integral interface.
protected abstract BaseNumber sum(BaseNumber addend)
throws InvalidOperandException
addend - the number to add to this.
InvalidOperandException - if the operands are incompatible.
protected BaseNumber difference(BaseNumber subtrahend)
throws InvalidOperandException
subtrahend - the number to subtract from this.
InvalidOperandException - if the operands are incompatible.
protected abstract BaseNumber product(BaseNumber multiplicand)
throws InvalidOperandException
multiplicand - the number to multiply by this.
InvalidOperandException - if the operands are incompatible.protected abstract BaseNumber scaled(long factor)
factor - the number to multiply by this.
protected abstract BaseNumber pow(int power)
power - the exponent for this.
public int compareTo(java.lang.Object that)
This method is the default compareTo method for any objects in the JQuantity package. If it is invoked, then there was no method declared which matched the objects more precisely. Each subclass (A) of BaseNumber is expected to declare a method of signature int compareTo(A). Furthermore, any subclass (A) of a class (B) which is itself a subclass of BaseNumber should provide a public constructor with signature: A(B).
So why is this method necessary at all?
Surely polymporphism takes care of all this stuff?
Well, not quite.
First of all, the jquantity package is complex because it involves so
many apparently unrelated classes and interfaces, which nevertheless are
directly comparable (for example, Manifest and WholeNumber).
Second, there is always the danger of coding infinite recursions in the
individual compareTo(Object) methods.
Thirdly, there is the fact that it is impossible in general to ensure
that the "that" object is in any sense more primitive than the "this" object.
Frequently, it will be the other way around, in which case the comparison
must be reversed.
There are four possibilities for the relationship between the classes of this and that:
For case 1, it is expected for any subclass (A) of BaseNumber that there
is defined a method int compareTo(A).
In case 2, it may be possible to widen that into this-class and
then perform the comparison.
In case 3, it may be possible to compare the objects in the opposite
ordering: i.e. to evaluate
- that.compareTo(this).
In case 4, there is nothing to be done - no comparison is valid,
unless explicitly provided for in this-class - or if that implements
an interface such that there is defined in this-class a method
int compareTo(interface).
Note also that extenders of this class should implement int compareTo(A) in such a way that if the objects to be compared are equal (in the sense of this.equals(that)) then 0 should be returned without further ado. Also note that since the methods isEqual(that) typically invoke compareTo, a compareTo method must not invoke isEqual.
The following is the standard javadoc for the compareTo(Object) method
as defined in the Comparable interface:
Compares this object with the specified object for order. Returns a
negative integer, zero, or a positive integer as this object is less
than, equal to, or greater than the specified object.
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
compareTo in interface java.lang.Comparablethat - the Object to be compared.
java.lang.RuntimeException - if the specified object's type prevents it
from being compared to this Object.
public Presentation present()
throws PresentationException
PresentationException - if this object cannot be presented with
given attributes.public double getBoundAbs()
public double getBound()
getBound in interface Fuzzypublic int getModel()
getModel in interface Fuzzypublic boolean isExact()
isExact in interface Fuzzypublic java.lang.String audit()
audit in interface Auditable
public void audit(java.io.PrintStream out,
java.lang.String label)
audit in interface Auditableout - the output stream.label - the label to attach to the output (may be null).public java.lang.String toString()
toString in class java.lang.Object
public Presentation impartFuzziness(NumberPresentation presentation)
throws PresentationException
presentation - the unfuzzy NumberPresentation.
PresentationExceptionpublic boolean isUncertain()
protected final BaseNumber abs()
public final boolean isZero()
public final boolean isEqual(BaseNumber other)
other - the number to compare.
public final int bestModel(Fuzzy that)
that - the other model source.
static int Characteristic(double x)
x - the value whose characteristic is required.
static double valueOfLog10(double x)
protected final void test(java.io.PrintStream out,
BaseNumber check,
java.lang.String label)
protected final void test(java.io.PrintStream out,
BaseNumber check)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||