Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

id768506457

...

id768506479

...

id768506455

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

On this page

Table of Contents
maxLevel4

...

id768506468

Checking the State of an object

Getting the current State of a runtime object

You can use the following ALH API to get the current State of a specified object. If the object has more than one active State, it returns the first active state. The API returns the instance of the state.

Code Block
languagetext

...

boolean inState(Object_ object, String stateName)
boolean inState(String stateName)
ALH.getState(object)

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

...

:

Code Block
languagetext

...

ALH.getState(self);
ALH.

...

getState(self).getName()        //To get name of the state instance use .getName()

Checking the State of an object

You can use script to check state of an object. You can use

...

titleInformation

...

the fUML object syntax,

...

with object.in("stateName"). For example:

...

...

  • "Operating");

...

Alternatively, you can check the state of an object using ALH API. The API returns the Boolean value.

Code Block
languagetext

...

State getState(Object_ object)
ALH.inState(object, "stateName")
ALH.inState("stateName")                // Returns true or false.

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

...

Code Block
languagetext
if (ALH.

...

It returns the Instance of the following

Code Block
languagetext
com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State.
inState("Operating")) {
	force=ccForce
} else {
	force = acc*2
}

Checking a visited State

You can use following ALH API to check the visited state. You can check whether a specified State was visited by calling the following command.

Code Block
languagetext

...

ALH.wasInState(

...

"stateName")

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

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

Checking if an

...

activity is being simulated

You can use the script to check if an object performs a specific activity. You can use the fUML object syntax with object.performs("activityName"). For example:

  • self.performs("Driving");

Checking if an object is busy

You can use the script to check if an object performing any behavior. You can use the fUML object syntax with object.isBusy(). For example:

  • self.isBusy();