List.java

Download
1/*2 * List.java3 * 4 * Computer Science S-22, Harvard University5 */6 7/*8 * An interface that defines a simple ADT for a list of objects of any9 * type.10 *11 * Methods that take an index i throw an IndexOutOfBoundsException12 * if i is less than 0 or greater than or equal to the length of the list.13 */14public interface List {15    /* returns the item at position i in the list */16    Object getItem(int i);17 18    /* 19     * adds the specified item at position i in the list, shifting the20     * items that are currently in positions i, i+1, i+2, etc. to the21     * right by one.  Returns false if the list is full, and true22     * otherwise.23     */24    boolean addItem(Object item, int i);25 26    /* 27     * removes the item at position i in the list, shifting the items28     * that are currently in positions i+1, i+2, etc. to the left by29     * one.  Returns a reference to the removed object.30     */31    Object removeItem(int i);32 33    /* returns the number of items in the list */34    int length();35 36    /* returns true if the list is full, and false otherwise */37    boolean isFull();38 39    /* returns an iterator object for this list. */40    ListIterator iterator();41}