Example usage for java.util TreeMap forEach

List of usage examples for java.util TreeMap forEach

Introduction

In this page you can find the example usage for java.util TreeMap forEach.

Prototype

@Override
    public void forEach(BiConsumer<? super K, ? super V> action) 

Source Link

Usage

From source file:org.commonjava.util.partyline.FileTree.java

/**
 * Iterate all {@link FileEntry instances} to extract information about active locks.
 *
 * @param predicate The selector determining which files to analyze.
 * @param fileConsumer The operation to extract information from a single active file.
 *//*  w  w  w. j  a  va  2s . c  o  m*/
void forAll(Predicate<? super FileEntry> predicate, Consumer<FileEntry> fileConsumer) {
    TreeMap<String, FileEntry> sorted = new TreeMap<>(entryMap);
    sorted.forEach((key, entry) -> {
        if (entry != null && predicate.test(entry)) {
            fileConsumer.accept(entry);
        }
    });
}

From source file:org.commonjava.util.partyline.FileTree.java

/**
 * Render the active files as a tree structure, for output to a log file or other string-oriented output.
 *//*from ww w . j a  v  a2 s .  co  m*/
String renderTree() {
    StringBuilder sb = new StringBuilder();
    TreeMap<String, FileEntry> sorted = new TreeMap<>(entryMap);
    sorted.forEach((key, entry) -> {
        sb.append("+- ");
        Stream.of(key.split("/")).forEach((part) -> sb.append("  "));

        sb.append(new File(key).getName());
        if (entry.file != null) {
            sb.append(" (F)");
        } else {
            sb.append("/");
        }
    });
    return sb.toString();
}

From source file:org.mycore.frontend.cli.MCRBasicCommands.java

/**
 * Shows the help text for one or more commands.
 *
 * @param pattern// w  w  w  .j av  a 2s .  co  m
 *            the command, or a fragment of it
 */
@MCRCommand(syntax = "help {0}", help = "Show the help text for the commands beginning with {0}.", order = 10)
public static void listKnownCommandsBeginningWithPrefix(String pattern) {
    TreeMap<String, List<org.mycore.frontend.cli.MCRCommand>> matchingCommands = MCRCommandManager
            .getKnownCommands().entrySet().stream()
            .collect(Collectors.toMap(e -> e.getKey(),
                    e -> e.getValue().stream().filter(
                            cmd -> cmd.getSyntax().contains(pattern) || cmd.getHelpText().contains(pattern))
                            .collect(Collectors.toList()),
                    (k, v) -> k, TreeMap::new));

    matchingCommands.entrySet().removeIf(e -> e.getValue().isEmpty());

    if (matchingCommands.isEmpty()) {
        MCRCommandLineInterface.output("Unknown command:" + pattern);
    } else {
        MCRCommandLineInterface.output("");

        matchingCommands.forEach((grp, cmds) -> {
            outputGroup(grp);
            cmds.forEach(org.mycore.frontend.cli.MCRCommand::outputHelp);
        });
    }
}