@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 testPoll() { int num = 10; assertNull(list.poll()); assertNull(list.poll()); assertNull(list.poll()); for (int i = 0; i < num; i++) { list.addTail(i); } for (int i = 0; i < num; i++) { assertEquals(i, list.poll().intValue()); } assertNull(list.poll()); assertNull(list.poll()); assertNull(list.poll()); for (int i = num; i < num * 2; i++) { list.addHead(i); } for (int i = num * 2 - 1; i >= num; i--) { assertEquals(i, list.poll().intValue()); } assertNull(list.poll()); assertNull(list.poll()); assertNull(list.poll()); }
@Test public void testAddHeadAndTail() { int num = 10; for (int i = 0; i < num; i++) { list.addHead(i); } for (int i = num; i < num * 2; i++) { list.addTail(i); } for (int i = num * 2; i < num * 3; i++) { list.addHead(i); } for (int i = num * 3; i < num * 4; i++) { list.addTail(i); } for (int i = num * 3 - 1; i >= num * 2; i--) { assertEquals(i, list.poll().intValue()); } for (int i = num - 1; i >= 0; i--) { assertEquals(i, list.poll().intValue()); } for (int i = num; i < num * 2; i++) { assertEquals(i, list.poll().intValue()); } for (int i = num * 3; i < num * 4; i++) { assertEquals(i, list.poll().intValue()); } }
@Test public void testAddTail() { int num = 10; assertEquals(0, list.size()); for (int i = 0; i < num; i++) { list.addTail(i); assertEquals(i + 1, list.size()); } for (int i = 0; i < num; i++) { assertEquals(i, list.poll().intValue()); assertEquals(num - i - 1, list.size()); } }
@Test public void testAddHead() { int num = 10; assertEquals(0, list.size()); for (int i = 0; i < num; i++) { list.addHead(i); assertEquals(i + 1, list.size()); } for (int i = num - 1; i >= 0; i--) { assertEquals(i, list.poll().intValue()); assertEquals(i, list.size()); } }