// File:  ADTList\List.java

/**
 * Realization of a List ADT
 * 
 * @author Bary W Pollack
 * @version Dec. 31, 2000 - 23:00 PST
 */

// This file implements a simple list in a generic manner.

// It does NOT actually store any data -- rather, it provides
// the framework for an actual List implementation using
// arrays, list structures, whatever...

public class List implements ListIfx {

    // Default constructor
    List() { }

    // Creates a fresh list
    public void create() {
        list = null;
    }

    // True if the list is empty
    public boolean isEmpty() throws ListException {
        checkNullList();
        return (size() <= 0);
    }

    // True if the list cannot contain any more Items
    public boolean isFull() throws ListException {
        checkNullList();
        return false;
    }

    // Returns the number of Items in the list
    public int size() throws ListException {
        checkNullList();
        return 0;
    }

    // Adds the Item at location index, moving the rest down
    public void add(int index, Item item) throws ListException {
        checkNullList();
    }

    // Removes the Item at list[index]
    public void remove(int index) throws ListException {
        checkNullList();
        checkIndex(index);
    }

    // Empties the list
    public void removeAll() {
        list = null;
    }

    // Retrieves a copy of the Item at list[index]
    public Item get(int index) throws ListException {
        checkNullList();
        checkIndex(index);
        return null;
    }

    // Displays the list on System.out
    public void display() throws ListException {
        checkNullList();
        System.out.println(list);
    }

    // Returns the String version of the data in the list
    // Assumes that Item has a toString method
    public String toString() {
        String s = "";
        try {
            for (int i = 0; i < size(); i++) {
                if (i > 0)
                    s += ", ";
                s += get(i);
            }
        } catch (ListException e) {
            s = "<null>";
        }
        return s;
    }

    // Checks to ensure that 'list' is not null
    protected void checkNullList() throws ListException {
        if (list == null)
            throw new ListException("list is <null>");
    }

    // Checks to ensure that index is in range
    protected void checkIndex(int index) throws ListException {
        if (index < 0 || index >= size())
            throw new ListException("index out of range (" + index + ")");
    }

    // 'list' is the actual list data
    protected List list;
}
