List of usage examples for java.util ArrayDeque isEmpty
public boolean isEmpty()
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveElement() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertFalse(deque.remove(o1));/*from ww w . ja v a 2s .c o m*/ deque.add(o1); assertTrue(deque.remove(o1)); assertTrue(deque.isEmpty()); deque.add(o1); deque.add(o2); assertTrue(deque.remove(o1)); checkDequeSizeAndContent(deque, o2); assertTrue(deque.remove(o2)); assertTrue(deque.isEmpty()); assertFalse(deque.remove(null)); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveLastOccurrence() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertFalse(deque.removeLastOccurrence(o1)); deque.add(o1);/*w ww . jav a2 s . c om*/ assertTrue(deque.removeLastOccurrence(o1)); assertTrue(deque.isEmpty()); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); assertTrue(deque.removeLastOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); deque.add(o1); deque.add(o2); deque.add(o3); assertTrue(deque.removeLastOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o2, o3, o1, o3); assertTrue(deque.removeLastOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3, o1, o3); assertTrue(deque.removeLastOccurrence(o3)); checkDequeSizeAndContent(deque, o1, o3, o1); assertTrue(deque.removeLastOccurrence(o3)); checkDequeSizeAndContent(deque, o1, o1); assertFalse(deque.removeLastOccurrence(o3)); assertFalse(deque.removeLastOccurrence(null)); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveFirstOccurrence() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertFalse(deque.removeFirstOccurrence(o1)); deque.add(o1);/* w ww .ja va 2s . com*/ assertTrue(deque.removeFirstOccurrence(o1)); assertTrue(deque.isEmpty()); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); assertTrue(deque.removeFirstOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); deque.add(o1); deque.add(o2); deque.add(o3); assertTrue(deque.removeFirstOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3, o1, o2, o3); assertTrue(deque.removeFirstOccurrence(o2)); checkDequeSizeAndContent(deque, o1, o3, o1, o3); assertTrue(deque.removeFirstOccurrence(o1)); checkDequeSizeAndContent(deque, o3, o1, o3); assertTrue(deque.removeFirstOccurrence(o1)); checkDequeSizeAndContent(deque, o3, o3); assertFalse(deque.removeFirstOccurrence(o1)); assertFalse(deque.removeFirstOccurrence(null)); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testPop() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {/*from w w w . jav a 2 s .c o m*/ deque.pop(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.pop()); assertTrue(deque.isEmpty()); deque.add(o1); deque.add(o2); assertEquals(o1, deque.pop()); checkDequeSizeAndContent(deque, o2); assertEquals(o2, deque.pop()); assertTrue(deque.isEmpty()); try { deque.pop(); fail(); } catch (NoSuchElementException 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 {/*from w w w.j ava2 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) { } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveLast() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {/*from w ww . java 2 s . c o m*/ deque.removeLast(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.removeLast()); assertTrue(deque.isEmpty()); deque.add(o1); deque.add(o2); assertEquals(o2, deque.removeLast()); checkDequeSizeAndContent(deque, o1); assertEquals(o1, deque.removeLast()); assertEquals(0, deque.size()); try { deque.removeLast(); fail(); } catch (NoSuchElementException expected) { } }
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 {/*from ww w .j a v a 2 s . c o m*/ 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));/*from w ww . ja 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 testElement() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {// w w w . j a v a2 s . c om deque.element(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.element()); checkDequeSizeAndContent(deque, o1); deque.add(o2); assertEquals(o1, deque.element()); checkDequeSizeAndContent(deque, o1, o2); deque.clear(); assertTrue(deque.isEmpty()); try { deque.element(); fail(); } catch (NoSuchElementException expected) { } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testGetLast() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {/* w w w . j a v a 2 s .c o m*/ deque.getLast(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.getLast()); checkDequeSizeAndContent(deque, o1); deque.add(o2); assertEquals(o2, deque.getLast()); checkDequeSizeAndContent(deque, o1, o2); deque.clear(); assertTrue(deque.isEmpty()); try { deque.getLast(); fail(); } catch (NoSuchElementException expected) { } }