Statechart functions

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

Function

Description

Statechart<T> getStatechart
(A agent)

Returns statechart from the given agent which owns this state.

IStatechartState getActiveSimpleState()

Returns the currently active simple state of the statechart.

IStatechartState 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(IStatechartState state)

Returns true if a given state (simple or composite) is active, otherwise returns false.

Parameter: state - the state.

Agent getAgent()

Returns the agent that owns the statechart.

boolean inState(IStatechartState state)

Returns true if the agent is in the specified state, i.e. exactly in the state for a simple state and in one of its inner states for a composite state.

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

IStatechartState getContainerState()

Returns the immediate container state of this 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 containsState(IStatechartState simpleState)

Сhecks if this state of a statechart is composite and сontains the simpleState state (deep contents - inside contained composite states - are also checked).

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


Transition functions

Function

Description

boolean isActive()

Returns true if the transition firing is scheduled, and false otherwise.

double getRest()

Returns the time in the model time units remaining to the scheduled transition firing, or infinity if the firing is not scheduled.

double getRest(TimeUnits units)

Returns the time in given time units remaining to the scheduled transition firing. For example, getRest(MINUTE) returns the remaining time in minutes.