public boolean add(Object value) { addLast(value); return true; }
public boolean addFirst(Object o) { addNodeAfter(header, o); return true; }
public void add(int index, Object value) { Node node = getNode(index, true); addNodeBefore(node, value); }
/** * Creates a new node with the specified object as its * <code>value</code> and inserts it before <code>node</code>. * <p> * This implementation uses {@link #createNode(Object)} and * {@link #addNode(AbstractLinkedList.Node,AbstractLinkedList.Node)}. * * @param node node to insert before * @param value value of the newly added node * @throws NullPointerException if <code>node</code> is null */ protected void addNodeBefore(Node node, Object value) { Node newNode = createNode(value); addNode(newNode, node); }
if (isAddSupported() == false) { try { list.addFirst(null); } catch (UnsupportedOperationException ex) {} list.addFirst("value1"); list.addNodeAfter(list.getNode(0,false),"value2"); assertEquals("value1", list.getFirst()); assertEquals("value2", list.getLast()); list.removeFirst(); checkNodes(); list.addNodeAfter(list.getNode(0,false),"value3"); checkNodes(); assertEquals("value2", list.getFirst()); assertEquals("value3", list.getLast()); list.addNodeAfter(list.getNode(0, false),"value4"); checkNodes(); assertEquals("value2", list.getFirst()); assertEquals("value3", list.getLast()); assertEquals("value4", list.get(1)); list.addNodeAfter(list.getNode(2, false), "value5"); checkNodes(); assertEquals("value2", list.getFirst()); assertEquals("value4", list.get(1)); assertEquals("value3", list.get(2)); assertEquals("value5", list.getLast());
public void testRemoveNode() { resetEmpty(); if (isAddSupported() == false || isRemoveSupported() == false) return; AbstractLinkedList list = (AbstractLinkedList) collection; list.addAll( Arrays.asList( new String[]{"value1", "value2"})); list.removeNode(list.getNode(0, false)); checkNodes(); assertEquals("value2", list.getFirst()); assertEquals("value2", list.getLast()); list.addFirst("value1"); list.addFirst("value0"); checkNodes(); list.removeNode(list.getNode(1, false)); assertEquals("value0", list.getFirst()); assertEquals("value2", list.getLast()); checkNodes(); list.removeNode(list.getNode(1, false)); assertEquals("value0", list.getFirst()); assertEquals("value0", list.getLast()); checkNodes(); }
/** * Deserializes the data held in this object to the stream specified. * <p> * The first serializable subclass must call this method from * <code>readObject</code>. */ protected void doReadObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException { init(); int size = inputStream.readInt(); for (int i = 0; i < size; i++) { add(inputStream.readObject()); } }
AbstractLinkedList list = (AbstractLinkedList) collection; assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next); try { Object obj = list.getNode(0, false); fail("Expecting IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException ex) { list.addAll( Arrays.asList( new String[]{"value1", "value2"})); checkNodes(); list.addFirst("value0"); checkNodes(); list.removeNode(list.getNode(1, false)); checkNodes(); try { Object obj = list.getNode(2, false); fail("Expecting IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException ex) { Object obj = list.getNode(-1, false); fail("Expecting IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException ex) { Object obj = list.getNode(3, true); fail("Expecting IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException ex) {
/** * 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); }
public Object remove(int index) { Node node = getNode(index, false); Object oldValue = node.getValue(); removeNode(node); return oldValue; }
public void testRemoveFirst() { resetEmpty(); AbstractLinkedList list = (AbstractLinkedList) collection; if (isRemoveSupported() == false) { try { list.removeFirst(); } catch (UnsupportedOperationException ex) {} } list.addAll( Arrays.asList( new String[]{"value1", "value2"})); assertEquals( "value1", list.removeFirst() ); checkNodes(); list.addLast( "value3"); checkNodes(); assertEquals( "value2", list.removeFirst() ); assertEquals( "value3", list.removeFirst() ); checkNodes(); list.addLast( "value4" ); checkNodes(); assertEquals( "value4", list.removeFirst() ); checkNodes(); }
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 set(int index, Object value) { Node node = getNode(index, false); Object oldValue = node.getValue(); updateNode(node, value); return oldValue; }
public Object get(int index) { rangeCheck(index, size); checkModCount(); return parent.get(index + offset); }
public boolean containsAll(Collection coll) { Iterator it = coll.iterator(); while (it.hasNext()) { if (contains(it.next()) == false) { return false; } } return true; }
/** * 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(int index, Object obj) { rangeCheck(index, size + 1); checkModCount(); parent.add(index + offset, obj); expectedModCount = parent.modCount; size++; LinkedSubList.this.modCount++; }
/** * Create a ListIterator for a list. * * @param parent the parent list * @param fromIndex the index to start at */ protected LinkedListIterator(AbstractLinkedList parent, int fromIndex) throws IndexOutOfBoundsException { super(); this.parent = parent; this.expectedModCount = parent.modCount; this.next = parent.getNode(fromIndex, true); this.nextIndex = fromIndex; }
public boolean addLast(Object o) { addNodeBefore(header, o); return true; }