// CSE 143, Winter 2011, Marty Stepp // This class captures common code shared by both the ArrayList and LinkedList. // An abstract class is a good way to provide a partially implemented class, or // a partial implementation of an interface. Notice that the header of this // class claims to implement the List interface, but the file doesn't // write all of the methods. Java allows this file to compile because it knows // the abstract class must be extended to complete it. If a subclass of // AbstractList doesn't implement all the rest of the List // interface's methods, that subclass will not compile. public abstract class AbstractList implements List { // Adds the given value to the end of the list. // If necessary, resizes the array to fit the value. public void add(E value) { // just call the other add method (to remove redundancy) add(size(), value); } // Returns true if the given value is found in this list. public boolean contains(E value) { return indexOf(value) >= 0; } // Returns true if the list does not contain any elements. public boolean isEmpty() { return size() == 0; // "boolean zen" } }