package freenet.support; import java.util.Enumeration; /** * Framework for managing a doubly linked list. * The purpose of DoublyLinkedList is simply and solely so that * we can override the entries with our own classes. This makes * removal for example extremely fast: O(1) not O(n). * In any other case we can use LinkedList. * @author tavin */ public interface DoublyLinkedList> extends Iterable { // public abstract DoublyLinkedList clone(); /** * List element */ public interface Item> { /** * Get next {@link Item}. May or may not return * null if this is the last Item. * * @see DoublyLinkedList#hasNext() */ T getNext(); /** Set next {@link Item} */ T setNext(Item i); /** * Get previous {@link Item}. May or may not return null * if this is the first Item. * * @see DoublyLinkedList#hasNext() */ T getPrev(); /** Get previous {@link Item} */ T setPrev(Item i); /** Return the contained list. For sanity checking only. */ DoublyLinkedList getParent(); /** Set the contained list. For sanity checking only.*/ DoublyLinkedList setParent(DoublyLinkedList l); } /** Clear this list */ void clear(); /** Return the size of this list */ int size(); /** Check if this list is empty. @return true if this list is empty, false otherwise. */ boolean isEmpty(); /** Get a {@link Enumeration} of {@link DoublyLinkedList.Item}. */ Enumeration elements(); // for consistency w/ typical Java API /** * Returns true if the list contains an item i where i.equals(item) is true. */ public boolean contains(T item); /** * Returns the first item. * @return the item at the head of the list, or null if empty */ T head(); /** * Returns the last item. * @return the item at the tail of the list, or null if empty */ T tail(); /** * Puts the item before the first item. */ void unshift(T i); /** * Removes and returns the first item. */ T shift(); /** * Remove n elements from head and return them as a DoublyLinkedList. */ DoublyLinkedList shift(int n); /** * Puts the item after the last item. */ void push(T i); /** * Removes and returns the last item. */ T pop(); /** * Remove n elements from tail and return them as a DoublyLinkedList. */ DoublyLinkedList pop(int n); /** @return true if i has next item. (ie. not the last item); false otherwise */ boolean hasNext(T i); /** @return true if i has previous item. (ie. not the first item); false otherwise */ boolean hasPrev(T i); /** @return next item of i. If this is the last element, return null */ T next(T i); /** @return previous item of i. If this is the first element, return null */ T prev(T i); /** Remove and return a element * @return this item, or null if the item was not in the list */ T remove(T i); /** * Inserts item j before item i. */ void insertPrev(T i, T j); /** * Inserts item j after item i