org.jline.reader.impl.completer.AggregateCompleter Maven / Gradle / Ivy
/*
* Copyright (c) 2002-2016, the original author(s).
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.reader.impl.completer;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.jline.reader.Candidate;
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
import org.jline.reader.ParsedLine;
/**
* Completer which contains multiple completers and aggregates them together.
*
* @author Jason Dillon
* @since 2.3
*/
public class AggregateCompleter implements Completer {
private final Collection completers;
/**
* Construct an AggregateCompleter with the given completers.
* The completers will be used in the order given.
*
* @param completers the completers
*/
public AggregateCompleter(final Completer... completers) {
this(Arrays.asList(completers));
}
/**
* Construct an AggregateCompleter with the given completers.
* The completers will be used in the order given.
*
* @param completers the completers
*/
public AggregateCompleter(Collection completers) {
assert completers != null;
this.completers = completers;
}
/**
* Retrieve the collection of completers currently being aggregated.
*
* @return the aggregated completers
*/
public Collection getCompleters() {
return completers;
}
/**
* Perform a completion operation across all aggregated completers.
*
* The effect is similar to the following code:
* {@code completers.forEach(c -> c.complete(reader, line, candidates));}
*
* @see Completer#complete(LineReader, ParsedLine, List)
*/
public void complete(LineReader reader, final ParsedLine line, final List candidates) {
Objects.requireNonNull(line);
Objects.requireNonNull(candidates);
completers.forEach(c -> c.complete(reader, line, candidates));
}
/**
* @return a string representing the aggregated completers
*/
@Override
public String toString() {
return getClass().getSimpleName() + "{" + "completers=" + completers + '}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy