org.eclipse.ohf.stem.core.common
Interface SanityChecker

All Known Subinterfaces:
AggregatingDiseaseModelState, AggregatingSEIRDiseaseModel, AggregatingSIDiseaseModel, AggregatingSIRDiseaseModel, AreaLabel, AreaLabelValue, CommonBorderRelationshipLabel, CommonBorderRelationshipLabelValue, Decorator, DeterministicSEIRDiseaseModel, DeterministicSIDiseaseModel, DeterministicSIRDiseaseModel, DiseaseModel, DiseaseModelLabel, DiseaseModelLabelValue, DiseaseModelState, DynamicEdgeLabel, DynamicLabel, DynamicNodeLabel, Edge, EdgeDecorator, EdgeLabel, GeographicFeature, Graph, GraphDecorator, Identifiable, Infector, Label, LabelValue, Model, Node, NodeDecorator, NodeLabel, PhysicalRelationshipLabel, PhysicalRelationshipLabelValue, PopulationLabel, PopulationLabelValue, RealTimeSequencer, Region, RelativePhysicalRelationshipLabel, RelativePhysicalRelationshipLabelValue, Scenario, SEIR, SEIRLabel, SEIRLabelValue, Sequencer, SequentialSequencer, SI, SIDiseaseModelState, SIInfector, SILabel, SILabelValue, SIR, SIRLabel, SIRLabelValue, StandardDiseaseModel, StandardDiseaseModelLabel, StandardDiseaseModelLabelValue, StandardDiseaseModelState, StandardInfector, StandardStochasticDiseaseModel, StaticEdgeLabel, StaticNodeLabel, StochasticDiseaseModel, StochasticSEIRDiseaseModel, StochasticSIDiseaseModel, StochasticSIRDiseaseModel, TestDynamicEdgeLabel, TestDynamicLabel1, TestDynamicNodeLabel, TestEdgeDecorator1, TestGraphDecorator1, TestIntegerLabelValue, TestLabel, TestNodeDecorator1, TestScenarioGraphDecorator1, TestStaticEdgeLabel, TestStaticNodeLabel, TransportRelationshipLabel, TransportRelationshipLabelValue
All Known Implementing Classes:
AggregatingDiseaseModelStateImpl, AggregatingSEIRDiseaseModelImpl, AggregatingSIDiseaseModelImpl, AggregatingSIRDiseaseModelImpl, AreaLabelImpl, AreaLabelValueImpl, CommonBorderRelationshipLabelImpl, CommonBorderRelationshipLabelValueImpl, DecoratorImpl, DeterministicSEIRDiseaseModelImpl, DeterministicSIDiseaseModelImpl, DeterministicSIRDiseaseModelImpl, DiseaseModelImpl, DiseaseModelLabelImpl, DiseaseModelLabelValueImpl, DiseaseModelStateImpl, DynamicEdgeLabelImpl, DynamicLabelImpl, DynamicNodeLabelImpl, EdgeDecoratorImpl, EdgeImpl, EdgeLabelImpl, GeographicFeatureImpl, GraphDecoratorImpl, GraphImpl, IdentifiableImpl, InfectorImpl, LabelImpl, LabelValueImpl, ModelImpl, NodeDecoratorImpl, NodeImpl, NodeLabelImpl, PhysicalRelationshipLabelImpl, PhysicalRelationshipLabelValueImpl, PopulationLabelImpl, PopulationLabelValueImpl, RealTimeSequencerImpl, RegionImpl, RelativePhysicalRelationshipLabelImpl, RelativePhysicalRelationshipLabelValueImpl, ScenarioImpl, SEIRImpl, SEIRLabelImpl, SEIRLabelValueImpl, SequencerImpl, SequentialSequencerImpl, SIDiseaseModelStateImpl, SIImpl, SIInfectorImpl, SILabelImpl, SILabelValueImpl, SIRImpl, SIRLabelImpl, SIRLabelValueImpl, StandardDiseaseModelImpl, StandardDiseaseModelLabelImpl, StandardDiseaseModelLabelValueImpl, StandardDiseaseModelStateImpl, StandardInfectorImpl, StandardStochasticDiseaseModelImpl, StaticEdgeLabelImpl, StaticNodeLabelImpl, StochasticDiseaseModelImpl, StochasticSEIRDiseaseModelImpl, StochasticSIDiseaseModelImpl, StochasticSIRDiseaseModelImpl, TestDynamicEdgeLabelImpl, TestDynamicLabel1Impl, TestDynamicNodeLabelImpl, TestEdgeDecorator1Impl, TestGraphDecorator1Impl, TestIntegerLabelValueImpl, TestLabelImpl, TestNodeDecorator1Impl, TestScenarioGraphDecorator1Impl, TestStaticEdgeLabelImpl, TestStaticNodeLabelImpl, TransportRelationshipLabelImpl, TransportRelationshipLabelValueImpl

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

sane

boolean sane()
This method is for ongoing development and testing purposes. It performs a "self-check" on the instance of the class. The checking consists of combination of boolean tests and assertions using the Java "assert" facillity. Assertions must be enabled using the "-ea" JVM flag for the assertions to be enabled.

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).

Returns:
true if the class passes its self-test, false otherwise
Throws:
java.lang.AssertionError - if assertions are enabled and false would be returned