2019-06-02 05:03:08 +03:00
|
|
|
package pro.gravit.launchserver.manangers;
|
2018-12-26 15:40:53 +03:00
|
|
|
|
2019-06-02 05:03:08 +03:00
|
|
|
import pro.gravit.launchserver.Reconfigurable;
|
|
|
|
import pro.gravit.utils.helper.LogHelper;
|
|
|
|
import pro.gravit.utils.helper.VerifyHelper;
|
2018-12-26 15:40:53 +03:00
|
|
|
|
2019-01-15 06:35:39 +03:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2018-12-26 15:40:53 +03:00
|
|
|
public class ReconfigurableManager {
|
|
|
|
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
|
2019-01-15 06:35:39 +03:00
|
|
|
|
|
|
|
public void registerReconfigurable(String name, Reconfigurable reconfigurable) {
|
2019-03-28 08:07:54 +03:00
|
|
|
VerifyHelper.putIfAbsent(RECONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"),
|
2018-12-26 15:40:53 +03:00
|
|
|
String.format("Reloadable has been already registered: '%s'", name));
|
|
|
|
}
|
2019-05-15 14:11:22 +03:00
|
|
|
|
|
|
|
public Reconfigurable unregisterReconfigurable(String name) {
|
2019-04-27 13:17:10 +03:00
|
|
|
return RECONFIGURABLE.remove(name);
|
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
|
|
|
public void printHelp(String name) {
|
2019-03-28 08:07:54 +03:00
|
|
|
RECONFIGURABLE.get(name.toLowerCase()).printConfigHelp();
|
2018-12-26 15:40:53 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-15 06:32:46 +03:00
|
|
|
public void call(String name, String action, String[] args) {
|
2019-03-28 08:07:54 +03:00
|
|
|
RECONFIGURABLE.get(name.toLowerCase()).reconfig(action.toLowerCase(), args);
|
2018-12-26 15:40:53 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
|
|
|
public void printReconfigurables() {
|
2018-12-26 15:40:53 +03:00
|
|
|
LogHelper.info("Print reconfigurables");
|
|
|
|
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
|
|
|
|
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());
|
|
|
|
}
|
|
|
|
}
|