import java.util.ArrayList;

/**
 * Sorted list of arbitrary comparable objects.
 *
 * @author Drue Coles
 */
public class SortedList {

    private final ArrayList<Comparable> list;

    /**
     * Creates an empty list.
     */
    public SortedList() {
        list = new ArrayList<>();
    }

    /**
     * Returns the size of this list.
     */
    public int size() {
        return list.size();
    }

    /**
     * Returns the item at a given position of the list.
     */
    public Comparable get(int i) {
        return list.get(i);
    }

    /**
     * Adds an item to the list at its correct position in sorted order.
     */
    public void add(Comparable itemToAdd) {
        int i = 0;
        while (i < size()) {
            Comparable listItem = get(i);
            if (itemToAdd.compareTo(listItem) <= 0) { // late binding 
                break;
            }
            i++;
        }
        list.add(i, itemToAdd);
    }
}