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:pl.reticular.ttw.game.model.Spider.java

private void switchToAttack(Node fingerNode) {
    LinkedList<Node> newPath = graph.findPathToNode(target, fingerNode, fingerDetectDistance);
    if (newPath != null) {
        Node node = newPath.removeFirst();
        if (node != target) {
            Log.e(getClass().getName(), "Bad path");
        }/*from  w  w w. ja  va 2  s.c o m*/
        path = newPath;
        mode = MODE_ATTACK;
    } else {
        switchToRandom();
    }
}

From source file:no.norrs.projects.andronary.service.DokproUioService.java

public HashMap<String, List<String>> lookup(String dict) {
    HashMap<String, List<String>> results = new HashMap<String, List<String>>();
    try {/*from w  w w.  ja v  a  2 s. c  o  m*/
        HttpResponse response;
        switch (selectedDict) {
        case nbNO: {
            response = HttpUtil.GET(
                    new URL(String.format("%s?OPP=%s&ordbok=%s&s=%s",
                            "http://www.dokpro.uio.no/perl/ordboksoek/ordbok.cgi", dict, "bokmaal", "n")),
                    null);
            break;
        }
        case nnNO: {
            response = HttpUtil.GET(
                    new URL(String.format("%s?OPP=%s&ordbok=%s&s=%s",
                            "http://www.dokpro.uio.no/perl/ordboksoek/ordbok.cgi", dict, "nynorsk", "n")),
                    null);
            break;
        }
        default:
            return null;
        }
        String responseString = HttpUtil.readString(response.getEntity().getContent(), "ISO-8859-1");

        //System.out.println(responseString);
        Parser parser = new Parser(responseString);

        NodeList list = parser
                .parse(new AndFilter(new TagNameFilter("TR"), new HasAttributeFilter("valign", "top")));

        // refuses to find colspan 2        Tag (1665[0,1665],1694[0,1694]): TD align="left" colspan="2"   LAME
        // Problems with parser like finding attribute "colspan" etc, makes filtering annoying.
        // Apply ugly results hack begins here:
        //@todo GET A CLEANER SOLUTION ....

        Node[] nodes = list.toNodeArray();

        // Skipping first and 2 last results by the filter, static content not removed by filter.
        for (int i = 1; i < nodes.length - 2; i++) {
            Node test = nodes[i].getFirstChild().getFirstChild();

            if (test.getParent().getNextSibling().getFirstChild().getText().equals("TABLE")) {
                LinkedList<String> dataToAdd = new LinkedList<String>(Arrays
                        .asList(test.getParent().getNextSibling().toPlainTextString().split("&nbsp;&nbsp")));
                String topic = dataToAdd.getFirst().trim();
                dataToAdd.removeFirst();
                results.put(topic, dataToAdd);
            }

        }

        //System.out.println("Results: " + results.size());
    } catch (URISyntaxException ex) {
        Logger.getLogger(DokproUioService.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserException ex) {
        Logger.getLogger(DokproUioService.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(DokproUioService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return results;
}

From source file:org.apache.camel.component.pdf.text.DefaultLineBuilderStrategy.java

/**
 * Builds lines from words. Utilizes the same behaviour as office software:
 * <ul>/*from   w w  w . j a v a  2 s .c om*/
 *     <li>If word doesn't fit in current line, and current lines contains other words, then
 *     it will be moved to new line.</td>
 *     <li>Word doesn't fit in the line and line does not contain other words, then word will be
 *     slitted, and split index will be on max amount of characters that fits in the line </li>
 * </ul>
 */
@Override
public Collection<String> buildLines(Collection<String> splittedText) throws IOException {
    LinkedList<String> wordsList = new LinkedList<String>(splittedText);
    Collection<String> lines = new ArrayList<String>();
    LineBuilder currentLine = new LineBuilder();
    float allowedLineWidth = getAllowedLineWidth();
    while (!wordsList.isEmpty()) {
        String word = wordsList.removeFirst();
        if (isWordFitInCurrentLine(currentLine, word, allowedLineWidth)) {
            currentLine.appendWord(word);
            if (wordsList.isEmpty()) {
                lines.add(currentLine.buildLine());
            }
        } else if (currentLine.getWordsCount() != 0) {
            lines.add(currentLine.buildLine());
            wordsList.addFirst(word);
        } else {
            int splitIndex = findSplitIndex(word, allowedLineWidth);
            currentLine.appendWord(word.substring(0, splitIndex));
            lines.add(currentLine.buildLine());
            wordsList.addFirst(word.substring(splitIndex));
        }
    }
    return lines;
}

From source file:com.icantrap.collections.dawg.DawgBuilder.java

private void compress() {
    LinkedList<Node> stack = new LinkedList<Node>();
    int index = 0;

    stack.addLast(root);/*from w  w  w.jav  a2 s .c  om*/
    while (!stack.isEmpty()) {
        Node ptr = stack.removeFirst();

        ptr.index = index++;
        if (root != ptr)
            ptr.siblings = ptr.parent.nextChildren.size() - 1 + (null == ptr.parent.child ? 0 : 1);
        nodeList.add(ptr);

        for (Node nextChild : ptr.nextChildren)
            stack.add(nextChild);
        if (null != ptr.child)
            stack.add(ptr.child);
    }

    // assign child depths to all nodes
    for (Node node : nodeList)
        if (node.terminal) {
            node.childDepth = 0;

            Node ptr = node;
            int depth = 0;
            while (root != ptr) {
                ptr = ptr.parent;
                ++depth;
                if (depth > ptr.childDepth)
                    ptr.childDepth = depth;
                else
                    break;
            }
        }

    // bin nodes by child depth
    for (Node node : nodeList) {
        LinkedList<Node> nodes = childDepths.get(node.childDepth);
        if (null == nodes) {
            nodes = new LinkedList<Node>();
            nodes.add(node);
            childDepths.put(node.childDepth, nodes);
        } else
            nodes.add(node);
    }

    int maxDepth = -1;
    for (int depth : childDepths.keySet())
        if (depth > maxDepth)
            maxDepth = depth;

    for (int depth = 0; depth <= maxDepth; ++depth) {
        LinkedList<Node> nodes = childDepths.get(depth);
        if (null == nodes)
            continue;

        for (ListIterator<Node> pickNodeIter = nodes.listIterator(); pickNodeIter.hasNext();) {
            Node pickNode = pickNodeIter.next();

            if ((null == pickNode.replaceMeWith) && pickNode.isChild && (0 == pickNode.siblings))
                for (ListIterator<Node> searchNodeIter = nodes
                        .listIterator(pickNodeIter.nextIndex()); searchNodeIter.hasNext();) {
                    Node searchNode = searchNodeIter.next();
                    if ((null == searchNode.replaceMeWith) && searchNode.isChild && (0 == searchNode.siblings)
                            && pickNode.equals(searchNode)) {
                        searchNode.parent.child = pickNode;
                        searchNode.replaceMeWith = pickNode;
                    }
                }
        }
    }
}

From source file:com.icantrap.collections.dawg.DawgBuilder.java

/**
 * Builds the dawg based on the words added.
 *
 * @return the new Dawg instance//from   w w  w  .j  a  v a  2s . com
 */
public Dawg build() {
    compress();

    for (Node node : nodeList)
        node.index = -1;

    LinkedList<Node> stack = new LinkedList<Node>();

    nodeList.clear();
    stack.clear();
    stack.addLast(root);

    int index = 0;

    while (!stack.isEmpty()) {
        Node ptr = stack.removeFirst();
        if (-1 == ptr.index)
            ptr.index = index++;
        nodeList.add(ptr);

        for (Node nextChild : ptr.nextChildren)
            stack.addLast(nextChild);
        if (null != ptr.child)
            stack.addLast(ptr.child);
    }

    int[] ints = new int[index];

    for (Node node : nodeList)
        ints[node.index] = node.toInteger();

    return new Dawg(ints);
}

From source file:com.asakusafw.runtime.directio.DirectDataSourceRepository.java

/**
 * Returns all {@link DirectDataSource}s registered in this repository.
 * @return all {@link DirectDataSource}s
 * @throws IOException if failed to initialize data sources
 * @throws InterruptedException if interrupted
 *//*from  w  ww . j av a  2s  .c  om*/
public Collection<String> getContainerPaths() throws IOException, InterruptedException {
    Collection<String> results = new ArrayList<>();
    LinkedList<Node> work = new LinkedList<>();
    work.add(root);
    while (work.isEmpty() == false) {
        Node node = work.removeFirst();
        if (node.hasContent()) {
            results.add(node.path.getPathString());
        }
        work.addAll(node.children.values());
    }
    return results;
}

From source file:com.moss.simpledeb.core.action.LaunchScriptAction.java

@Override
public void run(DebState state) throws Exception {

    {// w  w w .  j  ava  2  s .  c  om
        File target = new File(targetFile).getParentFile();
        LinkedList<File> pathsNeeded = new LinkedList<File>();

        File f = target;
        while (f != null) {
            pathsNeeded.addFirst(f);
            f = f.getParentFile();
        }

        for (int i = 0; i < pathLevel; i++) {
            pathsNeeded.removeFirst();
        }

        for (File e : pathsNeeded) {
            String p = "./" + e.getPath();

            if (!p.endsWith("/")) {
                p = p + "/";
            }

            TarArchiveEntry tarEntry = new TarArchiveEntry(p);
            tarEntry.setGroupId(0);
            tarEntry.setGroupName("root");
            tarEntry.setIds(0, 0);
            tarEntry.setModTime(System.currentTimeMillis());
            tarEntry.setSize(0);
            tarEntry.setUserId(0);
            tarEntry.setUserName("root");
            tarEntry.setMode(Integer.parseInt("755", 8));

            ArchivePath path = new DirArchivePath(tarEntry);
            state.addPath(DebComponent.CONTENT, path);
        }
    }

    String cp;
    {
        StringBuffer sb = new StringBuffer();
        for (String path : state.classpath) {
            if (sb.length() == 0) {
                sb.append(path);
            } else {
                sb.append(":");
                sb.append(path);
            }
        }
        cp = sb.toString();
    }

    StringBuilder sb = new StringBuilder();
    sb.append("#!/bin/bash\n");
    sb.append("CP=\"");
    sb.append(cp);
    sb.append("\"\n");
    sb.append("/usr/bin/java -cp $CP ");
    sb.append(className);
    sb.append(" $@\n");

    byte[] data = sb.toString().getBytes();

    String entryName = "./" + targetFile;

    TarArchiveEntry tarEntry = new TarArchiveEntry(entryName);
    tarEntry.setGroupId(0);
    tarEntry.setGroupName("root");
    tarEntry.setIds(0, 0);
    tarEntry.setModTime(System.currentTimeMillis());
    tarEntry.setSize(data.length);
    tarEntry.setUserId(0);
    tarEntry.setUserName("root");
    tarEntry.setMode(Integer.parseInt("755", 8));

    ArchivePath path = new BytesArchivePath(tarEntry, data);
    state.addPath(DebComponent.CONTENT, path);
}

From source file:aiai.ai.core.ExecProcessService.java

private String readLastLines(int maxSize, File consoleLogFile) throws IOException {
    LinkedList<String> lines = new LinkedList<>();
    String inputLine;/*from w  w  w.ja va 2s.c o  m*/
    try (FileReader fileReader = new FileReader(consoleLogFile);
            BufferedReader in = new BufferedReader(fileReader)) {
        while ((inputLine = in.readLine()) != null) {
            inputLine = inputLine.trim();
            if (lines.size() == maxSize) {
                lines.removeFirst();
            }
            lines.add(inputLine);
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String line : lines) {
        sb.append(line).append('\n');
    }
    return sb.toString();
}

From source file:com.moss.simpledeb.core.action.CopyAction.java

@Override
public void run(final DebState state) throws Exception {

    File target = new File(targetDir);
    LinkedList<File> pathsNeeded = new LinkedList<File>();

    File f = target;/*  w w  w.j  a  va  2 s  .  c  o m*/
    while (f != null) {
        pathsNeeded.addFirst(f);
        f = f.getParentFile();
    }

    for (int i = 0; i < assumedTargetPathLevel; i++) {
        pathsNeeded.removeFirst();
    }

    for (File e : pathsNeeded) {
        String p = "./" + e.getPath();

        if (!p.endsWith("/")) {
            p = p + "/";
        }

        TarArchiveEntry tarEntry = new TarArchiveEntry(p);
        tarEntry.setGroupId(0);
        tarEntry.setGroupName("root");
        tarEntry.setIds(0, 0);
        tarEntry.setModTime(System.currentTimeMillis());
        tarEntry.setSize(0);
        tarEntry.setUserId(0);
        tarEntry.setUserName("root");
        tarEntry.setMode(Integer.parseInt("755", 8));

        ArchivePath path = new DirArchivePath(tarEntry);
        state.addPath(component, path);
    }

    files.visit(new FileVisitor() {
        public void file(File file) {
            try {
                copyFile(file, state);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    });
}

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

public void popCurrentSession() {
    LinkedList stack = (LinkedList) currentJbpmSessionStack.get();
    if ((stack == null) || (stack.isEmpty()) || (stack.getFirst() != this)) {
        log.warn("can't pop current session: are you calling JbpmSession.close() multiple times ?");
    } else {/*w  ww  .  j av  a  2  s  . c om*/
        stack.removeFirst();
    }
}