Example usage for java.util LinkedList removeFirst

List of usage examples for java.util LinkedList removeFirst

Introduction

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

Prototype

public E removeFirst() 

Source Link

Document

Removes and returns the first element from this list.

Usage

From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java

/**
 * Returns the result of applying a filter using breadth-first traversal.
 *
 * @param context The parent context./*from  w ww.ja  va 2  s  . c om*/
 * @param node The root node to traverse from.
 * @param filter The filter to satisfy.
 * @return The first node reached via BFS traversal that satisfies the
 *         filter.
 */
public static AccessibilityNodeInfoCompat searchFromBfs(Context context, AccessibilityNodeInfoCompat node,
        NodeFilter filter) {
    if (node == null) {
        return null;
    }

    final LinkedList<AccessibilityNodeInfoCompat> queue = new LinkedList<AccessibilityNodeInfoCompat>();

    queue.add(AccessibilityNodeInfoCompat.obtain(node));

    while (!queue.isEmpty()) {
        final AccessibilityNodeInfoCompat item = queue.removeFirst();

        if (filter.accept(context, item)) {
            return AccessibilityNodeInfoCompat.obtain(item);
        }

        final int childCount = item.getChildCount();

        for (int i = 0; i < childCount; i++) {
            final AccessibilityNodeInfoCompat child = item.getChild(i);

            if (child != null) {
                queue.addLast(child);
            }
        }
    }

    return null;
}

From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java

private static List<Path> consumeStep(LinkedList<Segment> segments) {
    assert segments != null;
    assert segments.isEmpty() == false;
    assert segments.getFirst().isTraverse() == false;
    List<Path> results = new ArrayList<>();

    Segment current = segments.removeFirst();
    for (String segment : resolve(current)) {
        results.add(new Path(segment));
    }/*from   w ww .j  a v  a  2s .  c  om*/
    while (isGlobRequired(current) && segments.isEmpty() == false
            && segments.getFirst().isTraverse() == false) {
        current = segments.removeFirst();
        Set<String> suffixCandidates = resolve(current);
        if (suffixCandidates.size() == 1) {
            String suffix = suffixCandidates.iterator().next();
            for (ListIterator<Path> i = results.listIterator(); i.hasNext();) {
                Path parent = i.next();
                i.set(new Path(parent, suffix));
            }
        } else {
            List<Path> nextResults = new ArrayList<>();
            for (Path parent : results) {
                for (String suffix : suffixCandidates) {
                    nextResults.add(new Path(parent, suffix));
                }
            }
            results = nextResults;
        }
    }

    Set<Path> saw = new HashSet<>();
    for (Iterator<Path> iter = results.iterator(); iter.hasNext();) {
        Path path = iter.next();
        if (saw.contains(path)) {
            iter.remove();
        } else {
            saw.add(path);
        }
    }
    return results;
}

From source file:fitnesse.authentication.PasswordFile.java

private void loadCipher(LinkedList<String> lines) {
    if (lines.size() > 0) {
        String firstLine = lines.getFirst();
        if (firstLine.startsWith("!")) {
            String cipherClassName = firstLine.substring(1);
            instantiateCipher(cipherClassName);
            lines.removeFirst();
        }/* w  w w  . ja va2 s. co m*/
    }
}

From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java

/**
 * Returns the result of applying a filter using breadth-first traversal.
 *
 * @param context The parent context.//from   www .  jav  a  2s.c  o  m
 * @param node The root node to traverse from.
 * @param filter The filter to satisfy.
 * @param maxResults The number of results to stop searching after
 * @return The first n nodes reached via BFS traversal that satisfies the
 *         filter.
 */
public static List<AccessibilityNodeInfoCompat> searchAllFromBfs(Context context,
        AccessibilityNodeInfoCompat node, NodeFilter filter, int maxResults) {
    if (node == null) {
        return null;
    }

    final List<AccessibilityNodeInfoCompat> toReturn = new ArrayList<AccessibilityNodeInfoCompat>();
    final LinkedList<AccessibilityNodeInfoCompat> queue = new LinkedList<AccessibilityNodeInfoCompat>();

    queue.add(AccessibilityNodeInfoCompat.obtain(node));

    while (!queue.isEmpty() && toReturn.size() < maxResults) {
        final AccessibilityNodeInfoCompat item = queue.removeFirst();

        if (filter.accept(context, item)) {
            toReturn.add(AccessibilityNodeInfoCompat.obtain(item));
        }

        final int childCount = item.getChildCount();

        for (int i = 0; i < childCount; i++) {
            final AccessibilityNodeInfoCompat child = item.getChild(i);

            if (child != null) {
                queue.addLast(child);
            }
        }
    }

    return toReturn;
}

From source file:ltsa.jung.TreeLikeGraphLayout.java

/**
 * Computes the depths of every node by a BFS on the graph.  Stores 
 * the depth in {depths} and the maximal depth in {maxDepth}.
 *///from  w  w w . j  av a2s .co  m
protected void computeDepth() {
    if (root == null || graph == null)
        return;
    LinkedList<V> queue = new LinkedList<V>();
    queue.add(root);
    depths.put(root, 0);

    while (!queue.isEmpty()) {
        V v = queue.removeFirst(); // FIFO for BFS order

        for (V successor : graph.getSuccessors(v)) {
            if (!depths.containsKey(successor)) {
                int depth = depths.get(v) + 1;
                depths.put(successor, depth);
                if (depth > maxDepth)
                    maxDepth = depth;
                queue.add(successor);
            }
        }
    }
}

From source file:com.servioticy.queueclient.SimpleQueueClient.java

@Override
protected Object getImpl() {
    LinkedList<Object> queue;
    Object returnValue;// www  . j  a v  a 2 s.co m
    try {
        queue = readQueue();
    } catch (Exception e) {
        return null;
    }
    if (queue.isEmpty()) {
        return null;
    }
    returnValue = queue.getFirst();
    queue.removeFirst();

    try {
        writeQueue(queue);
    } catch (Exception e) {
    }

    return returnValue;
}

From source file:com.opera.core.systems.scope.stp.services.ScopeWindowManager.java

public void closeAllWindows() {
    int toBeClosed = windows.size();

    if (supportsClosingWindows()) {
        LinkedList<Integer> list = Lists.newLinkedList(windows.asStack());
        while (!list.isEmpty()) {
            closeWindow(list.removeFirst());
        }/* w  w  w .j  a  v  a  2 s  .co  m*/
    } else if (services.getExec().getActionList().contains(CLOSE_ALL_PAGES_ACTION)) {
        services.getExec().action(CLOSE_ALL_PAGES_ACTION);
        sleep(OperaIntervals.WINDOW_CLOSE_USING_ACTION_SLEEP.getMs() * toBeClosed);
    } else {
        // This is a different type of exception than the one in closeWindow(i)
        throw new UnsupportedOperationException("Product does not support closing windows");
    }
}

From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java

protected EditProcessObject createEpo(HttpServletRequest request, boolean forceNew) {
    /* this is actually a bit of a misnomer, because we will reuse an epo
    if an epoKey parameter is passed */
    EditProcessObject epo = null;//from w  w  w.j  a v a  2  s .c  o m
    HashMap epoHash = getEpoHash(request);
    String existingEpoKey = request.getParameter("_epoKey");
    if (!forceNew && existingEpoKey != null && epoHash.get(existingEpoKey) != null) {
        epo = (EditProcessObject) epoHash.get(existingEpoKey);
        epo.setKey(existingEpoKey);
        epo.setUseRecycledBean(true);
    } else {
        LinkedList epoKeylist = getEpoKeylist(request);
        if (epoHash.size() == MAX_EPOS) {
            try {
                epoHash.remove(epoKeylist.getFirst());
                epoKeylist.removeFirst();
            } catch (Exception e) {
                // see JIRA issue VITRO-340, "Odd exception from backend editing"
                // possible rare concurrency issue here
                log.error("Error removing old EPO", e);
            }
        }
        Random rand = new Random();
        String epoKey = createEpoKey();
        while (epoHash.get(epoKey) != null) {
            epoKey += Integer.toHexString(rand.nextInt());
        }
        epo = new EditProcessObject();
        epoHash.put(epoKey, epo);
        epoKeylist.add(epoKey);
        epo.setKey(epoKey);
        epo.setReferer(
                (forceNew) ? request.getRequestURL().append('?').append(request.getQueryString()).toString()
                        : request.getHeader("Referer"));
        epo.setSession(request.getSession());
    }
    return epo;
}

From source file:org.apache.jackrabbit.standalone.cli.JcrParser.java

/**
 * Parse the user's input.// www  . j a  va  2 s  .c  o m
 * @param input
 *        user's input
 * @throws JcrParserException
 *         if the input is illegal
 * @throws ConfigurationException
 *         if the mapped command can't be mapped to a Commons Chain Command
 */
public void parse(String input) throws JcrParserException, ConfigurationException {
    this.cl = null;
    this.cmd = null;

    // Validate input
    if (input == null || input.length() == 0) {
        throw new JcrParserException("exception.parse.input.empty");
    }

    // Extract arguments
    LinkedList args = this.getArguments(input);

    // The first arg is the command name
    String cmdName = (String) args.getFirst();
    args.removeFirst();

    // Get the command line descriptor
    cl = CommandLineFactory.getInstance().getCommandLine(cmdName);

    // populate with the given params
    populate(cl, args);

    // validate the command line
    validate(cl);

    // Create Chain Command
    String impl = cl.getImpl();
    if (impl == null) {
        impl = cl.getName();
    }
    cmd = catalog.getCommand(impl);

    if (cmd == null) {
        throw new JcrParserException("no chain command for name " + impl);
    }

}

From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java

private int applyOperations(LinkedList<AbstractJournalOperation> transactionQueue) throws JournalException {
    int newBlockCount = -1;
    while (transactionQueue.size() > 0) {
        AbstractJournalOperation op = transactionQueue.removeFirst();

        if (op instanceof MetaDataWriteOperation) {
            ((MetaDataWriteOperation) op).writeTo(allocationTableRandomAccessFile);
        } else if (op instanceof MetaDataBlockWriteOperation) {
            ((MetaDataBlockWriteOperation) op).writeTo(allocationTableRandomAccessFile);
        } else if (op instanceof DataBlockWriteOperation) {
            ((DataBlockWriteOperation) op).writeTo(dataRandomAccessFile);
        } else if (op instanceof StoreExtendOperation) {
            newBlockCount = ((StoreExtendOperation) op).extend(allocationTableRandomAccessFile,
                    dataRandomAccessFile);
        } else//from   ww  w. j av  a  2  s  .  c  o m
            throw new IllegalArgumentException("Unexpected journal operation : " + op);
    }

    return newBlockCount;
}