22

Enums, functional interfaces, streams, and Optional as patterns

Everyday functional Java 25 constructs standing in for classic patterns, in a nightly fulfillment batch.

Demo 22Source on GitHub ↗

Everyday Java 25 constructs are pattern implementations in disguise. This module runs a nightly fulfillment batch that uses an enum carrying behavior (Strategy and a Singleton sequence), lambdas and method references as Strategy and Command, a Template Method expressed as a function taking steps, composed UnaryOperator pricing adjustments (andThen and compose do not commute), stream pipelines with EnumMap-backed grouping, and Optional as an explicit return type (never a field).

The JUnit 5 tests assert behavior across each construct, including composition order and present/absent Optional cases.

Build, run, observe

cd examples/22-functional-java
mvn -q test
./demo.sh

The module also runs from the aggregator root with mvn -q -f examples/pom.xml test.