Example usage for java.util Deque descendingIterator

List of usage examples for java.util Deque descendingIterator

Introduction

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

Prototype

Iterator<E> descendingIterator();

Source Link

Document

Returns an iterator over the elements in this deque in reverse sequential order.

Usage

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);/*ww w.jav a  2  s .  co  m*/
    deque.add(2);
    deque.add(3);
    deque.add(4);

    for (Iterator itr = deque.iterator(); itr.hasNext();) {
        System.out.println(itr.next());
    }

    for (Iterator descItr = deque.descendingIterator(); descItr.hasNext();) {
        System.out.println(descItr.next());
    }
}

From source file:Main.java

private static <T> Iterator<T> reverse(Iterable<T> values) {
    Deque<T> reversed = new LinkedList<>();
    for (T value : values) {
        reversed.add(value);//from   www  . j a  va 2  s.  co  m
    }
    return reversed.descendingIterator();
}

From source file:com.twosigma.beaker.core.rest.RecentMenuRest.java

private static List<String> reverseView(Deque<String> input) {
    List<String> ret = new ArrayList<>(input.size());
    Iterator<String> it = input.descendingIterator();
    while (it.hasNext()) {
        ret.add(it.next());// w w w  .  j ava2  s .  c o m
    }
    return ret;
}

From source file:org.alfresco.repo.content.transform.TransformerDebugLog.java

@Override
protected void addOrModify(Deque<DebugEntry> entries, Object message) {
    String msg = (String) message;
    String requestId = getRequestId(msg);
    if (requestId != null) {
        Iterator<DebugEntry> iterator = entries.descendingIterator();
        while (iterator.hasNext()) {
            DebugEntry entry = iterator.next();
            if (requestId.equals(entry.requestId)) {
                entry.addLine(msg);/*from   www.j  av a2 s .  c  o m*/
                return;
            }
        }
        entries.add(new DebugEntry(requestId, msg));
    }
}

From source file:com.griddynamics.banshun.DependencySorter.java

private List<Location> pullLocationListTail(Deque<Location> locations) {
    LinkedList<Location> resolvedLocations = new LinkedList<>();
    List<String> annihilatedExports = new LinkedList<>();

    for (Iterator<Location> it = locations.descendingIterator(); it.hasNext();) {
        Location location = it.next();

        if (annihilatedExports.containsAll(location.getExportBeanNames())) {
            it.remove(); //remove location from unresolved
            resolvedLocations.addFirst(location);

            for (BeanReferenceInfo imp : location.importBeans) {
                if (isSomewhereImported(locations, imp)) {
                    annihilatedExports.add(imp.getServiceName());
                }/*w  w w .  j av a 2s . com*/
            }
            it = locations.descendingIterator(); //reset iterator
        }
    }
    return resolvedLocations;
}

From source file:au.com.cybersearch2.classyfy.ClassyfyLogic.java

public NodeDetailsBean getNodeDetails(Node data) {
    NodeDetailsBean nodeDetailsBean = new NodeDetailsBean();
    // Collect children, distinguishing between folders and categories
    for (Node child : data.getChildren()) {
        String title = child.getTitle();
        long id = (long) child.getId();
        ListItem item = new ListItem("Title", title, id);
        if (RecordModel.getModel(child.getModel()) == RecordModel.recordFolder)
            nodeDetailsBean.getFolderTitles().add(item);
        else/*from  w w w .  jav a  2  s .  c o m*/
            nodeDetailsBean.getCategoryTitles().add(item);
    }
    // Collect node hierarchy up to root node
    Node node = data.getParent();
    Deque<Node> nodeDeque = new ArrayDeque<Node>();
    // Walk up to top node
    while (node.getModel() != NodeType.ROOT)// Top of tree
    {
        nodeDeque.add(node);
        node = node.getParent();
    }
    Iterator<Node> nodeIterator = nodeDeque.descendingIterator();
    while (nodeIterator.hasNext()) {
        node = nodeIterator.next();
        String title = node.getTitle();
        long id = (long) node.getId();
        ListItem item = new ListItem("Title", title, id);
        nodeDetailsBean.getHierarchy().add(item);
    }
    // Build heading from Title and record type
    StringBuilder builder = new StringBuilder();
    builder.append(RecordModel.getNameByNode(data)).append(": ");
    if ((data.getTitle() != null) && (data.getTitle().length() > 0))
        builder.append(data.getTitle());
    else
        builder.append('?'); // This is an error. Handle gracefully.
    nodeDetailsBean.setHeading(builder.toString());
    // Collect details in FieldDescripter order
    Map<String, Object> valueMap = data.getProperties();
    Set<FieldDescriptor> fieldSet = FieldDescriptorSetFactory.instance(data);
    for (FieldDescriptor descriptor : fieldSet) {
        Object value = valueMap.get(descriptor.getName());
        if (value == null)
            continue;
        nodeDetailsBean.getFieldList().add(new ListItem(descriptor.getTitle(), value.toString()));
    }
    return nodeDetailsBean;
}

From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java

private boolean isPreviousElementDatatype(Deque<XSElementDeclaration> eltStack) {
    final Iterator<XSElementDeclaration> it = eltStack.descendingIterator();
    // skip the tail element
    it.next();//from   w  w w.j  ava2s  .c  om
    if (!it.hasNext()) {
        return false;
    }
    final XSTypeDefinition lastType = it.next().getTypeDefinition();
    return this.datatypeUsages.containsKey(typeQName(lastType));
}

From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java

private boolean isSameElementDatatypePresentInPreviousLevels(Deque<XSElementDeclaration> eltStack,
        int uptoNoOfLevels) {
    final Iterator<XSElementDeclaration> it = eltStack.descendingIterator();
    // skip the tail element
    final XSTypeDefinition checkType = it.next().getTypeDefinition();
    XSTypeDefinition lastType = null;//from   w  w w .  ja v a  2 s  .c  o m
    for (int i = 0; i < uptoNoOfLevels; i++) {
        if (!it.hasNext()) {
            return false;
        }
        lastType = it.next().getTypeDefinition();
        if (typeQName(checkType).equals(typeQName(lastType))) {
            return true;
        }
    }
    return false;
}

From source file:org.springframework.xd.dirt.stream.zookeeper.ZooKeeperStreamRepository.java

@Override
public void delete(String id) {
    logger.info("Undeploying stream {}", id);

    String streamDeploymentPath = Paths.build(Paths.STREAM_DEPLOYMENTS, id);
    String streamModuleDeploymentPath = Paths.build(streamDeploymentPath, Paths.MODULES);
    CuratorFramework client = zkConnection.getClient();
    Deque<String> paths = new ArrayDeque<String>();

    try {//from  ww  w .  j  ava2 s.  com
        client.setData().forPath(Paths.build(Paths.STREAM_DEPLOYMENTS, id, Paths.STATUS), ZooKeeperUtils
                .mapToBytes(new DeploymentUnitStatus(DeploymentUnitStatus.State.undeploying).toMap()));
    } catch (Exception e) {
        logger.warn("Exception while transitioning stream {} state to {}", id,
                DeploymentUnitStatus.State.undeploying, e);
    }

    // Place all module deployments into a tree keyed by the
    // ZK transaction id. The ZK transaction id maintains
    // total ordering of all changes. This allows the
    // undeployment of modules in the reverse order in
    // which they were deployed.
    Map<Long, String> txMap = new TreeMap<Long, String>();
    try {
        List<String> deployments = client.getChildren().forPath(streamModuleDeploymentPath);
        for (String deployment : deployments) {
            String path = new StreamDeploymentsPath(Paths.build(streamModuleDeploymentPath, deployment))
                    .build();
            Stat stat = client.checkExists().forPath(path);
            Assert.notNull(stat);
            txMap.put(stat.getCzxid(), path);
        }
    } catch (Exception e) {
        //NoNodeException - nothing to delete
        ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class);
    }

    for (String deployment : txMap.values()) {
        paths.add(deployment);
    }

    for (Iterator<String> iterator = paths.descendingIterator(); iterator.hasNext();) {
        try {
            String path = iterator.next();
            logger.trace("removing path {}", path);
            client.delete().deletingChildrenIfNeeded().forPath(path);
        } catch (Exception e) {
            ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class);
        }
    }

    try {
        client.delete().deletingChildrenIfNeeded().forPath(streamDeploymentPath);
    } catch (KeeperException.NotEmptyException e) {
        List<String> children = new ArrayList<String>();
        try {
            children.addAll(client.getChildren().forPath(streamModuleDeploymentPath));
        } catch (Exception ex) {
            children.add("Could not load list of children due to " + ex);
        }
        throw new IllegalStateException(String.format("The following children were not deleted from %s: %s",
                streamModuleDeploymentPath, children), e);
    } catch (Exception e) {
        ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class);
    }
}

From source file:loci.formats.in.LIFReader.java

private void populateOriginalMetadata(Element root, Deque<String> nameStack) {
    String name = root.getNodeName();
    if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment")
            && !name.equals("LMSDataContainerHeader")) {
        nameStack.push(name);//from  www .ja  v a  2s  . c  om

        String suffix = root.getAttribute("Identifier");
        String value = root.getAttribute("Variant");
        if (suffix == null || suffix.trim().length() == 0) {
            suffix = root.getAttribute("Description");
        }
        StringBuffer key = new StringBuffer();
        final Iterator<String> nameStackIterator = nameStack.descendingIterator();
        while (nameStackIterator.hasNext()) {
            final String k = nameStackIterator.next();
            key.append(k);
            key.append("|");
        }
        if (suffix != null && value != null && suffix.length() > 0 && value.length() > 0
                && !suffix.equals("HighInteger") && !suffix.equals("LowInteger")) {
            addSeriesMetaList(key.toString() + suffix, value);
        } else {
            NamedNodeMap attributes = root.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                Attr attr = (Attr) attributes.item(i);
                if (!attr.getName().equals("HighInteger") && !attr.getName().equals("LowInteger")) {
                    addSeriesMeta(key.toString() + attr.getName(), attr.getValue());
                }
            }
        }
    }

    NodeList children = root.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Object child = children.item(i);
        if (child instanceof Element) {
            populateOriginalMetadata((Element) child, nameStack);
        }
    }

    if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment")
            && !name.equals("LMSDataContainerHeader")) {
        nameStack.pop();
    }
}