Suggestions:getList() now returns <Suggestion> not <String>
This commit is contained in:
@@ -66,9 +66,9 @@ public class Suggestion implements Comparable<Suggestion> {
|
||||
return text.compareTo(o.text);
|
||||
}
|
||||
|
||||
public String expand(final String command, final StringRange range) {
|
||||
public Suggestion expand(final String command, final StringRange range) {
|
||||
if (range.equals(this.range)) {
|
||||
return text;
|
||||
return this;
|
||||
}
|
||||
final StringBuilder result = new StringBuilder();
|
||||
if (range.getStart() < this.range.getStart()) {
|
||||
@@ -78,6 +78,6 @@ public class Suggestion implements Comparable<Suggestion> {
|
||||
if (range.getEnd() > this.range.getEnd()) {
|
||||
result.append(command.substring(this.range.getEnd(), range.getEnd()));
|
||||
}
|
||||
return result.toString();
|
||||
return new Suggestion(range, result.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -16,9 +15,9 @@ public class Suggestions {
|
||||
private static final Suggestions EMPTY = new Suggestions(StringRange.at(0), Lists.newArrayList());
|
||||
|
||||
private final StringRange range;
|
||||
private final List<String> suggestions;
|
||||
private final List<Suggestion> suggestions;
|
||||
|
||||
public Suggestions(final StringRange range, final List<String> suggestions) {
|
||||
public Suggestions(final StringRange range, final List<Suggestion> suggestions) {
|
||||
this.range = range;
|
||||
this.suggestions = suggestions;
|
||||
}
|
||||
@@ -27,7 +26,7 @@ public class Suggestions {
|
||||
return range;
|
||||
}
|
||||
|
||||
public List<String> getList() {
|
||||
public List<Suggestion> getList() {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
@@ -74,9 +73,7 @@ public class Suggestions {
|
||||
|
||||
final Set<Suggestion> texts = new HashSet<>();
|
||||
for (final Suggestions suggestions : input) {
|
||||
for (final String text : suggestions.getList()) {
|
||||
texts.add(new Suggestion(suggestions.getRange(), text));
|
||||
}
|
||||
texts.addAll(suggestions.getList());
|
||||
}
|
||||
return create(command, texts);
|
||||
}
|
||||
@@ -92,12 +89,12 @@ public class Suggestions {
|
||||
end = Math.max(suggestion.getRange().getEnd(), end);
|
||||
}
|
||||
final StringRange range = new StringRange(start, end);
|
||||
final Set<String> texts = Sets.newHashSet();
|
||||
final Set<Suggestion> texts = Sets.newHashSet();
|
||||
for (final Suggestion suggestion : suggestions) {
|
||||
texts.add(suggestion.expand(command, range));
|
||||
}
|
||||
final List<String> sorted = Lists.newArrayList(texts);
|
||||
sorted.sort(String::compareToIgnoreCase);
|
||||
final List<Suggestion> sorted = Lists.newArrayList(texts);
|
||||
sorted.sort((a, b) -> a.getText().compareToIgnoreCase(b.getText()));
|
||||
return new Suggestions(range, sorted);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user