Static helper methods for StringRange to make them more readable
This commit is contained in:
@@ -183,7 +183,7 @@ public class CommandDispatcher<S> {
|
||||
reader.skip();
|
||||
if (child.getRedirect() != null) {
|
||||
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor());
|
||||
childContext.withNode(child.getRedirect(), new StringRange(cursor, reader.getCursor() - 1));
|
||||
childContext.withNode(child.getRedirect(), StringRange.between(cursor, reader.getCursor() - 1));
|
||||
final ParseResults<S> parse = parseNodes(child.getRedirect(), reader, childContext);
|
||||
context.withChild(parse.getContext());
|
||||
return new ParseResults<>(context, parse.getReader(), parse.getExceptions());
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CommandContextBuilder<S> {
|
||||
public CommandContextBuilder(final CommandDispatcher<S> dispatcher, final S source, final int start) {
|
||||
this.dispatcher = dispatcher;
|
||||
this.source = source;
|
||||
this.range = new StringRange(start, start);
|
||||
this.range = StringRange.at(start);
|
||||
}
|
||||
|
||||
public CommandContextBuilder<S> withSource(final S source) {
|
||||
@@ -47,7 +47,7 @@ public class CommandContextBuilder<S> {
|
||||
|
||||
public CommandContextBuilder<S> withNode(final CommandNode<S> node, final StringRange range) {
|
||||
nodes.put(node, range);
|
||||
this.range = new StringRange(Math.min(this.range.getStart(), range.getStart()), Math.max(this.range.getEnd(), range.getEnd()));
|
||||
this.range = StringRange.encompassing(this.range, range);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ public class ParsedArgument<S, T> {
|
||||
private final T result;
|
||||
|
||||
public ParsedArgument(final int start, final int end, final T result) {
|
||||
this.range = new StringRange(start, end);
|
||||
this.range = StringRange.between(start, end);
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,18 @@ public class StringRange {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public static StringRange at(final int pos) {
|
||||
return new StringRange(pos, pos);
|
||||
}
|
||||
|
||||
public static StringRange between(final int start, final int end) {
|
||||
return new StringRange(start, end);
|
||||
}
|
||||
|
||||
public static StringRange encompassing(final StringRange a, final StringRange b) {
|
||||
return new StringRange(Math.min(a.getStart(), b.getStart()), Math.max(a.getEnd(), b.getEnd()));
|
||||
}
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
@@ -61,5 +73,4 @@ public class StringRange {
|
||||
", end=" + end +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class Suggestions {
|
||||
private static final Suggestions EMPTY = new Suggestions(new StringRange(0, 0), Lists.newArrayList());
|
||||
private static final Suggestions EMPTY = new Suggestions(StringRange.at(0), Lists.newArrayList());
|
||||
|
||||
private final StringRange range;
|
||||
private final List<String> suggestions;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SuggestionsBuilder {
|
||||
return this;
|
||||
}
|
||||
final String prefix = Strings.commonPrefix(text, remaining);
|
||||
result.add(new Suggestion(new StringRange(start + prefix.length(), input.length()), text.substring(prefix.length())));
|
||||
result.add(new Suggestion(StringRange.between(start + prefix.length(), input.length()), text.substring(prefix.length())));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class LiteralCommandNode<S> extends CommandNode<S> {
|
||||
}
|
||||
}
|
||||
|
||||
contextBuilder.withNode(this, new StringRange(start, reader.getCursor()));
|
||||
contextBuilder.withNode(this, StringRange.between(start, reader.getCursor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user