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 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())); } } } }
boolean hasRightItem = j < columns - 1 && index.applyAsInt(i, j + 1) < candidates.size(); AttributedString left = AttributedString.fromAnsi(cand.displ()); AttributedString right = AttributedString.fromAnsi(cand.descr()); int lw = left.columnLength(); int rw = 0;