Statechart functions

You can use the following functions to programmatically control statecharts and states.
Statechart functions

Function

Description

T getActiveSimpleState()

Returns the currently active simple state of the statechart.

T getState()

Returns the currently active simple state of the statechart. Note that this function does not return composite states.

Set<T> getFullState()

Returns the unordered set of the currently active composite states of the statechart, including the current simple state.

String getName()

Returns the name of the statechart.

String getFullName()

Returns the name of the statechart prefixed by the full name of its agent.

boolean isStateActive( T state )

Returns true if the statechart is at the specified state. For a specified simple state, it is the actual state. For a specified composite state, it is one of its inner states. Returns false if the statechart is not at the specified state.

Parameter: state - the state.

Agent getAgent()

Returns the agent that owns the statechart.

boolean receiveMessage( Object msg )

Posts a message to the statechart without queueing: the message is either immediately consumed (if there is a matching transition active) or is discarded. If a message matches two or more transitions, they will be able to execute independently (according to the statechart structure), thus consuming the same message. If two or more messages arrive simultaneously and both match the trigger of a transition, the second message will be ignored.

Returns true if the message matched at least one trigger; returns false otherwise.

Parameter: msg - the message posted to the statechart.

boolean receiveMessage( int msg )

Same as receiveMessage( Object ), but with an integer value as a message. Returns true if the message matched at least one trigger; returns false otherwise.

Parameter: msg - the integer posted to the statechart.

fireEvent( Object msg )

Adds a message to the statechart's queue. The message will be consumed either immediately or after a number of zero-time steps of the statechart, otherwise it will be discarded.

Parameter: msg - the message received by the statechart.

void onChange()

Should be called when something changes in the agent. If the statechart has at least one transition of the Condition or Rate type, this will allow to detect when the rate changes or a condition becomes true.

State functions

Function

Description

T getContainerState()

Returns the upper level state of the current state or null if this state is at the topmost level (has no container state).

Set<T> getFullState()

Returns the unordered set containing this state and all composite states (if any) containing the current state.

Collection<T> getSimpleStatesDeep()

Returns the collection of all simple states inside the current state.

Statechart<T> getStatechart( Agent agent )

Returns the statechart for the given agent that owns the current state. Returns null if the agent has no statechart with the current state.

Parameter: agent - the agent that owns the current state.

Set<T> getStatesInside()

Returns the unordered set of all states (both simple and composite) contained inside the current state.

boolean inState( Agent agent )

Returns true if the current state is active for the specified agent; returns false otherwise.

Parameter: agent - the agent that owns the current state.

boolean isSimpleState()

Returns true if the current state is a simple state; returns false if the current state is a composite state.

String name()

Returns the name of the current state.

int ordinal()

Returns the ordinal number of this state (states are numbered in a deterministic order).