@Override public void clear() { for (int i = 0; i < NUMBER_OF_BUCKETS; i++) { this.buckets[i].clear(); } size = 0; }
/** * Adds all elements of this list to the given {@link DoubleLinkedList}. After this operation this list will not contain any elements. * * @param newList * The list to append all the elements of this list. */ public void mergeInto(DoubleLinkedList<T> newList) { newList.head.prev.next = this.head.next; this.head.next.prev = newList.head.prev; this.head.prev.next = newList.head; newList.head.prev = this.head.prev; newList.size += size; clear(); }
@Test public void testPushFrontAndPopFrontWithClear() { for (int i = 0; i < TEST_NUMBERS; i++) { list.pushFront(new DoubleLinkedIntListItem(i)); } assertEquals(TEST_NUMBERS, list.size()); list.clear(); assertEquals(0, list.size()); testPushFrontAndPopFront(); }
@Test public void testPushEndAndPopFrontWithClear() { for (int i = 0; i < TEST_NUMBERS; i++) { list.pushEnd(new DoubleLinkedIntListItem(i)); } assertEquals(TEST_NUMBERS, list.size()); list.clear(); assertEquals(0, list.size()); testPushEndAndPopFront(); }