Search in sources :

Example 26 with ArrayDeque

use of java.util.ArrayDeque in project checkstyle by checkstyle.

the class RequireThisCheck method getAllTokensWhichAreEqualToCurrent.

/**
     * Collects all tokens which are equal to current token starting with the current ast node and
     * which line number is lower or equal to the end line number.
     * @param ast ast node.
     * @param token token.
     * @param endLineNumber end line number.
     * @return a set of tokens which are equal to current token starting with the current ast node
     *         and which line number is lower or equal to the end line number.
     */
private static Set<DetailAST> getAllTokensWhichAreEqualToCurrent(DetailAST ast, DetailAST token, int endLineNumber) {
    DetailAST vertex = ast;
    final Set<DetailAST> result = new HashSet<>();
    final Deque<DetailAST> stack = new ArrayDeque<>();
    while (vertex != null || !stack.isEmpty()) {
        if (!stack.isEmpty()) {
            vertex = stack.pop();
        }
        while (vertex != null) {
            if (token.equals(vertex) && vertex.getLineNo() <= endLineNumber) {
                result.add(vertex);
            }
            if (vertex.getNextSibling() != null) {
                stack.push(vertex.getNextSibling());
            }
            vertex = vertex.getFirstChild();
        }
    }
    return result;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 27 with ArrayDeque

use of java.util.ArrayDeque in project hive by apache.

the class PTFDeserializer method initializePTFChain.

public void initializePTFChain(PartitionedTableFunctionDef tblFnDef) throws HiveException {
    Deque<PTFInputDef> ptfChain = new ArrayDeque<PTFInputDef>();
    PTFInputDef currentDef = tblFnDef;
    while (currentDef != null) {
        ptfChain.push(currentDef);
        currentDef = currentDef.getInput();
    }
    while (!ptfChain.isEmpty()) {
        currentDef = ptfChain.pop();
        if (currentDef instanceof PTFQueryInputDef) {
            initialize((PTFQueryInputDef) currentDef, inputOI);
        } else if (currentDef instanceof WindowTableFunctionDef) {
            initializeWindowing((WindowTableFunctionDef) currentDef);
        } else {
            initialize((PartitionedTableFunctionDef) currentDef);
        }
    }
    PTFDeserializer.alterOutputOIForStreaming(ptfDesc);
}
Also used : PTFInputDef(org.apache.hadoop.hive.ql.plan.ptf.PTFInputDef) WindowTableFunctionDef(org.apache.hadoop.hive.ql.plan.ptf.WindowTableFunctionDef) PartitionedTableFunctionDef(org.apache.hadoop.hive.ql.plan.ptf.PartitionedTableFunctionDef) ArrayDeque(java.util.ArrayDeque) PTFQueryInputDef(org.apache.hadoop.hive.ql.plan.ptf.PTFQueryInputDef)

Example 28 with ArrayDeque

use of java.util.ArrayDeque in project mongomvcc by igd-geo.

the class Index method readCommit.

/**
	 * Iteratively reads the information from the given commit and all its
	 * ancestors and builds up the index
	 * @param c the commit to read
	 * @param tree the tree of commits
	 */
private void readCommit(Commit c, Tree tree) {
    ArrayDeque<Commit> stack = new ArrayDeque<Commit>();
    while (true) {
        //iteratively read parent commit (if there is any)
        stack.addLast(c);
        long cid = c.getParentCID();
        if (cid == 0) {
            break;
        }
        c = tree.resolveCommit(cid);
    }
    while (!stack.isEmpty()) {
        c = stack.removeLast();
        //read objects from the given commit and put them into the index
        for (Map.Entry<String, IdMap> e : c.getObjects().entrySet()) {
            IdMap m = getObjects(e.getKey());
            IdSet o = getOIDs(e.getKey());
            IdMapIterator it = e.getValue().iterator();
            while (it.hasNext()) {
                it.advance();
                if (it.value() < 0) {
                    //deleted object
                    long prev = m.get(it.key());
                    if (prev != 0) {
                        m.remove(it.key());
                        o.remove(prev);
                    }
                } else {
                    long prev = m.put(it.key(), it.value());
                    if (prev != 0) {
                        //overwrite object with new value
                        o.remove(prev);
                    }
                    o.add(it.value());
                }
            }
        }
    }
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdMapIterator(de.fhg.igd.mongomvcc.helper.IdMapIterator) Map(java.util.Map) IdHashMap(de.fhg.igd.mongomvcc.helper.IdHashMap) HashMap(java.util.HashMap) IdMap(de.fhg.igd.mongomvcc.helper.IdMap) ArrayDeque(java.util.ArrayDeque)

Example 29 with ArrayDeque

use of java.util.ArrayDeque in project mapdb by jankotek.

the class ArrayDequeTest method testAdd.

/**
     * add(x) succeeds
     */
public void testAdd() {
    ArrayDeque q = new ArrayDeque();
    assertTrue(q.add(zero));
    assertTrue(q.add(one));
    assertSame(zero, q.peekFirst());
    assertSame(one, q.peekLast());
}
Also used : ArrayDeque(java.util.ArrayDeque)

Example 30 with ArrayDeque

use of java.util.ArrayDeque in project mapdb by jankotek.

the class ArrayDequeTest method testAddAll1.

/**
     * addAll(null) throws NPE
     */
public void testAddAll1() {
    ArrayDeque q = new ArrayDeque();
    try {
        q.addAll(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ArrayDeque(java.util.ArrayDeque)

Aggregations

ArrayDeque (java.util.ArrayDeque)217 ArrayList (java.util.ArrayList)36 Test (org.junit.Test)36 IOException (java.io.IOException)27 HashMap (java.util.HashMap)23 List (java.util.List)20 HashSet (java.util.HashSet)19 Map (java.util.Map)17 Deque (java.util.Deque)11 Iterator (java.util.Iterator)10 NoSuchElementException (java.util.NoSuchElementException)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 File (java.io.File)7 Path (java.nio.file.Path)7 Random (java.util.Random)7 ByteBuffer (java.nio.ByteBuffer)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 HttpFields (org.eclipse.jetty.http.HttpFields)5 Name (com.github.anba.es6draft.ast.scope.Name)4 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)4