EasyFlow
EasyFlow - Simple and lightweight Finite State Machine for Java
Install / Use
/learn @Beh01der/EasyFlowREADME
EasyFlow
EasyFlow 1.3 is out (12 Dec 2013)
- refactored to use Java enums for states and events
- added new example
EasyFlow is a simple and lightweight Finite State Machine for Java
With EasyFlow you can:
- implement complex logic but keep your code simple and clean
- handle asynchronous calls with ease and elegance
- avoid concurrency by using event-driven programming approach
- avoid StackOverflow error by avoiding recursion
- simplify design, programming and testing of complex java applications
All this in less then 30kB and no run-time overhead!
Here is a simple example illustrating how a state machine can be definded and implemented with EasyFlow
This is a State diargam fragment describing a simple ATM workflow
With EasyFlow we can define the above state machine like this
enum States implements StateEnum {
SHOWING_WELCOME, WAITING_FOR_PIN, RETURNING_CARD, SHOWING_WELCOME, ...
}
enum Events implements EventEnum {
cardPresent, pinProvided, cardExtracted, cancel, ...
}
...
EasyFlow<FlowContext> flow =
from(SHOWING_WELCOME).transit(
on(cardPresent).to(WAITING_FOR_PIN).transit(
on(pinProvided).to(...).transit(
...
),
on(cancel).to(RETURNING_CARD).transit(
on(cardExtracted).to(SHOWING_WELCOME)
)
)
);
then all what's left to do is to implement our state handlers like so
whenEnter(SHOWING_WELCOME, new ContextHandler<FlowContext>() {
@Override
public void call(final FlowContext context) throws Exception {
...
btnOption1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.trigger(cardPresent);
}
});
...
}
});
...
and start the flow
flow.start(new FlowContext());
See complete example ATM emulator - Android application
To start using EasyFlow on your project, define Maven dependency like so
<dependency>
<groupId>au.com.datasymphony</groupId>
<artifactId>EasyFlow</artifactId>
<version>1.3.1</version>
</dependency>
See also
License Apache 2.0
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
