Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache several common argument types #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import java.util.concurrent.CompletableFuture;

public class BoolArgumentType implements ArgumentType<Boolean> {
private static final BoolArgumentType INSTANCE = new BoolArgumentType();
private static final Collection<String> EXAMPLES = Arrays.asList("true", "false");

private BoolArgumentType() {
}

public static BoolArgumentType bool() {
return new BoolArgumentType();
return INSTANCE;
}

public static boolean getBool(final CommandContext<?> context, final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collection;

public class DoubleArgumentType implements ArgumentType<Double> {
private static final DoubleArgumentType ALL = new DoubleArgumentType(-Double.MAX_VALUE, Double.MAX_VALUE);
private static final Collection<String> EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "-.5", "-1234.56");

private final double minimum;
Expand All @@ -22,7 +23,7 @@ private DoubleArgumentType(final double minimum, final double maximum) {
}

public static DoubleArgumentType doubleArg() {
return doubleArg(-Double.MAX_VALUE);
return ALL;
}

public static DoubleArgumentType doubleArg(final double min) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collection;

public class FloatArgumentType implements ArgumentType<Float> {
private static final FloatArgumentType ALL = new FloatArgumentType(-Float.MAX_VALUE, Float.MAX_VALUE);
private static final Collection<String> EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "-.5", "-1234.56");

private final float minimum;
Expand All @@ -22,7 +23,7 @@ private FloatArgumentType(final float minimum, final float maximum) {
}

public static FloatArgumentType floatArg() {
return floatArg(-Float.MAX_VALUE);
return ALL;
}

public static FloatArgumentType floatArg(final float min) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collection;

public class IntegerArgumentType implements ArgumentType<Integer> {
private static final IntegerArgumentType ALL = new IntegerArgumentType(Integer.MIN_VALUE, Integer.MAX_VALUE);
private static final Collection<String> EXAMPLES = Arrays.asList("0", "123", "-123");

private final int minimum;
Expand All @@ -22,7 +23,7 @@ private IntegerArgumentType(final int minimum, final int maximum) {
}

public static IntegerArgumentType integer() {
return integer(Integer.MIN_VALUE);
return ALL;
}

public static IntegerArgumentType integer(final int min) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collection;

public class LongArgumentType implements ArgumentType<Long> {
private static final LongArgumentType ALL = new LongArgumentType(Long.MIN_VALUE, Long.MAX_VALUE);
private static final Collection<String> EXAMPLES = Arrays.asList("0", "123", "-123");

private final long minimum;
Expand All @@ -22,7 +23,7 @@ private LongArgumentType(final long minimum, final long maximum) {
}

public static LongArgumentType longArg() {
return longArg(Long.MIN_VALUE);
return ALL;
}

public static LongArgumentType longArg(final long min) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
import java.util.Collection;

public class StringArgumentType implements ArgumentType<String> {
private static final StringArgumentType WORD_ARGUMENT = new StringArgumentType(StringType.SINGLE_WORD);
private static final StringArgumentType QUOTED_ARGUMENT = new StringArgumentType(StringType.QUOTABLE_PHRASE);
private static final StringArgumentType GREEDY_ARGUMENT = new StringArgumentType(StringType.GREEDY_PHRASE);

private final StringType type;

private StringArgumentType(final StringType type) {
this.type = type;
}

public static StringArgumentType word() {
return new StringArgumentType(StringType.SINGLE_WORD);
return WORD_ARGUMENT;
}

public static StringArgumentType string() {
return new StringArgumentType(StringType.QUOTABLE_PHRASE);
return QUOTED_ARGUMENT;
}

public static StringArgumentType greedyString() {
return new StringArgumentType(StringType.GREEDY_PHRASE);
return GREEDY_ARGUMENT;
}

public static String getString(final CommandContext<?> context, final String name) {
Expand Down