List of usage examples for java.util ArrayDeque iterator
public Iterator<E> iterator()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);/*from ww w . j a v a 2 s. c o m*/ deque.add(4); deque.add(25); deque.add(1); for (Iterator itr = deque.iterator(); itr.hasNext();) { System.out.println(itr.next()); } }
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);// www . j av a 2s . c om deque.add(4); deque.add(25); deque.add(1); //iterator() is used to print all the elements //next() returns the next element on each iteration System.out.println("printing elements using iterator:"); for (Iterator itr = deque.iterator(); itr.hasNext();) { System.out.println(itr.next()); } //descendingIterator() is used to print the elements in reverse order //next() returns the next element on each iteration System.out.println("printing elements in reverse order:"); for (Iterator descItr = deque.descendingIterator(); descItr.hasNext();) { System.out.println(descItr.next()); } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testFailFastIterator() { ArrayDeque<Object> deque = new ArrayDeque<>(asList(getFullNonNullElements())); Iterator<Object> it = deque.iterator(); it.next();/*from w w w . jav a 2 s.c o m*/ deque.removeFirst(); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.removeLast(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); deque.clear(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); deque.addFirst(new Object()); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.addLast(new Object()); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); it.next(); deque.removeFirst(); try { it.remove(); } catch (ConcurrentModificationException e) { fail(); } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); it.next(); deque.removeFirst(); deque.removeFirst(); try { it.remove(); fail(); } catch (ConcurrentModificationException expected) { } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRolloverInvariants() { ArrayDeque<Integer> deque = new ArrayDeque<>(); assertTrue(deque.add(1));//from ww w .j ava2 s . co m assertEquals(1, (int) deque.removeFirst()); for (int i = 0; i < 100; i++) { assertTrue(deque.add(i)); } assertNotNull(deque.peek()); assertFalse(deque.isEmpty()); Iterator<Integer> it = deque.iterator(); for (int i = 0; i < 100; i++) { assertTrue(it.hasNext()); assertEquals(i, (int) it.next()); it.remove(); } assertFalse(it.hasNext()); assertNull(deque.peek()); assertTrue(deque.isEmpty()); }
From source file:com.espertech.esper.epl.core.ResultSetProcessorRowPerGroupRollup.java
public Iterator<EventBean> getIterator(Viewable parent) { if (!prototype.isHistoricalOnly()) { return obtainIterator(parent); }//from www . ja va2s.c om aggregationService.clearResults(agentInstanceContext); Iterator<EventBean> it = parent.iterator(); EventBean[] eventsPerStream = new EventBean[1]; Object[] groupKeys = new Object[prototype.getGroupByRollupDesc().getLevels().length]; AggregationGroupByRollupLevel[] levels = prototype.getGroupByRollupDesc().getLevels(); for (; it.hasNext();) { eventsPerStream[0] = it.next(); Object groupKeyComplete = generateGroupKey(eventsPerStream, true); for (int j = 0; j < levels.length; j++) { Object subkey = levels[j].computeSubkey(groupKeyComplete); groupKeys[j] = subkey; } aggregationService.applyEnter(eventsPerStream, groupKeys, agentInstanceContext); } ArrayDeque<EventBean> deque = ResultSetProcessorUtil.iteratorToDeque(obtainIterator(parent)); aggregationService.clearResults(agentInstanceContext); return deque.iterator(); }