Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

desmoj
Class Condition  view Condition download Condition.java

java.lang.Object
  extended bydesmoj.NamedObject
      extended bydesmoj.ModelComponent
          extended bydesmoj.Condition

public abstract class Condition
extends ModelComponent

Derive from this class to create your own special objects to test for certain conditions in your Model or Experiment. Two methods for testing on conditions are provided:

Override these methods to return true whenever the model or entity comply to the condition to be checked.

Version:
DESMO-J, Ver. 1.5 copyright (c) 2001 licensed under GNU GPL

Field Summary
 
Fields inherited from class desmoj.ModelComponent
 
Fields inherited from class desmoj.NamedObject
 
Constructor Summary
Condition(Model owner, java.lang.String name, boolean showInTrace)
          Constructs a condition with the given name and parameters for trace files.
 
Method Summary
abstract  boolean check()
          Returns a boolean value indicating whether the condition is met or not.
abstract  boolean check(Entity e)
          Returns a boolean showing whether the given entity complies to the condition tested by this method or not.
 
Methods inherited from class desmoj.ModelComponent
current, currentEntity, currentEvent, currentModel, currentSimProcess, currentTime, debugIsOn, debugOff, debugOn, epsilon, getModel, isExperimentCompatible, isModelCompatible, sendDebugNote, sendMessage, sendTraceNote, sendWarning, setOwner, skipTraceNote, skipTraceNote, traceIsOn, traceOff, traceOn
 
Methods inherited from class desmoj.NamedObject
getName, getQuotedName, rename, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Condition

public Condition(Model owner,
                 java.lang.String name,
                 boolean showInTrace)
Constructs a condition with the given name and parameters for trace files.

Method Detail

check

public abstract boolean check()
Returns a boolean value indicating whether the condition is met or not. Override this abstract method and implement the specific check to return true if the tested condition conforms to your specified needs. If a condition is used as a stop-condition for an experiment beware that the simulation will run endless if your condition can't be met. It is advisable to always use a time limit if you are not sure about the condition in question. This abstract method must be implemented to make sure the appropriate result is returned.


check

public abstract boolean check(Entity e)
Returns a boolean showing whether the given entity complies to the condition tested by this method or not. Inherit from this class and implement this abstract method to return true if the passed entity conforms to your special condition. Note that any type of entity can be contained in a queue, so it is absolutely necessary to verify that the entity given as a parameter is actually an object of the type of entity you want to check. This can easily be done using the Java instanceof operator. To avoid runtime type mismatches always check for the appropriate type of object before accessing the desired object's attributes or methods like shown below:

// not sure about the special type of entity e if ( ! e instanceof mySpecialEntity ) return false;
// now we can be sure to have the special type of entity to check return ((mySpecialEntity)e).getSpecialEntityValue == neededValue;

The line above aborts all further tests when the passed entity is not of the desired type. If we do have an entity of the right type, we can check it and even use its specific methods. Note also, that using these specific methods still requires a typecast. But since we have tested for the right type of entity before, this runtime typecast should never get into a situation to throw an exception. This abstract method must be implemented to return the desired value.