Example usage for java.util.stream Stream max

List of usage examples for java.util.stream Stream max

Introduction

In this page you can find the example usage for java.util.stream Stream max.

Prototype

Optional<T> max(Comparator<? super T> comparator);

Source Link

Document

Returns the maximum element of this stream according to the provided Comparator .

Usage

From source file:com.liferay.blade.cli.command.CreateCommand.java

private void _printTemplates() throws Exception {
    BladeCLI bladeCLI = getBladeCLI();/*w w w.j a v  a 2s. c  o  m*/

    Map<String, String> templates = BladeUtil.getTemplates(bladeCLI);

    List<String> templateNames = new ArrayList<>(BladeUtil.getTemplateNames(getBladeCLI()));

    Collections.sort(templateNames);

    Comparator<String> compareLength = Comparator.comparingInt(String::length);

    Stream<String> stream = templateNames.stream();

    String longestString = stream.max(compareLength).get();

    int padLength = longestString.length() + 2;

    for (String name : templateNames) {
        PrintStream out = bladeCLI.out();

        out.print(StringUtils.rightPad(name, padLength));

        bladeCLI.out(templates.get(name));
    }
}