A lightweight Java decision DSL that replaces nested if-else with fluent rule composition, supporting AND/OR/NOT predicate logic and functional execution flows.
DSL = A specialized way of writing code that makes it feel like you are describing the problem, not programming it.
Instead of writing:
if (a) {
if (b) {
action1();
}
} else {
action2();
}We write:
Decisio.of(value)
.when(a).then(action1)
.otherwise(action2);Deeply nested if-else logic quickly becomes:
- hard to read
- difficult to maintain
- error-prone
- tightly coupled
Decisio simplifies this by providing a fluent, readable decision flow API using Java lambdas.
- Fluent decision API
- Replace nested if-else logic
- Predicate composition (AND / OR / NOT)
- Functional execution flow
- Lightweight (no external dependencies)
- Easy to embed in any Java project
<dependency>
<groupId>io.github.mashukbd</groupId>
<artifactId>decisio</artifactId>
<version>1.0.0</version>
</dependency>Decisio.of(user)
.when(Objects::isNull)
.then(u -> guest())
.when(User::isBlocked)
.then(u -> blocked())
.when(User::isAdmin)
.and(User::isActive)
.then(u -> admin())
.when(User::isPremium)
.or(User::isVip)
.then(u -> premium())
.otherwise(u -> normal());.when(User::isAdmin)
.and(User::isActive).when(User::isPremium)
.or(User::isVip).when(User::isAdmin)
.andNot(User::isBlocked)Decisio evaluates rules in order:
- Match condition
- Execute associated action
- Stop (default behavior: first match wins)
- Fallback to otherwise
- Business rule evaluation
- Validation flows
- Access control logic
- Decision trees
- Request routing logic
- Reducing nested conditional complexity
- Keep it simple
- Stay close to Java functional style
- Avoid enterprise complexity
- Focus on readability over abstraction
Decisio is not a full rule engine or BPM system.
It is a lightweight decision composition library for everyday Java development.
MIT License