Fix SWCommandUtils

Dieser Commit ist enthalten in:
yoyosource 2022-05-30 14:59:00 +02:00 committet von Lixfel
Ursprung 800e507330
Commit 57ab89e058

Datei anzeigen

@ -38,11 +38,19 @@ public class SWCommandUtils {
@Getter @Getter
private final Map<String, AbstractGuardChecker<?>> GUARD_FUNCTIONS = new HashMap<>(); private final Map<String, AbstractGuardChecker<?>> GUARD_FUNCTIONS = new HashMap<>();
private SWTypeMapperCreator swTypeMapperCreator; private SWTypeMapperCreator swTypeMapperCreator = (mapper, tabCompleter) -> new AbstractTypeMapper<Object, Object>() {
@Override
public Object map(Object sender, String[] previousArguments, String s) {
return mapper.apply(s);
}
public static <T extends AbstractTypeMapper<K, V>, K, V> void init(SWTypeMapperCreator<T, K, V> swTypeMapperCreator) { @Override
SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator; public Collection<String> tabCompletes(Object sender, String[] previousArguments, String s) {
return tabCompleter.apply(sender, s);
}
};
static {
addMapper(boolean.class, Boolean.class, createMapper(s -> { addMapper(boolean.class, Boolean.class, createMapper(s -> {
if (s.equalsIgnoreCase("true")) return true; if (s.equalsIgnoreCase("true")) return true;
if (s.equalsIgnoreCase("false")) return false; if (s.equalsIgnoreCase("false")) return false;
@ -55,6 +63,10 @@ public class SWCommandUtils {
MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList)); MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList));
} }
public static <T extends AbstractTypeMapper<K, V>, K, V> void init(SWTypeMapperCreator<T, K, V> swTypeMapperCreator) {
SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator;
}
private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, AbstractTypeMapper<?, ?> mapper) { private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, AbstractTypeMapper<?, ?> mapper) {
MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper); MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper);
MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper); MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper);