Update number type mapper
Dieser Commit ist enthalten in:
Ursprung
441661a8f5
Commit
8d1b5c5f66
@ -58,10 +58,10 @@ public class SWCommandUtils {
|
||||
if (s.equalsIgnoreCase("false")) return false;
|
||||
return null;
|
||||
}, s -> Arrays.asList("true", "false")));
|
||||
addMapper(float.class, Float.class, createMapper(numberMapper(Float::parseFloat), numberCompleter(Float::parseFloat)));
|
||||
addMapper(double.class, Double.class, createMapper(numberMapper(Double::parseDouble), numberCompleter(Double::parseDouble)));
|
||||
addMapper(int.class, Integer.class, createMapper(numberMapper(Integer::parseInt), numberCompleter(Integer::parseInt)));
|
||||
addMapper(long.class, Long.class, createMapper(numberMapper(Long::parseLong), numberCompleter(Long::parseLong)));
|
||||
addMapper(float.class, Float.class, createMapper(numberMapper(Float::parseFloat), numberCompleter(Float::parseFloat, true)));
|
||||
addMapper(double.class, Double.class, createMapper(numberMapper(Double::parseDouble), numberCompleter(Double::parseDouble, true)));
|
||||
addMapper(int.class, Integer.class, createMapper(numberMapper(Integer::parseInt), numberCompleter(Integer::parseInt, false)));
|
||||
addMapper(long.class, Long.class, createMapper(numberMapper(Long::parseLong), numberCompleter(Long::parseLong, false)));
|
||||
MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList));
|
||||
}
|
||||
|
||||
@ -255,10 +255,25 @@ public class SWCommandUtils {
|
||||
};
|
||||
}
|
||||
|
||||
private static Function<String, Collection<String>> numberCompleter(Function<String, ?> mapper) {
|
||||
return s -> numberMapper(mapper).apply(s) != null
|
||||
? Collections.singletonList(s)
|
||||
: Collections.emptyList();
|
||||
private static Function<String, Collection<String>> numberCompleter(Function<String, ?> mapper, boolean comma) {
|
||||
return s -> {
|
||||
if (numberMapper(mapper).apply(s) == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> strings = new ArrayList<>();
|
||||
if (s.length() == 0) {
|
||||
strings.add("-");
|
||||
} else {
|
||||
strings.add(s);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
strings.add(s + i);
|
||||
}
|
||||
if (comma && (!s.contains(".") || !s.contains(","))) {
|
||||
strings.add(s + ".");
|
||||
}
|
||||
return strings;
|
||||
};
|
||||
}
|
||||
|
||||
static <T extends Annotation> T[] getAnnotation(Method method, Class<T> annotation) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren