Example usage for java.util LinkedList addFirst

List of usage examples for java.util LinkedList addFirst

Introduction

In this page you can find the example usage for java.util LinkedList addFirst.

Prototype

public void addFirst(E e) 

Source Link

Document

Inserts the specified element at the beginning of this list.

Usage

From source file:com.google.dart.engine.services.internal.correction.CorrectionUtils.java

/**
 * @return parent {@link ASTNode}s from {@link CompilationUnit} (at index "0") to the given one.
 *//*  w  w  w .j  av  a2  s  .  c  om*/
public static List<ASTNode> getParents(ASTNode node) {
    LinkedList<ASTNode> parents = Lists.newLinkedList();
    ASTNode current = node;
    do {
        parents.addFirst(current.getParent());
        current = current.getParent();
    } while (current.getParent() != null);
    return parents;
}

From source file:org.jbpm.db.JbpmSession.java

public void pushCurrentSession() {
    LinkedList stack = (LinkedList) currentJbpmSessionStack.get();
    if (stack == null) {
        stack = new LinkedList();
        currentJbpmSessionStack.set(stack);
    }//ww w . j  a  v a  2  s  .  c o  m
    stack.addFirst(this);
}

From source file:org.iti.structureGraph.StructureGraph.java

private List<IStructureElement> getElementPathElements(IStructureElement element, boolean toRootElement) {
    IStructureElement currentElement = element;
    LinkedList<IStructureElement> elements = new LinkedList<>();
    int elementCount = (toRootElement) ? -1 : 2;

    while (currentElement != null && elementCount != 0) {
        elements.addFirst(currentElement);

        currentElement = getParent(currentElement);

        elementCount--;/*ww  w  . j  a  va 2s  .  c om*/
    }

    return elements;
}

From source file:org.dcm4chee.archive.conf.defaults.DeepEquals.java

/**
 * Deeply compare two SortedMap instances.  This method walks the Maps in order,
 * taking advantage of the fact that they Maps are SortedMaps.
 * @param dualKey SortedMaps/*  w  ww. j a va2s  .c om*/
 * @param stack add items to compare to the Stack (Stack versus recursion)
 * @param visited Set containing items that have already been compared, to prevent cycles.
 * @return false if the Maps are for certain not equals.  'true' indicates that 'on the surface' the maps
 * are equal, however, it will place the contents of the Maps on the stack for further comparisons.
 */
private static boolean compareSortedMap(DualKey dualKey, LinkedList stack, Set visited) {

    SortedMap map1 = (SortedMap) dualKey._key1;
    SortedMap map2 = (SortedMap) dualKey._key2;

    // Same instance check already performed...

    if (map1.size() != map2.size()) {
        return false;
    }

    Iterator i1 = map1.entrySet().iterator();
    Iterator i2 = map2.entrySet().iterator();

    while (i1.hasNext()) {
        Map.Entry entry1 = (Map.Entry) i1.next();
        Map.Entry entry2 = (Map.Entry) i2.next();

        // Must split the Key and Value so that Map.Entry's equals() method is not used.
        DualKey dk = new DualKey(entry1.getKey(), entry2.getKey(), dualKey);
        if (!visited.contains(dk)) { // Push Keys for further comparison
            stack.addFirst(dk);
        }

        dk = new DualKey(entry1.getValue(), entry2.getValue(), dualKey);
        if (!visited.contains(dk)) { // Push values for further comparison
            stack.addFirst(dk);
        }
    }
    return true;
}

From source file:com.opengamma.web.portfolio.WebPortfolioNodeResource.java

/**
 * Extracts the path from the root node to the current node, for web breadcrumb display.
 * The nodes are returned in a list, ordered from root to current node.
 * Not using findNodeStackByObjectId(), which traverses the tree exhaustively until it finds the required path.
 * @param node  the current node/*  w w w .jav a  2 s . c  om*/
 * @return      a list of <UniqueId, String> pairs denoting all nodes on the path from root to current node
 */
protected List<ObjectsPair<UniqueId, String>> getPathNodes(ManageablePortfolioNode node) {
    LinkedList<ObjectsPair<UniqueId, String>> result = new LinkedList<ObjectsPair<UniqueId, String>>();

    ManageablePortfolioNode currentNode = node;
    while (currentNode != null) {
        result.addFirst(new ObjectsPair<UniqueId, String>(currentNode.getUniqueId(), currentNode.getName()));
        currentNode = (currentNode.getParentNodeId() == null) ? null
                : data().getPortfolioMaster().getNode(currentNode.getParentNodeId());
    }
    return result;
}

From source file:org.dcm4chee.archive.conf.defaults.DeepEquals.java

/**
 * Deeply compare the two sets referenced by dualKey.  This method attempts
 * to quickly determine inequality by length, then if lengths match, it
 * places one collection into a temporary Map by deepHashCode(), so that it
 * can walk the other collection and look for each item in the map, which
 * runs in O(N) time, rather than an O(N^2) lookup that would occur if each
 * item from collection one was scanned for in collection two.
 * @param dualKey Collections//from  w  w w .java 2 s  .c  o  m
 * @param stack add items to compare to the Stack (Stack versus recursion)
 * @param visited Set containing items that have already been compared,
 * so as to prevent cycles.
 * @return boolean false if the Collections are for certain not equals. A
 * value of 'true' indicates that the Collections may be equal, and the sets
 * items will be added to the Stack for further comparison.
 */
private static boolean compareUnorderedCollection(DualKey dualKey, LinkedList stack, Set visited) {
    Collection col1 = (Collection) dualKey._key1;
    Collection col2 = (Collection) dualKey._key2;

    // Same instance check already performed...

    if (col1.size() != col2.size()) {
        return false;
    }

    Map fastLookup = new HashMap();
    for (Object o : col2) {
        fastLookup.put(deepHashCode(o), o);
    }

    for (Object o : col1) {
        Object other = fastLookup.get(deepHashCode(o));
        if (other == null) { // Item not even found in other Collection, no need to continue.
            return false;
        }

        DualKey dk = new DualKey(o, other, dualKey);
        if (!visited.contains(dk)) { // Place items on 'stack' for further comparison.
            stack.addFirst(dk);
        }
    }
    return true;
}

From source file:org.polymap.p4.atlas.ui.SearchContentProvider.java

public TreePath treePathOf(Object elm) {
    LinkedList result = new LinkedList();
    for (Object current = elm; current != null; current = getParent(current)) {
        if (current != input) {
            result.addFirst(current);
        }// w  w w. j ava  2s.c  o m
    }
    return new TreePath(result.toArray());
}

From source file:org.apache.ode.bpel.compiler.v1.WSDLRegistry.java

@SuppressWarnings("unchecked")
private void captureSchemas(Definition def, ResourceFinder rf, URI defuri) throws CompilationException {
    assert def != null;

    if (__log.isDebugEnabled())
        __log.debug("Processing XSD schemas in " + def.getDocumentBaseURI());

    Types types = def.getTypes();

    if (types != null) {
        for (ExtensibilityElement ee : ((List<ExtensibilityElement>) def.getTypes()
                .getExtensibilityElements())) {
            if (ee instanceof XMLSchemaType) {
                String schema = ((XMLSchemaType) ee).getXMLSchema();
                WsdlFinderXMLEntityResolver resolver = new WsdlFinderXMLEntityResolver(rf, defuri,
                        _internalSchemas, false);
                try {
                    Map<URI, byte[]> capture = XSUtils.captureSchema(defuri, schema, resolver);
                    _schemas.putAll(capture);

                    try {
                        Document doc = DOMUtils.parse(new InputSource(new StringReader(schema)));
                        String schemaTargetNS = doc.getDocumentElement().getAttribute("targetNamespace");
                        if (schemaTargetNS != null && schemaTargetNS.length() > 0)
                            _internalSchemas.put(new URI(schemaTargetNS), schema);
                        _documentSchemas.put(new URI(schemaTargetNS), doc);
                    } catch (Exception e) {
                        throw new RuntimeException("Couldn't parse schema in " + def.getTargetNamespace(), e);
                    }// www. j a va2s .  c om
                } catch (XsdException xsde) {
                    __log.debug("captureSchemas: capture failed for " + defuri, xsde);

                    LinkedList<XsdException> exceptions = new LinkedList<XsdException>();
                    while (xsde != null) {
                        exceptions.addFirst(xsde);
                        xsde = xsde.getPrevious();
                    }

                    for (XsdException ex : exceptions) {
                        // TODO: the line number here is going to be wrong for the in-line schema.
                        // String location = ex.getSystemId() + ":"  + ex.getLineNumber();
                        CompilationException ce = new CompilationException(__cmsgs
                                .errSchemaError(ex.getDetailMessage()).setSource(new SourceLocation(defuri)));
                        if (_ctx != null)
                            _ctx.recoveredFromError(new SourceLocation(defuri), ce);
                        else
                            throw ce;
                    }
                }
                // invalidate model
                _model = null;

            }
        }
    }
}

From source file:com.stimulus.archiva.domain.EmailFilter.java

public void setPriority(int id, Priority priority) {
    LinkedList<FilterRule> list = filterRules;
    FilterRule ar = filterRules.get(id);
    list.remove(ar);//from w  ww .  j  av a  2 s  . co  m

    switch (priority) {
    case HIGHER:
        if ((id - 1) <= 0)
            list.addFirst(ar);
        else
            list.add(id - 1, ar);
        break;
    case LOWER:
        if ((id + 1) >= list.size())
            list.addLast(ar);
        else
            list.add(id + 1, ar);
        break;
    case HIGHEST:
        list.addFirst(ar);
        break;
    case LOWEST:
        list.addLast(ar);
        break;
    }
}

From source file:org.apache.ode.bpel.compiler.v2.WSDLRegistry.java

@SuppressWarnings("unchecked")
private void captureSchemas(Definition def, ResourceFinder rf, URI defuri) throws CompilationException {
    assert def != null;

    if (__log.isDebugEnabled())
        __log.debug("Processing XSD schemas in " + def.getDocumentBaseURI());

    Types types = def.getTypes();

    if (types != null) {
        for (ExtensibilityElement ee : ((List<ExtensibilityElement>) def.getTypes()
                .getExtensibilityElements())) {
            if (ee instanceof XMLSchemaType) {
                String schema = ((XMLSchemaType) ee).getXMLSchema();

                WsdlFinderXMLEntityResolver resolver = new WsdlFinderXMLEntityResolver(rf, defuri,
                        _internalSchemas, false);

                try {
                    Map<URI, byte[]> capture = XSUtils.captureSchema(defuri, schema, resolver);
                    _schemas.putAll(capture);

                    try {
                        Document doc = DOMUtils.parse(new InputSource(new StringReader(schema)));
                        String schemaTargetNS = doc.getDocumentElement().getAttribute("targetNamespace");
                        if (schemaTargetNS != null && schemaTargetNS.length() > 0) {
                            _internalSchemas.put(new URI(schemaTargetNS), schema);
                            _documentSchemas.put(new URI(schemaTargetNS), doc);
                        }//  w w  w  .ja va 2 s . co m
                    } catch (Exception e) {
                        throw new RuntimeException("Couldn't parse schema in " + def.getTargetNamespace(), e);
                    }
                } catch (XsdException xsde) {
                    __log.debug("captureSchemas: capture failed for " + defuri, xsde);

                    LinkedList<XsdException> exceptions = new LinkedList<XsdException>();
                    while (xsde != null) {
                        exceptions.addFirst(xsde);
                        xsde = xsde.getPrevious();
                    }

                    for (XsdException ex : exceptions) {
                        // TODO: the line number here is going to be wrong for the in-line schema.
                        // String location = ex.getSystemId() + ":"  + ex.getLineNumber();
                        CompilationException ce = new CompilationException(__cmsgs
                                .errSchemaError(ex.getDetailMessage()).setSource(new SourceLocation(defuri)));
                        if (_ctx != null)
                            _ctx.recoveredFromError(new SourceLocation(defuri), ce);
                        else
                            throw ce;
                    }
                }
                // invalidate model
                _model = null;

            }
        }
    }
}