/** * Puts the linked list back into its initial state. Elements are saved for later use. */ public void reset() { Element e = first; while( e != null ) { Element n = e.next; e.clear(); available.add( e ); e = n; } first = last = null; size = 0; }
/** * Puts the linked list back into its initial state. Elements are saved for later use. */ public void reset() { Element e = first; while( e != null ) { Element n = e.next; e.clear(); available.add( e ); e = n; } first = last = null; size = 0; }
/** * Removes the element from the list and saves the element data structure for later reuse. * @param element The item which is to be removed from the list */ public void remove( Element<T> element ) { if( element.next == null ) { last = element.previous; } else { element.next.previous = element.previous; } if( element.previous == null ) { first = element.next; } else { element.previous.next = element.next; } size--; element.clear(); available.push(element); }
/** * Removes the last element from the list * @return The object which was contained in the lsat element */ public Object removeTail() { if( last == null ) throw new IllegalArgumentException("Empty list"); Object ret = last.getObject(); Element<T> e = last; available.add(last); if( last.previous != null ) { last.previous.next = null; last = last.previous; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }
/** * Removes the first element from the list * @return The object which was contained in the first element */ public T removeHead() { if( first == null ) throw new IllegalArgumentException("Empty list"); T ret = first.getObject(); Element<T> e = first; available.push(first); if( first.next != null ) { first.next.previous = null; first = first.next; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }
/** * Removes the element from the list and saves the element data structure for later reuse. * @param element The item which is to be removed from the list */ public void remove( Element<T> element ) { if( element.next == null ) { last = element.previous; } else { element.next.previous = element.previous; } if( element.previous == null ) { first = element.next; } else { element.previous.next = element.next; } size--; element.clear(); available.push(element); }
/** * Removes the first element from the list * @return The object which was contained in the first element */ public T removeHead() { if( first == null ) throw new IllegalArgumentException("Empty list"); T ret = first.getObject(); Element<T> e = first; available.push(first); if( first.next != null ) { first.next.previous = null; first = first.next; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }
/** * Removes the last element from the list * @return The object which was contained in the lsat element */ public Object removeTail() { if( last == null ) throw new IllegalArgumentException("Empty list"); Object ret = last.getObject(); Element<T> e = last; available.add(last); if( last.previous != null ) { last.previous.next = null; last = last.previous; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }