|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.rubecula.util.Item
Abstract base class from which to derive other more concrete classes.
This class provides support for the Presentable
,
Auditable
, Comparable and Serializable interfaces.
Instances of sub-classes can be "presented", resulting in an instance
of Presentation
(which in turn can be rendered as a string).
This class provides no numerical logic - it is simply a slightly more
intelligent and potentially persistent extension of Object.
Field Summary | |
private static java.lang.String |
$LEFT_ARROW
Constant String representing left arrow. |
private static java.lang.String |
$RIGHT_ARROW
Constant String representing right arrow. |
private static boolean |
DEBUG
Private Class Field which records whether the DEBUG flag is set. |
static java.lang.String |
JQUANTITY_TEST
Constant String for the relative path of the test directory. |
Constructor Summary | |
Item()
|
Method Summary | |
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 |
compareTo(java.lang.Object that)
This method is the default compareTo method for Items (most of the classes in the JQuantity package extend Item). |
static void |
Debug(java.lang.String string)
protected class method to print string to System.out if debug mode is set. // TODO Start to use j4log instead. |
protected java.lang.String |
getClassNameShort()
Method to yield the shortened name of this Class. |
java.lang.String |
getType()
This method is primarily for development purposes: it yields the name of the class of the presentable object or, in some cases, the class of the presentable object indirectly referenced. |
static boolean |
IsDebug()
Method to get the debug status. |
Presentation |
present()
Convert this Presentable object into a Presentation with default attributes. |
static void |
SetDebug(boolean debug)
Method to set the debug status. |
protected void |
test(java.io.PrintStream out,
Item check)
Protected method to test an Item by passing it to audit(java.io.PrintStream,String) ,
comparing it to another item,
reporting the result.
|
protected void |
test(java.io.PrintStream out,
Item check,
java.lang.String label)
Protected method to test an Item by passing it to audit(java.io.PrintStream,String) ,
comparing it to another item,
reporting the result.
|
java.lang.String |
toString()
This is the default toString method for all Items. |
static java.lang.String |
Wrap(java.lang.String string)
Class method to wrap a string in $LEFT_ARROW and
$RIGHT_ARROW .
|
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.util.Auditable |
audit |
Methods inherited from interface com.rubecula.util.Identifiable |
getIdentifier |
Field Detail |
private static boolean DEBUG
public static final java.lang.String JQUANTITY_TEST
private static final java.lang.String $RIGHT_ARROW
private static final java.lang.String $LEFT_ARROW
Constructor Detail |
public Item()
Method Detail |
public static java.lang.String Wrap(java.lang.String string)
$LEFT_ARROW
and
$RIGHT_ARROW
.
Note: this method relates to the Auditable class and would be defined there
if that was legal.
string
- the string to be wrapped.
public int compareTo(java.lang.Object that)
This method is the default compareTo method for Items (most of the classes in the JQuantity package extend Item). If it is invoked, then there was no method declared which matched the objects more precisely. Each subclass (A) of Item 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 Item 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 Item 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.Comparable
that
- the Object to be compared.
java.lang.RuntimeException
- if the specified object's type prevents it
from being compared to this Object.Object.getClass()
,
Class.isInstance(java.lang.Object)
,
Class.getName()
,
Class.getSuperclass()
,
Method.invoke(java.lang.Object, java.lang.Object[])
,
Integer.intValue()
,
IllegalAccessException
,
InvocationTargetException
,
InvocationTargetException.getTargetException()
,
NoSuchMethodException
,
Class.getConstructor(java.lang.Class[])
,
Constructor.newInstance(java.lang.Object[])
public Presentation present() throws PresentationException
PresentationException
- if this object cannot be presented with
given attributes.Presentable.present(AttrMap)
,
AttrMap.AttrMap()
public java.lang.String getType()
getType
in interface Presentable
getClassNameShort()
public java.lang.String audit()
audit
in interface Auditable
Auditable.audit(String)
public void audit(java.io.PrintStream out, java.lang.String label)
audit
in interface Auditable
out
- the output stream.label
- the label to attach to the output (may be null).Auditable.audit(String)
,
getClassNameShort()
,
PrintStream.println(String)
public java.lang.String toString()
present()
,
Presentation.toString()
protected final void test(java.io.PrintStream out, Item check, java.lang.String label)
audit(java.io.PrintStream,String)
,
out
- whither the outputcheck
- Item to compare againstlabel
- label to use for the auditaudit(PrintStream, String)
,
compareTo(Object)
,
PrintStream.println(java.lang.String)
protected final void test(java.io.PrintStream out, Item check)
audit(java.io.PrintStream,String)
,
out
- whither the outputcheck
- Item to compare againsttest(PrintStream, Item, String)
,
Identifiable.getIdentifier()
protected java.lang.String getClassNameShort()
Object.getClass()
,
Class.toString()
,
String.lastIndexOf(int)
,
String.substring(int)
public static void SetDebug(boolean debug)
debug
- true or false.DEBUG
public static boolean IsDebug()
DEBUG
public static void Debug(java.lang.String string)
string
- the string to be output for logging/debuggingDEBUG
,
System.out
,
PrintStream.println(java.lang.String)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |