All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.amayaframework.router.MachineRouter Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
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 machine;
    private final Map> dynamics;

    MachineRouter(Tokenizer tokenizer,
                  Map> statics,
                  StateMachine 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