Java 8 Deque - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Deque class.

This code example shows how to use the following methods: getFirst, pop, push
        parse(','); 
        return token;
    } 
 
    private State state() { 
        return states.getFirst();
    } 
 
    private void parse(char c) {
        char real = c;
        switch (c) {
            case ',': 
            case '\n': 
                switch (state()) { 
                    case EXPRESSION:
                    case ARRAY:
                    case STRING:
                    case OBJECT:
                        value += c;
                        break; 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: isEmpty, pop, push
    } 
 
    @Override 
    public Class<?> getType(ConfigVisitor visitor, ConfigVisitorNode previous) {
        Deque<ConfigVisitorNode> nodes = visitor.getCurrentNodes();
        if (nodes.isEmpty())
            throw new IllegalArgumentException("Cannot determine type - insufficient info on configuration!");
 
        ConfigVisitorNode current = nodes.pop();
        try { 
            if (current instanceof TypeProvider) {
                return TypeProvider.class.cast(current).getType(visitor, current);
            } else { 
                return getType(visitor, current);
            } 
        } finally { 
            nodes.push(current);
        } 
 
    } 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: isEmpty, addFirst, peek, peekFirst, removeFirst
 
    private Object next; 
    private boolean nextBlank = true;
 
    public void push(Iterator<?> iterator) {
        iterators.addFirst(iterator);
    } 
 
    @Override 
    public void remove() { 
        throw new UnsupportedOperationException();
    } 
 
    private void moveToNext() { 
        if (nextBlank && !this.iterators.isEmpty()) {
            if (!iterators.peek().hasNext()) {
                iterators.removeFirst();
                moveToNext(); 
            } else { 
                final Object next = iterators.peekFirst().next();

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: peek
    public E peek() { 
        Deque<E> st = deque.get();
        if (st == null) {
            return null; 
        } 
        return st.peek();
    } 
 
    public E pop() { 
        Deque<E> st = deque.get();
        if (st == null) {
            throw new EmptyStackException();
        } 
        E val = st.pop();
        if (st.isEmpty()) {
            deque.remove();
        } 
        return val;
    } 
 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addLast, removeFirst, size
    // correctness that the ring buffer and the frequencies table have 
    // consistent content 
    if (item == null) {
      throw new IllegalArgumentException("null items are not supported");
    } 
    assert ringBuffer.size() <= maxSize;
    if (ringBuffer.size() == maxSize) {
      // evict the oldest entry 
      final T removed = ringBuffer.removeFirst();
      final int newFrequency = frequency(removed) - 1;
      if (newFrequency == 0) {
        // free for GC 
        frequencies.remove(removed);
      } else { 
        frequencies.put(removed, newFrequency);
      } 
    } 
 
    // add the new entry and update frequencies 
    ringBuffer.addLast(item);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addFirst
                throw new ElasticsearchIllegalStateException("recycler entry already released..."); 
            } 
            final boolean recycle = beforeRelease();
            if (recycle) {
                c.recycle(value);
                deque.addFirst(value);
            } 
            else { 
                c.destroy(value);
            } 
            value = null;
            afterRelease(recycle);
        } 
    } 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addAll
    _stack = new ArrayDeque<Instruction>(); 
  } 
 
  public void scheduleInstructions(List<Instruction> instructions) 
  { 
    _stack.addAll(instructions);  /* adds to last */ 
  } 
 
  public boolean hasNext() 
  { 
    return !_stack.isEmpty(); 
  } 
 
  public Instruction next() 
  { 
    return _stack.removeLast(); 
  } 
 
  @Override 
  public void scheduleInstruction(Instruction instruction) 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addLast, removeFirst, size
  public ReadWriteLock getReadWriteLock() {
    return null; 
  } 
 
  private void cycleKeyList(Object key) { 
    keyList.addLast(key); 
    if (keyList.size() > size) {
      Object oldestKey = keyList.removeFirst(); 
      delegate.removeObject(oldestKey);
    } 
  } 
 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: add
  public void testPrepare() throws IOException {
    And and = new And();
    Expression first = mock(Expression.class);
    Expression second = mock(Expression.class);
 
    Deque<Expression> children = new LinkedList<Expression>();
    children.add(second);
    children.add(first);
    and.addChildren(children);
 
    and.prepare();
    verify(first).prepare();
    verify(second).prepare();
    verifyNoMoreInteractions(first);
    verifyNoMoreInteractions(second);
  } 
 
  // test finish is called on child 
  @Test(timeout = 1000)
  public void testFinish() throws IOException {
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: isEmpty, add, removeLast
    private final Deque<Number> stack = new LinkedList<Number>();
    private static final List<String> OPS = asList("-", "+", "*", "/");
 
    public void push(Object arg) { 
        if (OPS.contains(arg)) {
            Number y = stack.removeLast();
            Number x = stack.isEmpty() ? 0 : stack.removeLast();
            Double val = null;
            if (arg.equals("-")) { 
                val = x.doubleValue() - y.doubleValue();
            } else if (arg.equals("+")) { 
                val = x.doubleValue() + y.doubleValue();
            } else if (arg.equals("*")) { 
                val = x.doubleValue() * y.doubleValue();
            } else if (arg.equals("/")) { 
                val = x.doubleValue() / y.doubleValue();
            } 
            push(val);
        } else { 
            stack.add((Number) arg);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 Deque Methods: