Dieser Commit ist enthalten in:
Ursprung
0674c951aa
Commit
b0d74ed5a3
@ -38,11 +38,19 @@ public class SWCommandUtils {
|
||||
@Getter
|
||||
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) {
|
||||
SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator;
|
||||
@Override
|
||||
public Collection<String> tabCompletes(Object sender, String[] previousArguments, String s) {
|
||||
return tabCompleter.apply(sender, s);
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
addMapper(boolean.class, Boolean.class, createMapper(s -> {
|
||||
if (s.equalsIgnoreCase("true")) return true;
|
||||
if (s.equalsIgnoreCase("false")) return false;
|
||||
@ -55,6 +63,10 @@ public class SWCommandUtils {
|
||||
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) {
|
||||
MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper);
|
||||
MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren