
de.scravy.machina.GuardedStateList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of machina Show documentation
Show all versions of machina Show documentation
A finite state machine library that features true stateless
state machines.
// Generated by delombok at Mon May 25 16:22:43 CEST 2015
package de.scravy.machina;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import de.scravy.pair.Pair;
/**
* INTERNAL
*/
final class GuardedStateList implements Iterable> {
private final List> list;
private final S defaultState;
public GuardedStateList(final List, S>> guardedStates, final S defaultState) {
final List> list = new ArrayList<>(guardedStates.size());
for (final Pair extends Guard, S> guardedState : guardedStates) {
list.add(new GuardedState(guardedState.getFirst(), guardedState.getSecond()));
}
this.list = Collections.unmodifiableList(list);
this.defaultState = defaultState;
}
public S getStateFor(final E event, final C context) {
if (context != null) {
for (final GuardedState guardedState : this.list) {
if (guardedState.getGuard().evaluate(event, context)) {
return guardedState.getState();
}
}
}
return this.defaultState;
}
@Override
public Iterator> iterator() {
return this.list.iterator();
}
@SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public S getDefaultState() {
return this.defaultState;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy