
javarepl.completion.AggregateCompleter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javarepl Show documentation
Show all versions of javarepl Show documentation
Java REPL is a simple Read-Eval-Print-Loop for Java language.
package javarepl.completion;
import com.googlecode.totallylazy.Group;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.functions.Function1;
import static com.googlecode.totallylazy.Groups.groupKey;
import static com.googlecode.totallylazy.Sequences.empty;
public class AggregateCompleter extends Completer {
private final Sequence completers;
public AggregateCompleter(Sequence completers) {
this.completers = completers;
}
public CompletionResult call(String expression) throws Exception {
Option> group = completeGroup(expression);
if (group.isEmpty())
return new CompletionResult(expression, 0, empty(CompletionCandidate.class));
return new CompletionResult(expression, group.get().key(), group.get().flatMap(CompletionResult::candidates));
}
private Option> completeGroup(String expression) {
return completers.map(complete(expression))
.unique()
.groupBy(CompletionResult::position)
.sortBy(groupKey(Integer.class))
.reverse()
.headOption();
}
private Function1 complete(final String expression) {
return completer -> completer.apply(expression);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy