Index
Overview


First try coding the class without these suggestions.

Then if and when you get stuck, peruse through the suggestions.

Suggestions


Class must use generics, and specifically use a generic type parameter specified on the class (suggested parameter name of "E")
Class must implement the "DynamicList" interface
See the "Design" sections/pages of the previous chapter on linked list logic. You should minimize the number of ivars you use (only use what is needed), becuse each ivar adds code complexity.

Suggested ivar count: three.

Notes:
  • Remember you want very fast access (great performance) from both ends of the list (e.g., methods first, last, addFirst, addLast)
Implement the interface and all the specified methods
Code a couple easy ones first, e.g.:
  • size
  • isEmpty
This pattern works for throwing runtime exceptions:

if (isEmpty())
	throw new RuntimeException("(first) Attempted to access element in empty list");
You may want to code a helper method, e.g., to check validity of indexes (passed into methods) e.g., a possible name might be "checkIndex" which would return true if the index is valid relative to the lists valid index range
Use helper methods liberally (the name helper method just means any method you code to help you solve the problem, so, e.g., say you are coding "get" and want to check index validity, you may code "checkIndex" as a helper method. You might then call "checkIndex" from other methods, as needed (this is code reuse).
For a class as challenging as the domain model LinkedList it is suggested to write test code as you code the model (in parallel). Put your test code in another package (not the same package as the domain model class). This will help flush out more bugs.
As far as test data, it is okay for some of the tests to use primitive-like objects (integers, strings, ...) but you want to also write tests that use richer objects.

These "richer" object (types) are coder's choice (e.g. possible types are Employee, Person, Animal, Restaurant, etc)

The object type (i.e., the "class") should include equality methods.

Here is an example of a simple class with common methods such as equality methods, accessors (getters and setters), etc.
You will need to design and implement a node class -- the linked list will need it (see logic chapter)
Initially stub in required methods (so the code compiles), e.g.:

public E get(int index) {
	//TODO
	return null;
}
Then start to build up the code, i.e., knock off one "//TODO tag" at a time (and test as you go). Start with methods that can possibly be tested right away (e.g., the simpler methods). E.g., "size", "isEmpty" can immediataly be tested vs an empty list (expecting 0 and true). Then test them for a list of size 1 (expecting 1 and false). Follow that same pattern. E.g., "get" would be a good one to hit next.
"equals" and "hashCode" (handy for testing)
If implementing hashCode, a good algorithm is described in Java's List interface (under "hashCode")
You may (optionally) add a superclass for LinkedList (coder's choice). If so, you should consider also using the superclass for LinkedList.
The method "iterator" is defined as optional in the DynamicList interface. Iterators are handy and fun to code, and can simplify the overall code through use/reuse (of the iterator). See the iterator description for dynamic array for ideas (you will need a different implementation for a linked list iterator)