xyz.luan.console.parser.call.Caller Maven / Gradle / Ivy
package xyz.luan.console.parser.call;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import xyz.luan.console.parser.Controller;
import xyz.luan.console.parser.ControllerRef;
import xyz.luan.console.parser.actions.InvalidAction;
import xyz.luan.console.parser.actions.InvalidHandler;
public class Caller {
private Map> controllers;
public Caller() {
this.controllers = new HashMap<>();
}
public > void registerClass(String name, T controller) throws InvalidAction, InvalidHandler {
controllers.put(name, new ControllerRef(name, controller));
}
public void forEachController(Consumer> consumer) {
for (Map.Entry> entry : controllers.entrySet()) {
consumer.accept(entry.getValue());
}
}
public CallResult call(Call call) {
if (call == null) {
return CallResult.INVALID_COMMAND;
}
return call.invoke(controllers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy