On this page

Checking the State of an object

The following ALH API checks whether a particular object is in a specific state name.
 

boolean inState(Object_ object, String stateName)
boolean inState(String stateName)


Unless the object is specified, it will use the current active object, for example:

if (ALH.inState(ccobj, "Operating")) {
	force=ccForce
} else {
	force = acc*2
}

Information

Alternatively, you can use ALH API through the fUML object syntax, with object.in(stateName). For example:


Getting the current State of a runtime object

You can use the following API to retrieve a current State of a specified object. If the object has more than one active State, it recognizes which the runtime State is, and finds it.
 

State getState(Object_ object)


The following code fragment shows how to get the current state of a specified object using ALH API.

ALH.getState(o);


It returns the Instance of the following

com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State.


Checking a visited State

You can check whether a specified State was visited by calling the following command.

boolean wasInState(String stateName)


The following code fragment shows how to check whether a specified State of State Machine, e.g., State1, was visited through ALH API.

ALH.wasInState("State1");	// Returns true or false.

Checking if an Activity Diagram is being simulated