SteamWar/SpigotCore
Archiviert
13
0

Simplify Argument for Numbers with static constructor

Dieser Commit ist enthalten in:
jojo 2020-12-27 23:08:03 +01:00
Ursprung 96eb3e52ae
Commit 96c15aba71

Datei anzeigen

@ -58,6 +58,54 @@ public class Argument<T> {
return new Argument<>(ArgumentType.STRING, string -> string.equalsIgnoreCase(argument));
}
public static Argument<Integer> above(int minValue) {
return between(minValue, Integer.MAX_VALUE);
}
public static Argument<Integer> below(int maxValue) {
return between(Integer.MIN_VALUE, maxValue);
}
public static Argument<Integer> between(int minValue, int maxValue) {
return new Argument<>(ArgumentType.INT, i -> i >= minValue && i <= maxValue);
}
public static Argument<Long> above(long minValue) {
return between(minValue, Long.MAX_VALUE);
}
public static Argument<Long> below(long maxValue) {
return between(Long.MIN_VALUE, maxValue);
}
public static Argument<Long> between(long minValue, long maxValue) {
return new Argument<>(ArgumentType.LONG, l -> l >= minValue && l <= maxValue);
}
public static Argument<Float> above(float minValue) {
return between(minValue, Float.MAX_VALUE);
}
public static Argument<Float> below(float maxValue) {
return between(Float.MIN_VALUE, maxValue);
}
public static Argument<Float> between(float minValue, float maxValue) {
return new Argument<>(ArgumentType.FLOAT, f -> f >= minValue && f <= maxValue);
}
public static Argument<Double> above(double minValue) {
return between(minValue, Double.MAX_VALUE);
}
public static Argument<Double> below(double maxValue) {
return between(Double.MIN_VALUE, maxValue);
}
public static Argument<Double> between(double minValue, double maxValue) {
return new Argument<>(ArgumentType.DOUBLE, d -> d >= minValue && d <= maxValue);
}
public Optional<?> valueSupplier(String s) {
try {
T argumentMapped = argumentType.mapper.apply(s);