@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Override public T poll() { T t = null; // We are just using a simple prioritization algorithm: // Highest priority refs always get returned first. // This could cause starvation of lower priority refs. // TODO - A better prioritization algorithm for (int i = highestPriority; i >= 0; i--) { LinkedListImpl<T> ll = levels[i]; if (ll.size() != 0) { t = ll.poll(); if (t != null) { exclusiveIncrementSize(-1); if (ll.size() == 0) { if (highestPriority == i) { highestPriority--; } } } break; } } return t; }
@Test public void testRemoveHeadAndTail2() { LinkedListIterator<Integer> iter = list.iterator(); int num = 10; for (int i = 0; i < num; i++) { list.addHead(i); assertEquals(1, list.size()); assertTrue(iter.hasNext()); assertEquals(i, iter.next().intValue()); iter.remove(); } }
@Test public void testRemoveHeadAndTail3() { LinkedListIterator<Integer> iter = list.iterator(); int num = 10; for (int i = 0; i < num; i++) { if (i % 2 == 0) { list.addHead(i); } else { list.addTail(i); } assertEquals(1, list.size()); assertTrue(iter.hasNext()); assertEquals(i, iter.next().intValue()); iter.remove(); } }
@Test public void testRemoveInTurn() { LinkedListIterator<Integer> iter = list.iterator(); int num = 10; for (int i = 0; i < num; i++) { list.addTail(i); } for (int i = 0; i < num; i++) { assertTrue(iter.hasNext()); assertEquals(i, iter.next().intValue()); iter.remove(); } assertFalse(iter.hasNext()); assertEquals(0, list.size()); }
@Test public void testRemoveAll() { int num = 10; LinkedListIterator<Integer> iter = list.iterator(); try { iter.remove(); fail("Should throw NoSuchElementException"); } catch (NoSuchElementException e) { // OK } for (int i = 0; i < num; i++) { list.addTail(i); } assertEquals(num, list.size()); try { iter.remove(); fail("Should throw NoSuchElementException"); } catch (NoSuchElementException e) { // OK } for (int i = 0; i < num; i++) { assertTrue(iter.hasNext()); assertEquals(i, iter.next().intValue()); iter.remove(); assertEquals(num - i - 1, list.size()); } assertFalse(iter.hasNext()); }
size--; assertEquals(list.size(), size);