public boolean remove(Object value) { for (Node node = header.next; node != header; node = node.next) { if (isEqualValue(node.getValue(), value)) { removeNode(node); return true; } } return false; }
public Object get(int index) { rangeCheck(index, size); checkModCount(); return parent.get(index + offset); }
public Object set(int index, Object obj) { rangeCheck(index, size); checkModCount(); return parent.set(index + offset, obj); }
public void testCursorNextIndexAddBefore() { list.add("1"); list.add("2"); list.add("3"); list.add("5"); CursorableLinkedList.Cursor c1 = list.cursor(); assertEquals(0, c1.nextIndex()); assertEquals("1", c1.next()); list.add(0, "0"); assertEquals(2, c1.nextIndex()); assertEquals("2", c1.next()); }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ public Object get(int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }
public ListIterator listIterator(final int index) { rangeCheck(index, size + 1); checkModCount(); return parent.createSubListListIterator(this, index); }
public Object remove(int index) { rangeCheck(index, size); checkModCount(); Object result = parent.remove(index + offset); expectedModCount = parent.modCount; size--; LinkedSubList.this.modCount++; return result; }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ public ListIterator listIterator(int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator(this, fromIndex); }
public List subList(int fromIndex, int toIndex) { List superSubList = super.subList(fromIndex, toIndex); Set subSet = createSetBasedOnList(set, superSubList); return new SetUniqueList(superSubList, subSet); }
public int indexOf(Object value) { int i = 0; for (Node node = header.next; node != header; node = node.next) { if (isEqualValue(node.getValue(), value)) { return i; } i++; } return -1; }
/** * Removes the specified node from the list. * * @param node the node to remove * @throws NullPointerException if <code>node</code> is null */ protected void removeNode(Node node) { super.removeNode(node); broadcastNodeRemoved(node); }
/** * Removes the node from the list, storing it in the cache for reuse * if the cache is not yet full. * * @param node the node to remove */ protected void removeNode(Node node) { super.removeNode(node); addNodeToCache(node); }
/** * Inserts a new node into the list. * * @param nodeToInsert new node to insert * @param insertBeforeNode node to insert before * @throws NullPointerException if either node is null */ protected void addNode(Node nodeToInsert, Node insertBeforeNode) { super.addNode(nodeToInsert, insertBeforeNode); broadcastNodeInserted(nodeToInsert); }
public void add(Object obj) { checkModCount(); parent.addNodeBefore(next, obj); current = null; nextIndex++; expectedModCount++; }
public void add(Object obj) { checkModCount(); parent.add(nextIndex, obj); current = null; currentIndex = -1; nextIndex++; expectedModCount++; } }
/** * Creates a list iterator for the sublist. * * @param subList the sublist to get an iterator for * @param fromIndex the index to start from, relative to the sublist */ protected ListIterator createSubListListIterator(LinkedSubList subList, int fromIndex) { SubCursor cursor = new SubCursor(subList, fromIndex); registerCursor(cursor); return cursor; }
/** * Verify that base list and sublists are not modifiable */ public void testUnmodifiable() { setupList(); verifyUnmodifiable(list); verifyUnmodifiable(list.subList(0, 2)); }
public void testCursorNextIndexAddAfter() { list.add("1"); list.add("2"); list.add("3"); list.add("5"); CursorableLinkedList.Cursor c1 = list.cursor(); assertEquals(0, c1.nextIndex()); list.add(1, "0"); assertEquals(0, c1.nextIndex()); assertEquals("1", c1.next()); assertEquals(1, c1.nextIndex()); assertEquals("0", c1.next()); }
public int lastIndexOf(Object value) { int i = size - 1; for (Node node = header.previous; node != header; node = node.previous) { if (isEqualValue(node.getValue(), value)) { return i; } i--; } return -1; }
public void testCursorNextIndexFirst() { list.add("1"); list.add("2"); list.add("3"); list.add("5"); CursorableLinkedList.Cursor c1 = list.cursor(); assertEquals(0, c1.nextIndex()); list.remove(0); assertEquals(0, c1.nextIndex()); assertEquals("2", c1.next()); assertEquals(1, c1.nextIndex()); assertEquals("3", c1.next()); }