io.github.amayaframework.router.MachineRouter Maven / Gradle / Ivy
package io.github.amayaframework.router;
import com.github.romanqed.jsm.StateMachine;
import io.github.amayaframework.tokenize.Tokenizer;
import java.util.Map;
import java.util.function.Supplier;
final class MachineRouter extends AbstractRouter {
private final Map> statics;
private final StateMachine, String> machine;
private final Map> dynamics;
MachineRouter(Tokenizer tokenizer,
Map> statics,
StateMachine, String> machine,
Map> dynamics) {
super(tokenizer);
this.statics = statics;
this.machine = machine;
this.dynamics = dynamics;
}
@Override
public PathContext process(String path, Supplier> supplier) {
var found = statics.get(PathUtil.normalize(path));
if (found != null) {
return found;
}
if (machine == null) {
return null;
}
var hash = machine.stamp(supplier.get());
if (hash < 0) {
return null;
}
return dynamics.get(hash);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy