moar
This commit is contained in:
@@ -14,6 +14,10 @@ public interface StateMachineService {
|
|||||||
// Quirky pattern 2: Generic Varargs
|
// Quirky pattern 2: Generic Varargs
|
||||||
<T extends IEvent> void sendEventsVarargs(T... events);
|
<T extends IEvent> void sendEventsVarargs(T... events);
|
||||||
|
|
||||||
|
// Functional quirks: passing functions and method references
|
||||||
|
<T extends IEvent> void executeFunctionalTransition(java.util.function.Supplier<T> eventSupplier,
|
||||||
|
java.util.function.Function<T, Void> transitionAction);
|
||||||
|
|
||||||
// Child class of Spring's GenericMessage with a generic payload
|
// Child class of Spring's GenericMessage with a generic payload
|
||||||
<T extends click.kamil.domain.OrderEvent, P> void sendCustomMessage(click.kamil.domain.CustomStateMachineMessage<T, P> customMessage);
|
<T extends click.kamil.domain.OrderEvent, P> void sendCustomMessage(click.kamil.domain.CustomStateMachineMessage<T, P> customMessage);
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,15 @@ public class StateMachineServiceImpl implements StateMachineService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends IEvent> void executeFunctionalTransition(java.util.function.Supplier<T> eventSupplier,
|
||||||
|
java.util.function.Function<T, Void> transitionAction) {
|
||||||
|
// Resolve the event from the getter / supplier function
|
||||||
|
T event = eventSupplier.get();
|
||||||
|
// Apply the transition via the provided function / method reference
|
||||||
|
transitionAction.apply(event);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends OrderEvent, P> void sendCustomMessage(click.kamil.domain.CustomStateMachineMessage<T, P> customMessage) {
|
public <T extends OrderEvent, P> void sendCustomMessage(click.kamil.domain.CustomStateMachineMessage<T, P> customMessage) {
|
||||||
// Because CustomStateMachineMessage extends GenericMessage<T> and implements Message<T>,
|
// Because CustomStateMachineMessage extends GenericMessage<T> and implements Message<T>,
|
||||||
|
|||||||
@@ -34,4 +34,27 @@ public class OrderController {
|
|||||||
stateMachineService.sendMessage(OrderEvent.CANCEL);
|
stateMachineService.sendMessage(OrderEvent.CANCEL);
|
||||||
return "Order cancel event sent";
|
return "Order cancel event sent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Functional Quirks for Static Analysis ---
|
||||||
|
|
||||||
|
// A getter returning a specific ENUM constant
|
||||||
|
public OrderEvent getCompleteEvent() {
|
||||||
|
return OrderEvent.COMPLETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A specific function that performs the transition
|
||||||
|
public Void triggerTransitionFunction(click.kamil.domain.IEvent event) {
|
||||||
|
stateMachineService.sendMessage(event);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/functional-complete")
|
||||||
|
public String functionalCompleteOrder() {
|
||||||
|
// Pass the getter and the transition applier as method references
|
||||||
|
stateMachineService.executeFunctionalTransition(
|
||||||
|
this::getCompleteEvent,
|
||||||
|
this::triggerTransitionFunction
|
||||||
|
);
|
||||||
|
return "Functional complete event triggered via method references";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user