@Test public void testRemoveLast() { this.list.add( this.node1 ); this.list.add( this.node2 ); this.list.add( this.node3 ); assertSame( "List should return node1 on getLast()", this.list.getLast(), this.node3 ); this.list.removeLast(); assertSame( "List should return node2 on getLast()", this.list.getLast(), this.node2 ); this.list.removeLast(); assertSame( "List should return node3 on getLast()", this.list.getLast(), this.node1 ); this.list.removeLast(); assertNull( "Empty list should return null on getLast()", this.list.getLast() ); }
/** * Removes a <code>LinkedListNode</code> from the list. This works by attach the previous reference to the child reference. * When the node to be removed is the first node it calls <code>removeFirst()</code>. When the node to be removed is the last node * it calls <code>removeLast()</code>. * * @param node * The <code>LinkedListNode</code> to be removed. */ public void remove(final T node) { if ( this.firstNode == node ) { removeFirst(); } else if ( this.lastNode == node ) { removeLast(); } else { node.getPrevious().setNext( node.getNext() ); (node.getNext()).setPrevious( node.getPrevious() ); this.size--; node.setPrevious( null ); node.setNext( null ); } }