@Test public void flags() { final List<Option> options = new ArrayList<>(); options.add(new Option("--assignee, -a=<String[]>", null)); options.add(new Option("--body, -b=<String>", null)); options.add(new Option("--body-formatter, -g=<String>", null)); options.add(new Option("--assign", null)); options.add(new Option("--file, -f=<File>", null)); options.add(new Option("--a", null)); final List<String> flags = Highlight.flags(options); assertEquals("--body-formatter\n" + "--assignee\n" + "--assign\n" + "--file\n" + "--body\n" + "--a\n" + "-g\n" + "-f\n" + "-b\n" + "-a", Join.join("\n", flags)); }
static List<String> flags(final List<Option> options) { return options.stream() .map(Option::getFlag) .map(s -> s.split(", ")) .flatMap(Stream::of) .map(s -> s.replaceAll("=.*", "")) .map(String::trim) .filter(s -> s.startsWith("-")) .sorted(Comparator.reverseOrder()) .sorted((o1, o2) -> Integer.compare(o2.length(), o1.length())) .collect(Collectors.toList()); }
Highlight { static List<String> flags(final List<Option> options) { return options.stream() .map(Option::getFlag) .map(s -> s.split(", ")) .flatMap(Stream::of) .map(s -> s.replaceAll("=.*", "")) .map(String::trim) .filter(s -> s.startsWith("-")) .sorted(Comparator.reverseOrder()) .sorted((o1, o2) -> Integer.compare(o2.length(), o1.length())) .collect(Collectors.toList()); } }
Highlight { static List<String> flags(final List<Option> options) { return options.stream() .map(Option::getFlag) .map(s -> s.split(", ")) .flatMap(Stream::of) .map(s -> s.replaceAll("=.*", "")) .map(String::trim) .filter(s -> s.startsWith("-")) .sorted(Comparator.reverseOrder()) .sorted((o1, o2) -> Integer.compare(o2.length(), o1.length())) .collect(Collectors.toList()); } Highlight(final List<Option> options); }
Highlight { static List<String> flags(final List<Option> options) { return options.stream() .map(Option::getFlag) .map(s -> s.split(", ")) .flatMap(Stream::of) .map(s -> s.replaceAll("=.*", "")) .map(String::trim) .filter(s -> s.startsWith("-")) .sorted(Comparator.reverseOrder()) .sorted((o1, o2) -> Integer.compare(o2.length(), o1.length())) .collect(Collectors.toList()); } Highlight(final List<Option> options); String highlight(String text); String matches(String text); }
Highlight { static List<String> flags(final List<Option> options) { return options.stream() .map(Option::getFlag) .map(s -> s.split(", ")) .flatMap(Stream::of) .map(s -> s.replaceAll("=.*", "")) .map(String::trim) .filter(s -> s.startsWith("-")) .sorted(Comparator.reverseOrder()) .sorted((o1, o2) -> Integer.compare(o2.length(), o1.length())) .collect(Collectors.toList()); } Highlight(final List<Option> options); String highlight(String text); String matches(String text);  }