Skip to content

TUMFTM/conditionalstateful

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Conditionalstateful is a modification of the simple and lightweight event driven state machine library stateful. With Conditionalstateful you can implement complex state dependant logic with evaluation of matching conditions in a clean and simple design.

Installation

The project is built using Maven and the artifacts will be available at maven central in the future

Usage

Simple Transitions

enum State {
  INIT, RUNNING, COMPLETED
}

...

StateVariable<Integer> a = new StateVariable<>(5);
StateVariable<Boolean> b = new StateVariable<>(false);

StateMachine<State> stateMachine =
  new StateMachineBuilder<State>(State.INIT)
    .addTransition(State.INIT, () -> a.getValue() >=10 , State.RUNNING)
    .addTransition(State.RUNNING,() -> b, State.COMPLETED)
    .build();

stateMachine.getState(); // State.INIT
a.setValue(10);
stateMachine.evaluate();
stateMachine.getState(); // State.RUNNING
b.setValue(true);
stateMachine.evaluate();
stateMachine.getState(); // State.COMPLETED

On State Enter/Exit Listeners

StateMachine<State> stateMachine =
  new StateMachineBuilder<State>(State.INIT)
    .addTransition(State.INIT, () -> a.getValue() >=10 , State.RUNNING)
    .onExit(State.INIT, () -> System.out.println("Exiting Init!"))
    .onEnter(State.RUNNING, () -> System.out.println("Entering Running!"))
    .build();
a.setValue(10);
stateMachine.evaluate();

About

A simple and lightweight event driven state machine library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%