https://github.com/electrostat-lab/automata4j
A classic finite state automaton framework for JVM Applications (Android and jMonkeyEngine Applications).
https://github.com/electrostat-lab/automata4j
android-apps design-patterns electrostat-lab finite-state-automata java jmonkeyengine object-oriented-programming state-machines
Last synced: about 2 months ago
JSON representation
A classic finite state automaton framework for JVM Applications (Android and jMonkeyEngine Applications).
- Host: GitHub
- URL: https://github.com/electrostat-lab/automata4j
- Owner: Electrostat-Lab
- License: bsd-3-clause
- Created: 2023-05-30T09:53:14.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-08-28T08:47:37.000Z (almost 2 years ago)
- Last Synced: 2025-05-07T11:13:42.453Z (about 2 months ago)
- Topics: android-apps, design-patterns, electrostat-lab, finite-state-automata, java, jmonkeyengine, object-oriented-programming, state-machines
- Language: Java
- Homepage:
- Size: 5.05 MB
- Stars: 5
- Watchers: 0
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#
Automata4j [](https://app.codacy.com/gh/Software-Hardware-Codesign/Automata4j/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [](https://github.com/Software-Hardware-Codesign/Automata4j/releases/)
[]() []()A finite state automaton framework for Java, Android, and jMonkeyEngine Applications.
## Building:
```bash
┌─[pavl-machine@pavl-machine]─[/home/pavl-machine/projects]
└──╼ $git clone https://github.com/Software-Hardware-Codesign/Automata4j.git && cd ./Automata4j┌─[pavl-machine@pavl-machine]─[/home/pavl-machine/projects/Automata4j]
└──╼ $./gradlew automata4j:build && \
./gradlew automata4j:generateJavadocJar && \
./gradlew automata4j:generateSourcesJar
```
## Implementation Example:
```java
final String version = "1.0.0-beta"repositories {
mavenCentral()
}
dependencies {
implementation "io.github.software-hardware-codesign:automata4j:${version}"
}
```
```java
public final class SpaceCraftEngine extends Thread implements TransitionalListener {
private final TransitionalManager transitionalManager = new TransitionalManager();
private final LatLng initialPosition = VehicleManager.getInstance().getSpaceCraft().getLocation();
private final SpaceCraftEngine.TravelDistance travelDistance = new SpaceCraftEngine.TravelDistance(10f);
private final SpaceCraftEngine.MoveCommand horizontalMoveState = new SpaceCraftEngine.MoveCommand();
public SpaceCraftEngine() {
super(SpaceCraftEngine.class.getName());
}
/** Run your example from here or a Game state or a Unit Test */
public static void main(String args[]) {
final SpaceCraftEngine engine = new SpaceCraftEngine();
engine.startTravelling();
}
public void startTravelling() {
/* Assigns the initial state and starts the transitional manager */
transitionalManager.assignNextState(horizontalMoveState);
this.start();
}
@Override
public void run() {
/* Starts the finite-state-system by transiting to the next travel state */
travel(travelDistance);
}
@Override
public void onTransition(AutoState presentState) {
final AutoState autoState = (AutoState) presentState;
if (presentState.getStateTracer().getX() > (initialPosition.getX() + 200f)) {
/* Exits the system once traveling has been completed and docks the spacecraft */
VehicleManager.getInstance().getSpaceCraft().dock(DockingSpeed.DEFAULT_SPEED);
Gui.getInstance().message(Message.Type.Alert,
"Completed Travelling 200+ Miles, Docking the SpaceCraft");
return;
}
/* Continues assigning new states as long as the destination has not been met */
transitionalManager.assignNextState(horizontalMoveState);
travel(travelDistance);
}
protected void travel(SpaceCraftEngine.TravelDistance travelDistance) {
transitionalManager.transit(travelDistance, this);
Gui.getInstance().message(Message.Type.Alert, "Travelling Now for "
+ travelDistance.getPulse() + " Miles");
}protected static class MoveCommand implements AutoState {
private PulseCommand command;@Override
public void setInput(PulseCommand command) {
this.command = command;
}@Override
public void invoke(PulseCommand command) {
this.command = command;
// Your system state goes here
VehicleManager.getInstance().getSpaceCraft().force(command.getPulse(), 0);
Gui.getInstance().message(Message.Type.Info, "Added additional "
+ command.getPulse() + " Miles");
}
@Override
public PulseCommand getInput() {
return command;
}
@Override
public LatLng getStateTracer() {
return VehicleManager.getInstance().getSpaceCraft().getLocation();
}
@Override
public void onFinish() {
// Your finish code goes here
VehicleManager.getInstance().getSpaceCraft().stopEngine();
Gui.getInstance().message(Message.Type.Warning, "Engine Stops");
}
@Override
public void onStart() {
// Your start code goes here
VehicleManager.getInstance().getSpaceCraft().startEngine();
Gui.getInstance().message(Message.Type.Info, "Engine Starts");
}
}protected static class TravelDistance implements PulseCommand {
private float pulse;
public TravelDistance(float pulse) {
this.pulse = pulse;
}
@Override
public float getPulse() {
return pulse;
}
}protected static class Location implements LatLng {
private float x;
private float y;
public Location(float x, float y) {
this.x = x;
this.y = y;
}
@Override
public void setLocation(float x, float y) {
this.x = x;
this.y = y;
}
@Override
public float getX() {
return x;
}
@Override
public float getY() {
return y;
}
}
}
```## Appendix
### Features:
- [x] Finite-State-Machine pattern.
- [x] SerialAdder Example.
- [x] API Documentation.
- [x] Document describing the finite-state theory.
- [x] Publishing to Maven for public use.
- [x] Deterministic Finite-State-Automata.
- [x] Wiki for general use.### Theory Archive:
- [Finite-State-Automaton Theory Archive, from Switching and Finite Automata Theory 3rd Edition](https://github.com/Software-Hardware-Codesign/Automata4j/blob/master/archives/Finite-State-Automata.pdf)
- [Finite-State-Recognizers for DFSA V.S. NDFSA](https://github.com/Software-Hardware-Codesign/Automata4j/blob/master/archives/Finite-State-Recognizers(DFSA-NDFSA).pdf)### For more about Finite-States, find the full TextBook:
[](https://www.amazon.com/Switching-Finite-Automata-Theory-Kohavi/dp/0521857481)