jfsm
The jfsm
package provides implementations of finite state machines.
Features
- Mutable enum-based finite state machines.
- Written in pure Java 17.
- High coverage test suite.
- OSGi-ready.
- JPMS-ready.
- ISC license.
Usage
Declare a type that will be used to represent the states of the FSM.
An enum
type or a sealed
hierarchy is a good choice.
enum TrafficLight
{
RED,
YELLOW,
GREEN
}
Declare the allowed state transitions and build an FSM:
final FSMEnumMutableBuilderType<TrafficLight> b =
FSMEnumMutable.builder(TrafficLight.RED);
b.addTransition(TrafficLight.RED, TrafficLight.YELLOW);
b.addTransition(TrafficLight.YELLOW, TrafficLight.GREEN);
b.addTransition(TrafficLight.GREEN, TrafficLight.YELLOW);
b.addTransition(TrafficLight.YELLOW, TrafficLight.RED);
var fsm = b.build();
Execute transitions:
assert TrafficLight.RED == m.current();
m.transition(TrafficLight.YELLOW;
assert TrafficLight.YELLOW == m.current();
m.transition(TrafficLight.GREEN;
assert TrafficLight.GREEN == m.current();
m.transition(TrafficLight.YELLOW;
assert TrafficLight.YELLOW == m.current();
m.transition(TrafficLight.RED;
assert TrafficLight.RED == m.current();
m.transition(TrafficLight.YELLOW;
assert TrafficLight.YELLOW == m.current();
m.transition(TrafficLight.GREEN;
assert TrafficLight.GREEN == m.current();
m.transition(TrafficLight.YELLOW;
assert TrafficLight.YELLOW == m.current();
m.transition(TrafficLight.RED;
assert TrafficLight.RED == m.current();
m.transition(TrafficLight.YELLOW;
assert TrafficLight.YELLOW == m.current();
m.transition(TrafficLight.GREEN;
assert TrafficLight.GREEN == m.current();
The FSM will throw an FSMTransitionException
if an attempt is made to
perform a transition that is not permitted.
Releases & Development Snapshots
Releases
You can subscribe to the atom feed to be notified of project releases.
The most recently released version of the package is 2.0.1.
2.0.1 Release (2024-05-11Z)
- Move to new organization.
The compiled artifacts for the release (and all previous releases) are available on Maven Central.
Maven Modules
<dependency> <group>com.io7m.jfsm</group> <artifactId>com.io7m.jfsm.core</artifactId> <version>2.0.1</version> </dependency><dependency> <group>com.io7m.jfsm</group> <artifactId>com.io7m.jfsm.tests</artifactId> <version>2.0.1</version> </dependency>
Previous Releases
The changelogs for the most recent previous releases are as follows:
2.0.0 Release (2022-04-09Z)
- Require JDK 17 (Backwards incompatible)
1.0.0 Release (2017-11-15Z)
- All modules are now Java 9 modules. JDK 9 is now required. (Backwards incompatible)
0.1.1 Release (2017-04-09Z)
- Rename project. Use the new primogenitor POM and 2017 project conventions.
0.1.0 Release (2016-12-14Z)
- Initial release.
Development Snapshots
At the time of writing, the current unstable development version of the package is 2.0.2-SNAPSHOT.
Development snapshots may be available in the Central Portal Snapshots repository. Snapshots are published to this repository every time the project is built by the project's continuous integration system, but snapshots do expire after around ninety days and so may or may not be available depending on when a build of the package was last triggered.
Manual
This project does not have any user manuals or other documentation beyond what might be present on the page above.
Sources
This project uses Git to manage source code.
Repository: https://www.github.com/io7m-com/jfsm
$ git clone --recursive https://www.github.com/io7m-com/jfsm
Issues
This project uses GitHub Issues to track issues.
License
Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.