Example usage for java.util Deque forEach

List of usage examples for java.util Deque forEach

Introduction

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

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:com.ggvaidya.scinames.model.Project.java

public void serializeToDocument(Document doc) {
    // Add top-level element.
    Element project = doc.createElement("project");
    project.setAttribute("name", getName());
    doc.appendChild(project);// w  w w  .  j a v  a  2s.c om

    // Set up some properties.
    properties.put(PROP_NAME_EXTRACTORS,
            getNameExtractors().stream().map(lne -> NameExtractorFactory.serializeExtractorsToString(lne))
                    .distinct().sorted().collect(Collectors.joining("; ")));

    // Write out properties.
    Element propertiesElement = doc.createElement("properties");
    for (String key : properties.keySet()) {
        Element p = doc.createElement("property");
        p.setAttribute("name", key);
        p.setTextContent(properties.get(key));
        propertiesElement.appendChild(p);
    }
    project.appendChild(propertiesElement);

    // Add filters.
    Element filtersElement = doc.createElement("filters");
    Deque<ChangeFilter> changeFilters = new LinkedList<>();
    {
        // We need to read the filters inside-out, so they'll be recreated
        // the right way around.
        ChangeFilter cf = getChangeFilter();
        while (cf != null) {
            changeFilters.addLast(cf);
            cf = cf.getPrevChangeFilter();
        }
    }
    changeFilters.forEach(cf -> {
        // Skip any nulls.
        if (cf.getShortName().equals("null"))
            return;

        filtersElement.appendChild(cf.serializeToElement(doc));
    });

    project.appendChild(filtersElement);

    // List all timepoints.
    Element timepointsElement = doc.createElement("datasets");
    for (Dataset tp : getDatasets()) {
        Element t = tp.serializeToElement(doc);
        timepointsElement.appendChild(t);
    }
    project.appendChild(timepointsElement);
}

From source file:org.dataconservancy.packaging.tool.impl.generator.IPMUtil.java

public static String path(Node node, String suffix) {
    Deque<String> pathStack = new ArrayDeque<>();

    pathStack.push(suffix);/*w  ww. j a  v  a 2s  .co  m*/
    pathStack.push(name(node));

    while (!node.isRoot()) {
        node = node.getParent();
        if (node.getFileInfo() != null && !node.getFileInfo().isFile()) {
            pathStack.push("/");
            pathStack.push(name(node));
        }
    }

    StringBuilder builder = new StringBuilder();
    pathStack.forEach(builder::append);
    return builder.toString();

}