|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SanityChecker
The SanityChecker
interface is implemented by classes that can
perform a self-check to determine their "sanity" at run-time. If assertions
are enabled ("-ea" JVM flag) and an instance finds a problem an assertion
will typically fail and the execution will halt. If assertions are not
enabled then false
will be returned by the sane()
method and execution will continue.
This interface enables the ability to check the consistency of the entire system at run-time. Typically, that is done at strategic points in the exeuction, for instance, at the start of the main simulation cycle.
Method Summary | |
---|---|
boolean |
sane()
This method is for ongoing development and testing purposes. |
Method Detail |
---|
boolean sane()
This method is intended to be overridden by extending sub-classes. These
classes should first call the method in the super class (i.e.,
super.sane()
) to ensure that the super class is "ok" and
then it can issue its own assertions.
void sane() {
boolean retValue = super.sane();
// If foo references bar, then bar should reference foo!
retValue = retValue && (foo.a == bar && bar.a == foo);
assert(retValue);
return retValue;
} // sane
The idiom retValue = retValue && <boolean test>
followed by an assertion of the value of retValue
is a
typical pattern. If followed, then once a problem is detected, an
assertion will be thrown, or the rest of the tests will be skipped and
the value of false
returned. By having sane
return a value rather than simply relying upon the assert
keyword sanity testing can occur even if assertions are not enabled.
The sane
method should be called when the instance is
known to be "stable" so the consistency checks should complete with no
problems (if all is well).
true
if the class passes its self-test,
false
otherwise
java.lang.AssertionError
- if assertions are enabled and false
would be
returned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |