List of usage examples for java.util ArrayDeque pollFirst
public E pollFirst()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(25);/* ww w . j a v a2 s. c o m*/ deque.add(2); deque.add(1); deque.add(18); System.out.println(deque); int retval = deque.pollFirst(); System.out.println("Element removed is " + retval); System.out.println(deque); }
From source file:com.jaspersoft.android.jaspermobile.test.utils.SmartMockedSpiceManager.java
private <T> void handleResponse(RequestListener<T> requestListener, ArrayDeque<Object> queue) { Object response = queue.pollFirst(); if (response instanceof RequestExecutionAssertion) { requestListener.onRequestSuccess((T) ((RequestExecutionAssertion) response).getResponse()); } else {/*from w ww .j av a2s .co m*/ requestListener.onRequestSuccess((T) response); } }
From source file:com.jaspersoft.android.jaspermobile.test.utils.SmartMockedSpiceManager.java
private <T> void handleError(RequestListener<T> requestListener, ArrayDeque<SpiceException> queue) { requestListener.onRequestFailure(queue.pollFirst()); }
From source file:com.facebook.litho.dataflow.DataFlowGraph.java
private void regenerateSortedNodes() { mSortedNodes.clear();//ww w . ja v a 2 s. c om if (mBindings.size() == 0) { return; } final ArraySet<ValueNode> leafNodes = ComponentsPools.acquireArraySet(); final SimpleArrayMap<ValueNode, Integer> nodesToOutputsLeft = new SimpleArrayMap<>(); for (int i = 0, bindingsSize = mBindingToNodes.size(); i < bindingsSize; i++) { final ArraySet<ValueNode> nodes = mBindingToNodes.valueAt(i); for (int j = 0, nodesSize = nodes.size(); j < nodesSize; j++) { final ValueNode node = nodes.valueAt(j); final int outputCount = node.getOutputCount(); if (outputCount == 0) { leafNodes.add(node); } else { nodesToOutputsLeft.put(node, outputCount); } } } if (!nodesToOutputsLeft.isEmpty() && leafNodes.isEmpty()) { throw new DetectedCycleException("Graph has nodes, but they represent a cycle with no leaf nodes!"); } final ArrayDeque<ValueNode> nodesToProcess = ComponentsPools.acquireArrayDeque(); nodesToProcess.addAll(leafNodes); while (!nodesToProcess.isEmpty()) { final ValueNode next = nodesToProcess.pollFirst(); mSortedNodes.add(next); for (int i = 0, count = next.getInputCount(); i < count; i++) { final ValueNode input = next.getInputAt(i); final int outputsLeft = nodesToOutputsLeft.get(input) - 1; nodesToOutputsLeft.put(input, outputsLeft); if (outputsLeft == 0) { nodesToProcess.addLast(input); } else if (outputsLeft < 0) { throw new DetectedCycleException("Detected cycle."); } } } int expectedTotalNodes = nodesToOutputsLeft.size() + leafNodes.size(); if (mSortedNodes.size() != expectedTotalNodes) { throw new DetectedCycleException( "Had unreachable nodes in graph -- this likely means there was a cycle"); } Collections.reverse(mSortedNodes); mIsDirty = false; ComponentsPools.release(nodesToProcess); ComponentsPools.release(leafNodes); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testPollFirst() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertNull(deque.pollFirst()); assertTrue(deque.isEmpty());/*from w w w . ja v a 2s .c o m*/ deque.add(o1); assertEquals(o1, deque.pollFirst()); assertTrue(deque.isEmpty()); assertNull(deque.pollFirst()); deque.add(o1); deque.add(o2); assertEquals(o1, deque.pollFirst()); checkDequeSizeAndContent(deque, o2); assertEquals(o2, deque.pollFirst()); assertTrue(deque.isEmpty()); assertNull(deque.pollFirst()); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testPollLast() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertNull(deque.pollLast());/*w w w .j av a2 s. c o m*/ assertTrue(deque.isEmpty()); deque.add(o1); assertEquals(o1, deque.pollLast()); assertTrue(deque.isEmpty()); assertNull(deque.pollFirst()); deque.add(o1); deque.add(o2); assertEquals(o2, deque.pollLast()); checkDequeSizeAndContent(deque, o1); assertEquals(o1, deque.pollLast()); assertTrue(deque.isEmpty()); assertNull(deque.pollLast()); }