Implementing the List ADT
Introduction
In this lab you will write and test two implementations of a List Abstract Data Type (ADT). One implementation will use an array to store the objects, the other will use a linked list.
Getting Started
Update the 132Labs project from the SVN repository. Instructions for updating the labs project can be found under Updating the Labs Project from the SVN Repository in the How-To Document for the course.
Design
The List ADT that you will be implementing is defined in the CS132List interface. That interface defines six operations for all implementations of the List ADT. Each method in the interface contains JavaDoc comments specifying the behavior of the method.
You will be creating two distinctly different implementations of the List ADT. The CS132ArrayList class must be an array-based implementation of the CS132List interface. The CS132LinkedList class must be a linked list based implementation. Below are some notes on the implementation and/or testing of each of these classes.
CS132ArrayList
add or insert method in invoked and the underlying array is full, the size of the array should be doubled to make room for additional elements.
CS132ArrayListTest contains a protected field named myList. The setUp method creates a new CS132ArrayList and sets myList to refer to it. You should use the list referred to by myList in all of your tests. By doing so you will be able to eliminate the need to create any additional tests for the CS132LinkedList class. See the next section for more details.
CS132LinkedList
Because both the CS132ArrayList and CS132LinkedList classes implement the same interface, the functionality of their methods should be identical. That is the add method should have the same effect on the list regardless of whether it is a CS132ArrayList or a CS132LinkedList. Thus, if you have created a rigorous set of tests for your CS132ArrayList class, those same tests should test your CS132LinkedList class equally well.
The CS132LinkedListTest class is already setup to reuse the tests you create in CS132ArrayListTest to test your linked list implementation. To do so, the class CS132LinkedListTest extends the CS132ArrayListTest, thus it inherits all of the test methods that you wrote for the array-based implementation. The CS132LinkedListTest class then overrides the inherited setUp method. The new version of setUp initializes the myList hold a reference to a CS132LinkedList instead of a CS132ArrayList. Thus, when the inherited test methods are executed they will invoke the methods in the linked list implementation instead of the array-based implementation.
The Assignment
Implement and test the CS132ArrayList and CS132LinkedList classes according the the List ADT specified by the CS132List interface.
Submitting your solution
Turn in your solution by committing the 132Labs project to the SVN server. Information about how to turn in your completed project to the SVN server can be found under Turning in the Labs Project to the SVN Repository in the How-To Document for the course.
Bonus Features
Each of the following features may be implemented for extra credit. These features must be implemented in order. All implemented features must be documented using JavaDoc comments. Note that some of these features will require you to learn additional Java on your own.
sublist method to the CS132LinkedList class and test your method. The sublist method must have the signature public CS132List sublist(int start, int end) that returns a new list containing all of the elements from index start up to but not including end. If either start or end are not valid the method must throw an IndexOutOfBoundsException. Your method should operate as efficiently as possible. (+1)
reverse method to the CS132LinkedList class and test your method. The reverse method must have the signature public void reverse(). When reverse is invoked it reverses the order of the elements in the list. Your method should operate as efficiently as possible. (+1)
CS132ArrayList implement the java.lang.Iterable interface. (+2)
To implement this feature you will need to complete the following steps:
CS132ArrayList implement Iterable<Object>.
iterator method to the CS132ArrayList class. The iterator method must return an object that implements the java.util.Iterator interface (see next step).
java.util.Iterator interface.
Iterator returned by your iterator method works.
CS132LinkedList implement the java.lang.Iterable interface. (+2)