public String toString () { StringBuilder sb = new StringBuilder ("CLIPrefixedClassNameCompletor["); sb.append(hashCode()); for (Candidate c : candidates) { sb.append (System.getProperty("line.separator")); sb.append (" "); sb.append (c.value()); } sb.append(']'); return sb.toString(); } }
private void merge(List<Candidate> candidates) { Map<String, Candidate> map = new HashMap<>(); for (Candidate c : candidates) { map.merge(c.value(), c, (c1, c2) -> c1.descr() != null ? c1 : c2); } candidates.clear(); candidates.addAll(map.values()); }
private void merge(List<Candidate> candidates) { Map<String, Candidate> map = new HashMap<>(); for (Candidate c : candidates) { map.merge(c.value(), c, (c1, c2) -> c1.descr() != null ? c1 : c2); } candidates.clear(); candidates.addAll(map.values()); }
private void completeCommandName(String buf, List<Candidate> candidates) { if (buf == null) { // Nothing is there candidates.addAll(commandNames); } else if (buf.indexOf(' ') == -1) { // Partial one word List<Candidate> matchedNames = new ArrayList<Candidate>(); for (Candidate commandName : commandNames) { if (commandName.value().startsWith(buf)) { matchedNames.add(commandName); } } candidates.addAll(matchedNames); } else { throw new IllegalStateException("Invalid state"); } } }
private boolean doMatch(String arg, String name) { List<Candidate> candidates = new ArrayList<>(); completers.apply(name).complete(this.reader.get(), new ArgumentLine(arg, arg.length()), candidates); return candidates.stream().anyMatch(c -> c.value().equals(arg)); }
private boolean doMatch(String arg, String name) { List<Candidate> candidates = new ArrayList<>(); completers.apply(name).complete(this.reader.get(), new ArgumentLine(arg, arg.length()), candidates); return candidates.stream().anyMatch(c -> c.value().equals(arg)); }
private void mergeCandidates(List<Candidate> possible) { // Merge candidates if the have the same key Map<String, List<Candidate>> keyedCandidates = new HashMap<>(); for (Candidate candidate : possible) { if (candidate.key() != null) { List<Candidate> cands = keyedCandidates.computeIfAbsent(candidate.key(), s -> new ArrayList<>()); cands.add(candidate); } } if (!keyedCandidates.isEmpty()) { for (List<Candidate> candidates : keyedCandidates.values()) { if (candidates.size() >= 1) { possible.removeAll(candidates); // Candidates with the same key are supposed to have // the same description candidates.sort(Comparator.comparing(Candidate::value)); Candidate first = candidates.get(0); String disp = candidates.stream() .map(Candidate::displ) .collect(Collectors.joining(" ")); possible.add(new Candidate(first.value(), disp, first.group(), first.descr(), first.suffix(), null, first.complete())); } } } }
if (cand.value().equals(arg)) { found = true; break;
for (Candidate cand : candidates) { sortedCandidates .computeIfAbsent(AttributedString.fromAnsi(cand.value()).toString(), s -> new ArrayList<>()) .add(cand); completion = matching.values().stream().flatMap(Collection::stream) .filter(Candidate::complete) .filter(c -> exact.test(c.value())) .findFirst().orElse(null); if (completion != null && !completion.value().isEmpty()) { if (prefix) { buf.backspace(line.rawWordCursor()); buf.backspace(line.rawWordLength()); buf.write(line.escape(completion.value(), completion.complete())); if (completion.complete()) { if (buf.currChar() != ' ') {
private void update() { buf.backspace(word.length()); word = escaper.apply(completion().value(), true).toString(); buf.write(word);