List<SearchEverywhereCommandInfo> (Collection<? extends SearchEverywhereContributor<?>> contributors, String enteredCommandPart) { Comparator<SearchEverywhereCommandInfo> cmdComparator = (cmd1, cmd2) -> { String cmdName1 = cmd1.getCommand(); String cmdName2 = cmd2.getCommand(); if (!enteredCommandPart.isEmpty()) { if (cmdName1.startsWith(enteredCommandPart) && !cmdName2.startsWith(enteredCommandPart)) return -1; if (!cmdName1.startsWith(enteredCommandPart) && cmdName2.startsWith(enteredCommandPart)) return 1; } return String.CASE_INSENSITIVE_ORDER.compare(cmdName1, cmd2.getCommand()); }; return contributors.stream() .flatMap(contributor -> contributor.getSupportedCommands().stream()) .filter(command -> command.getCommand().contains(enteredCommandPart)) .sorted(cmdComparator) .collect(Collectors.toList()); }