Code Examples
A repository of 155 code examples for BeepBeep
finitestatemachines.SimpleMooreMachine Class Reference

Check the proper ordering of next/hasNext strings. More...

Static Public Member Functions

static void main (String[] args)
 

Detailed Description

Check the proper ordering of next/hasNext strings.

In this example, we suppose we get a stream of method calls on an Iterator object. The proper use of an iterator stipulates that one should never call method next() before first calling method hasNext(). The correct ordering of these calls can be expressed by a finite-state machine with three states.

On the input stream "hasNext", "next", "hasNext", "hasNext", "next", "next", the expected output of this program is:

unsafe
safe
unsafe
unsafe
safe
error
error

The basic Moore machine is very generic. The conditions on its transitions can be arbitrary functions on incoming events; as a result, defining a simple state machine can be a little verbose. For a more "compact" way of defining the state machine in this example, see SimpleMooreMachineCompact.

See also
SimpleMooreMachineCompact::main(String[])
Author
Sylvain Hallé

Definition at line 59 of file SimpleMooreMachine.java.


The documentation for this class was generated from the following file: