List of usage examples for java.util ArrayDeque removeFirst
public E removeFirst()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);//from w w w . ja v a2 s.co m deque.add(2); deque.add(25); deque.add(40); // this will remove element at the first(head) postion int retval = deque.removeFirst(); System.out.println("Element removed is: " + retval); System.out.println(deque); }
From source file:org.carrot2.source.microsoft.v5.Bing5NewsDocumentSource.java
@Override protected void handleResponse(BingResponse response, SearchEngineResponse ser) { NewsResponse newsResponse = (NewsResponse) response; ser.metadata.put(SearchEngineResponse.RESULTS_TOTAL_KEY, newsResponse.totalEstimatedMatches); if (newsResponse.value != null) { ArrayDeque<NewsResponse.NewsArticle> articles = new ArrayDeque<>(newsResponse.value); while (!articles.isEmpty()) { NewsResponse.NewsArticle r = articles.removeFirst(); if (r.clusteredArticles != null) { articles.addAll(r.clusteredArticles); }// w ww . j a v a 2 s .co m Document doc = new Document(r.name, r.description, r.url); if (r.image != null && r.image.thumbnail != null) { doc.setField(Document.THUMBNAIL_URL, r.image.thumbnail.contentUrl); } if (r.provider != null) { ArrayList<String> sources = new ArrayList<>(); for (NewsResponse.NewsArticle.Organization o : r.provider) { sources.add(o.name); } doc.setField(Document.SOURCES, sources); } ser.results.add(doc); } } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveFirst() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {/* w w w .ja v a2 s .com*/ deque.removeFirst(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.removeFirst()); assertTrue(deque.isEmpty()); deque.add(o1); deque.add(o2); assertEquals(o1, deque.removeFirst()); checkDequeSizeAndContent(deque, o2); assertEquals(o2, deque.removeFirst()); assertTrue(deque.isEmpty()); try { deque.removeFirst(); fail(); } catch (NoSuchElementException expected) { } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRolloverInvariants() { ArrayDeque<Integer> deque = new ArrayDeque<>(); assertTrue(deque.add(1));// w w w . j a v a 2s . c o 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.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.j a va 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 testFailFastDescendingIterator() { ArrayDeque<Object> deque = new ArrayDeque<>(asList(getFullNonNullElements())); Iterator<Object> it = deque.descendingIterator(); it.next();// w ww .j a v a2 s .c o m deque.removeLast(); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.removeFirst(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); deque.clear(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); deque.addLast(new Object()); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.addFirst(new Object()); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); it.next(); deque.removeLast(); try { it.remove(); } catch (ConcurrentModificationException e) { fail(); } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); it.next(); deque.removeLast(); deque.removeLast(); try { it.remove(); fail(); } catch (ConcurrentModificationException expected) { } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemove() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {// www . j a va2 s.c o m deque.remove(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.remove()); assertTrue(deque.isEmpty()); deque.add(o1); deque.add(o2); assertEquals(o1, deque.remove()); checkDequeSizeAndContent(deque, o2); assertEquals(o2, deque.removeFirst()); assertTrue(deque.isEmpty()); try { deque.remove(); fail(); } catch (NoSuchElementException expected) { } }