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:org.fusesource.mop.MOP.java

private void copyCommand(LinkedList<String> argList) throws Exception {
    assertNotEmpty(argList);//w w  w .  j  a v  a 2  s .  c  o m
    artifactIds = parseArtifactList(argList);
    assertNotEmpty(argList);
    File targetDir = new File(argList.removeFirst());
    repository.copy(targetDir, artifactIds);
}

From source file:com.jaspersoft.jasperserver.export.modules.repository.ResourceImporter.java

protected void createPrependFolder() {
    if (prependPath != null) {
        LinkedList toCreateURIs = new LinkedList();
        for (String path = prependPath; repository.getFolder(executionContext,
                path) == null; path = PathUtils.splitPath(path).parentPath) {
            toCreateURIs.addFirst(path);
        }/*from  ww  w. j ava 2  s  .c om*/

        while (!toCreateURIs.isEmpty()) {
            String path = (String) toCreateURIs.removeFirst();
            Folder folder = createFolder(path);

            commandOut.debug("About to save folder " + path);
            try {
                repository.saveFolder(executionContext, folder);
            } catch (SpringSecurityException er) {
                this.updateSecuredResource(executionContext, folder);
            }
        }
    }
}

From source file:org.eclipse.ecr.core.storage.sql.TestSQLBackend.java

private static Map<String, Set<String>> buildDescendants(List<String[]> graph, String root) {
    Map<String, Set<String>> ancestors = new HashMap<String, Set<String>>();
    Map<String, Set<String>> descendants = new HashMap<String, Set<String>>();
    // create all sets, for clearer code later
    for (String[] edge : graph) {
        for (String n : edge) {
            if (!ancestors.containsKey(n)) {
                ancestors.put(n, new HashSet<String>());
            }//from   w  w w  .  j  a  v  a2  s.co  m
            if (!descendants.containsKey(n)) {
                descendants.put(n, new HashSet<String>());
            }
        }
    }
    // traverse from root
    LinkedList<String> todo = new LinkedList<String>();
    todo.add(root);
    do {
        String p = todo.removeFirst();
        for (String[] edge : graph) {
            if (edge[0].equals(p)) {
                // found a child
                String c = edge[1];
                todo.add(c);
                // child's ancestors
                Set<String> cans = ancestors.get(c);
                cans.addAll(ancestors.get(p));
                cans.add(p);
                // all ancestors have it as descendant
                for (String pp : cans) {
                    descendants.get(pp).add(c);
                }
            }
        }
    } while (!todo.isEmpty());
    return descendants;
}

From source file:org.fusesource.mop.MOP.java

public void executeCommand(LinkedList<String> argList) throws Exception {
    resetValues();/*from  w  w w  .  j  a va2 s .  c o  m*/
    if (argList.isEmpty()) {
        throw new UsageException("No command specified.");
    }

    String command = argList.removeFirst();
    if (command.equals("exec")) {
        execJava(argList);
    } else if (command.equals("execjar")) {
        execJarCommand(argList);
    } else if (command.equals("jar")) {
        jarCommand(argList);
    } else if (command.equals("run")) {
        runCommand(argList);
    } else if (command.equals("echo")) {
        echoCommand(argList);
    } else if (command.equals("classpath")) {
        classpathCommand(argList);
    } else if (command.equals("copy")) {
        copyCommand(argList);
    } else if (command.equals("war")) {
        warCommand(argList);
    } else if (command.equals("help")) {
        helpCommand(argList);
    } else if (command.equals("list")) {
        listCommand(argList);
    } else if (command.equals("uninstall")) {
        uninstallCommand(argList);
    } else {
        tryDiscoverCommand(command, argList);
    }
}

From source file:com.github.lindenb.jvarkit.tools.misc.BamTile.java

@Override
public Collection<Throwable> call(final String inputName) throws Exception {
    SAMRecordIterator iter = null;/*from   w  w w  .  j  a va  2 s.  c  om*/
    SamReader sfr = null;
    SAMFileWriter sfw = null;
    try {
        sfr = openSamReader(inputName);

        SAMFileHeader header1 = sfr.getFileHeader();
        if (header1 == null) {
            return wrapException("File header missing");
        }

        if (header1.getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
            return wrapException("File header not sorted on coordinate");
        }

        SAMFileHeader header2 = header1.clone();
        header2.addComment(getName() + ":" + getVersion() + ":" + getProgramCommandLine());

        sfw = openSAMFileWriter(header2, true);

        SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header1);
        iter = sfr.iterator();
        LinkedList<SAMRecord> buffer = new LinkedList<>();
        for (;;) {
            SAMRecord rec = null;
            if (iter.hasNext()) {
                rec = progress.watch(iter.next());
                if (rec.getReadUnmappedFlag())
                    continue;
                if (!buffer.isEmpty()) {
                    SAMRecord last = buffer.getLast();
                    if (last.getReferenceIndex() == rec.getReferenceIndex()
                            && last.getAlignmentStart() <= rec.getAlignmentStart()
                            && last.getAlignmentEnd() >= rec.getAlignmentEnd()) {
                        continue;
                    }
                }
            }
            if (rec == null
                    || (!buffer.isEmpty() && buffer.getLast().getReferenceIndex() != rec.getReferenceIndex())) {
                while (!buffer.isEmpty()) {
                    sfw.addAlignment(buffer.removeFirst());
                }
                if (rec == null)
                    break;
            }
            buffer.add(rec);

            if (buffer.size() > 2) {
                int index = buffer.size();
                SAMRecord prev = buffer.get(index - 3);
                SAMRecord curr = buffer.get(index - 2);
                SAMRecord next = buffer.get(index - 1);

                if (prev.getAlignmentEnd() >= next.getAlignmentStart()
                        || curr.getAlignmentEnd() <= prev.getAlignmentEnd()) {
                    buffer.remove(index - 2);
                } else if (curr.getAlignmentStart() == prev.getAlignmentStart()
                        && curr.getAlignmentEnd() > prev.getAlignmentEnd()) {
                    buffer.remove(index - 3);
                }

            }
            while (buffer.size() > 3) {
                sfw.addAlignment(buffer.removeFirst());
            }

        }
        progress.finish();
        LOG.info("done");
        return Collections.emptyList();
    } catch (Exception err) {
        return wrapException(err);
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(sfr);
        CloserUtil.close(sfw);
    }
}

From source file:org.cloudata.core.tabletserver.RecordSearcher.java

private List<ColumnValue> mergeColumnValueFromSearcher(List<Searchable> searcherList, CellFilter cellFilter)
        throws IOException {
    LinkedList<ColumnValueEntry> workPlace = new LinkedList<ColumnValueEntry>();
    Searchable[] searchers = searcherList.toArray(new Searchable[] {});

    try {/*w w w .  ja  va2 s .c o  m*/
        initWorkPlace(workPlace, searchers);

        int numOfValues = cellFilter.getNumOfValues();

        List<ColumnValue> result = new ArrayList<ColumnValue>();
        ValueCollection currentColumnValues = new ValueCollection();

        Cell.Key previousColumnKey = null;
        ColumnValue previousColumnValue = null;

        boolean end = false;

        while (!end) {
            int size = workPlace.size();
            if (size == 0) {
                break;
            }
            Collections.sort(workPlace);
            ColumnValueEntry winner = workPlace.removeFirst();

            if (previousColumnKey == null) {
                previousColumnKey = winner.columnValue.getCellKey();
            }

            //meets new ValueCollection
            if (!previousColumnKey.equals(winner.columnValue.getCellKey())) {
                currentColumnValues.moveMatchedValues(cellFilter, result);
                currentColumnValues = new ValueCollection();
            }

            if (previousColumnValue == null || !previousColumnValue.equals(winner.columnValue)) {
                currentColumnValues.add(winner.columnValue, numOfVersion);
                previousColumnKey = winner.columnValue.getCellKey();
                previousColumnValue = winner.columnValue;
            }

            //fetch from winner, add workPlace
            end = !fetchFromWinner(workPlace, searchers, winner.index);

            if (result.size() >= numOfValues) {
                break;
            }
        } //end of while

        if (result.size() < numOfValues) {
            //check last value in while loop
            if (currentColumnValues.getValueSize() > 0) {
                currentColumnValues.moveMatchedValues(cellFilter, result);
            }
            return result;
        } else {
            return result.subList(0, numOfValues);
        }
    } finally {
        //scnner close
        for (int i = 0; i < searchers.length; i++) {
            if (searchers[i] != null) {
                try {
                    searchers[i].close();
                } catch (IOException e) {
                    LOG.error("Can't close scanner:" + searchers[i]);
                }
                searchers[i] = null;
            }
        }
    }
}

From source file:org.gephi.statistics.plugin.ConnectedComponents.java

public void weaklyConnected(HierarchicalUndirectedGraph hgraph, AttributeModel attributeModel) {
    isCanceled = false;/*from  w ww  .ja  v a 2 s .co m*/
    componentCount = 0;
    AttributeTable nodeTable = attributeModel.getNodeTable();
    AttributeColumn componentCol = nodeTable.getColumn(WEAKLY);
    if (componentCol == null) {
        componentCol = nodeTable.addColumn(WEAKLY, "Component ID", AttributeType.INT, AttributeOrigin.COMPUTED,
                new Integer(0));
    }

    List<Integer> sizeList = new ArrayList<Integer>();

    hgraph.readLock();

    HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
    int index = 0;
    for (Node s : hgraph.getNodes()) {
        indicies.put(s, index);
        index++;
    }

    int N = hgraph.getNodeCount();

    //Keep track of which nodes have been seen
    int[] color = new int[N];

    Progress.start(progress, hgraph.getNodeCount());
    int seenCount = 0;
    while (seenCount < N) {
        //The search Q
        LinkedList<Node> Q = new LinkedList<Node>();
        //The component-list
        LinkedList<Node> component = new LinkedList<Node>();

        //Seed the seach Q
        NodeIterable iter = hgraph.getNodes();
        for (Node first : iter) {
            if (color[indicies.get(first)] == 0) {
                Q.add(first);
                iter.doBreak();
                break;
            }
        }

        //While there are more nodes to search
        while (!Q.isEmpty()) {
            if (isCanceled) {
                hgraph.readUnlock();
                return;
            }
            //Get the next Node and add it to the component list
            Node u = Q.removeFirst();
            component.add(u);

            //Iterate over all of u's neighbors
            EdgeIterable edgeIter = hgraph.getEdgesAndMetaEdges(u);

            //For each neighbor
            for (Edge edge : edgeIter) {
                Node reachable = hgraph.getOpposite(u, edge);
                int id = indicies.get(reachable);
                //If this neighbor is unvisited
                if (color[id] == 0) {
                    color[id] = 1;
                    //Add it to the search Q
                    Q.addLast(reachable);
                    //Mark it as used 

                    Progress.progress(progress, seenCount);
                }
            }
            color[indicies.get(u)] = 2;
            seenCount++;
        }
        for (Node s : component) {
            AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
            row.setValue(componentCol, componentCount);
        }
        sizeList.add(component.size());
        componentCount++;
    }
    hgraph.readUnlock();

    componentsSize = new int[sizeList.size()];
    for (int i = 0; i < sizeList.size(); i++) {
        componentsSize[i] = sizeList.get(i);
    }
}

From source file:org.apache.openjpa.jdbc.sql.JoinSet.java

/**
 * Iterator over joins that prepares them for SQL translation.
 *//* w w  w  .j a v a  2 s  . co m*/
public Iterator joinIterator() {
    if (_size < 2)
        return iterator();
    if (_sorted != null)
        return _sorted.iterator();

    List sorted = new ArrayList(_size);
    LinkedList queue = new LinkedList();
    BitSet seen = new BitSet(_graph.size() * _graph.size() + _graph.size());

    // traverse graph
    Node n;
    int idx, sidx;
    for (int i = 0; i < _graph.size(); i++) {
        // seed queue with next set of disconnected joins
        for (n = (Node) _graph.get(i); n != null; n = n.next) {
            sidx = getSeenIndex(n.join);
            if (!seen.get(sidx)) {
                seen.set(sidx);
                queue.add(n);
            }
        }
        if (queue.isEmpty())
            continue;

        // traverse from those joins to reachables
        while (!queue.isEmpty()) {
            n = (Node) queue.removeFirst();

            // don't repeat a join to a table we've already joined, but
            // do traverse through it in the graph (the first indexes of
            // the seeen bitset are reserved for joined-to tables)
            idx = (n.forward) ? n.join.getIndex2() : n.join.getIndex1();
            if (!seen.get(idx)) {
                sorted.add((n.forward) ? n.join : n.join.reverse());
                seen.set(idx);
            }

            for (n = (Node) _graph.get(idx); n != null; n = n.next) {
                sidx = getSeenIndex(n.join);
                if (!seen.get(sidx)) {
                    seen.set(sidx);
                    queue.add(n);
                }
            }
        }
    }
    _sorted = sorted;
    return _sorted.iterator();
}

From source file:org.fusesource.mop.MOP.java

private void runCommand(LinkedList<String> argList)
        throws Exception, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    assertNotEmpty(argList);//from w  w  w .  j  ava  2  s  . c o m
    artifactIds = parseArtifactList(argList);
    assertNotEmpty(argList);
    className = argList.removeFirst();
    reminingArgs = argList;

    List<File> dependencies = resolveFiles();
    runClass(dependencies);
}

From source file:org.gephi.statistics.plugin.ConnectedComponents.java

private void tarjans(AttributeColumn col, LinkedList<Node> S, HierarchicalDirectedGraph hgraph, Node f,
        int[] index, int[] low_index, HashMap<Node, Integer> indicies) {
    int id = indicies.get(f);
    index[id] = count;//from   w  ww  .  j  a va 2  s.c  o m
    low_index[id] = count;
    count++;
    S.addFirst(f);
    EdgeIterable edgeIter = hgraph.getOutEdgesAndMetaOutEdges(f);
    for (Edge e : edgeIter) {
        Node u = hgraph.getOpposite(f, e);
        int x = indicies.get(u);
        if (index[x] == 0) {
            tarjans(col, S, hgraph, u, index, low_index, indicies);
            low_index[id] = Math.min(low_index[x], low_index[id]);
        } else if (S.contains(u)) {
            low_index[id] = Math.min(low_index[id], index[x]);
        }
    }
    if (low_index[id] == index[id]) {
        Node v = null;
        while (v != f) {
            v = S.removeFirst();
            AttributeRow row = (AttributeRow) v.getNodeData().getAttributes();
            row.setValue(col, stronglyCount);
        }
        stronglyCount++;
    }
}