/** * Construct an AggregateCompleter with the given collection of completers. * The completers will be used in the iteration order of the collection. * * @param completers the collection of completers */ public SortedAggregateCompleter(final Collection<Completer> completers) { checkNotNull(completers); this.completers.addAll(completers); }
public Completion(final List<CharSequence> candidates) { checkNotNull(candidates); this.candidates = new LinkedList<CharSequence>(candidates); }
public StringsCompleter(final Collection<String> strings) { Preconditions.checkNotNull(strings); getStrings().addAll(strings); }
private int completeCollection(final String buffer, final int cursor, final Collection<CharSequence> candidates) { Preconditions.checkNotNull(candidates); if (buffer == null) { candidates.addAll(strings); } else { String part = buffer.substring(0, cursor); String bufferTmp = part.toUpperCase(); for (String match : strings.tailSet(part)) { String matchTmp = match.toUpperCase(); if (!matchTmp.startsWith(bufferTmp)) { break; } candidates.add(match); } } return candidates.isEmpty() ? -1 : 0; } }
public void complete(final Completer completer, final String buffer, final int cursor) { checkNotNull(completer); this.cursor = completer.complete(buffer, cursor, candidates); } }
/** * @param strings The completer strings */ public StringsCompleter(final Collection<String> strings) { checkNotNull(strings); getStrings().addAll(strings); }
@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { // buffer could be null checkNotNull(candidates); if (buffer == null) { candidates.addAll(commands); } else { String prefix = buffer; if (buffer.length() > cursor) { prefix = buffer.substring(0, cursor); } for (String match : commands.tailSet(prefix)) { if (!match.startsWith(prefix)) { break; } candidates.add(match); } } if (candidates.size() == 1) { candidates.set(0, candidates.get(0) + " "); } return candidates.isEmpty() ? -1 : 0; }
@Override public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) { // buffer could be null checkNotNull(candidates); if (buffer == null) { candidates.addAll(getStrings()); } else { for (String match : getStrings().tailSet(buffer)) { if (!match.startsWith(buffer)) { break; } candidates.add(match); } } if (candidates.size() == 1) { candidates.set(0, candidates.get(0) + " "); } return candidates.isEmpty() ? -1 : 0; } }
@Override public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) { // buffer could be null checkNotNull(candidates); List<Completion> completions = new ArrayList<Completion>(completers.size()); // Run each completer, saving its completion results int max = -1; for (Completer completer : completers) { Completion completion = new Completion(candidates); completion.complete(completer, buffer, cursor); // Compute the max cursor position max = Math.max(max, completion.cursor); completions.add(completion); } SortedSet<CharSequence> allCandidates = new TreeSet<>(); // Append candidates from completions which have the same cursor position as max for (Completion completion : completions) { if (completion.cursor == max) { allCandidates.addAll(completion.candidates); } } candidates.addAll(allCandidates); return max; }
/** * @param arguments The array of tokens * @param cursorArgumentIndex The token index of the cursor * @param argumentPosition The position of the cursor in the current token * @param bufferPosition The position of the cursor in the whole buffer */ public ArgumentList(final String[] arguments, final int cursorArgumentIndex, final int argumentPosition, final int bufferPosition) { this.arguments = checkNotNull(arguments); this.cursorArgumentIndex = cursorArgumentIndex; this.argumentPosition = argumentPosition; this.bufferPosition = bufferPosition; }
/** * Create a new completer with the specified argument delimiter. * * @param delimiter The delimiter for parsing arguments * @param completers The embedded completers */ public ArgumentCompleter(final ArgumentDelimiter delimiter, final Collection<Completer> completers) { this.delimiter = checkNotNull(delimiter); checkNotNull(completers); this.completers.addAll(completers); }
/** * Construct an AggregateCompleter with the given collection of completers. * The completers will be used in the iteration order of the collection. * * @param completers the collection of completers */ public AggregateCompleter(final Collection<Completer> completers) { checkNotNull(completers); this.completers.addAll(completers); }
/** * Create a FileHistory, but only initialize if doInit is true. This allows * setting maxSize or other settings; call load() before using if doInit is * false. */ public FileHistory(final File file, final boolean doInit) throws IOException { this.file = checkNotNull(file).getAbsoluteFile(); if (doInit) { load(); } }
public EnumCompleter(Class<? extends Enum<?>> source, boolean toLowerCase) { checkNotNull(source); for (Enum<?> n : source.getEnumConstants()) { this.getStrings().add(toLowerCase ? n.name().toLowerCase() : n.name()); } } }
public void complete(final Completer completer, final String buffer, final int cursor) { checkNotNull(completer); this.cursor = completer.complete(buffer, cursor, candidates); } }
public AnsiStringsCompleter(final Collection<String> strings) { checkNotNull(strings); for (String str : strings) { this.strings.put(Ansi.stripAnsi(str), str); } }
public void load(final Reader reader) throws IOException { checkNotNull(reader); BufferedReader input = new BufferedReader(reader); String item; while ((item = input.readLine()) != null) { internalAdd(item); } }
public void add(CharSequence item) { checkNotNull(item); if (isAutoTrim()) { item = String.valueOf(item).trim(); } if (isIgnoreDuplicates()) { if (!items.isEmpty() && item.equals(items.getLast())) { return; } } internalAdd(item); }
public UnixTerminal(String ttyDevice, String type) throws Exception { super(true); checkNotNull(ttyDevice); this.settings = TerminalLineSettings.getSettings(ttyDevice); if (type == null) { type = System.getenv("TERM"); } this.type = type; parseInfoCmp(); }
public String getPropertyAsString(String name) { checkNotNull(name); if (!fetchConfig(name)) { return null; } return getPropertyAsString(name, config); }