structure5
Class AbstractList<E>

java.lang.Object
  extended by structure5.AbstractStructure<E>
      extended by structure5.AbstractList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, List<E>, Structure<E>
Direct Known Subclasses:
CircularList, DoublyLinkedList, SinglyLinkedList, Vector

public abstract class AbstractList<E>
extends AbstractStructure<E>
implements List<E>

An abstract structure implementing features common to all list-like structures in this package.

Lists are typically used to store data of unknown or varying length. The structure package provides several extensions of the AbstractList class, each of which has its particular strengths and weaknesses.

Example usage: To place a copy of every unique parameter passed to a program into a List, we could use the following:

 public static void main(String[] arguments)
 {
     AbstractList argList = new SinglyLinkedList();
     for (int i = 0; i < arguments.length; i++){
         if (!argList.contains(arguments[i])){
             argList.add(arguments[i]);
         }
    }
    System.out.println(argList);
 }
 

See Also:
DoublyLinkedList, CircularList, SinglyLinkedList

Constructor Summary
AbstractList()
          Default constructor for AbstractLists
 
Method Summary
 void add(E value)
          Add an object to tail of list.
 void addFirst(E value)
          Add a value to head of list.
 void addLast(E value)
          Add a value to tail of list.
 boolean contains(E value)
          Check to see if a value is in list.
 E get()
          Retrieves value from tail of list.
 E getFirst()
          Fetch first element of list.
 E getLast()
          Fetch last element of list.
 boolean isEmpty()
          Determine if list is empty.
 E remove()
          Removes value from tail of list.
 E removeFirst()
          Remove a value from first element of list.
 E removeLast()
          Remove last value from list.
 
Methods inherited from class structure5.AbstractStructure
elements, hashCode, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface structure5.List
add, clear, get, indexOf, iterator, lastIndexOf, remove, remove, set, size
 
Methods inherited from interface structure5.Structure
elements, values
 

Constructor Detail

AbstractList

public AbstractList()
Default constructor for AbstractLists

Postcondition:
does nothing
Method Detail

isEmpty

public boolean isEmpty()
Determine if list is empty.

Specified by:
isEmpty in interface List<E>
Specified by:
isEmpty in interface Structure<E>
Overrides:
isEmpty in class AbstractStructure<E>
Returns:
True if list has no elements.
Postcondition:
returns true iff list has no elements

addFirst

public void addFirst(E value)
Add a value to head of list.

Specified by:
addFirst in interface List<E>
Parameters:
value - The value to be added to head of list.
Postcondition:
value is added to beginning of list

addLast

public void addLast(E value)
Add a value to tail of list.

Specified by:
addLast in interface List<E>
Parameters:
value - The value to be added to tail of list.
Postcondition:
value is added to end of list

getFirst

public E getFirst()
Fetch first element of list.

Specified by:
getFirst in interface List<E>
Returns:
A reference to first element of list.
Precondition:
list is not empty
Postcondition:
returns first value in list

getLast

public E getLast()
Fetch last element of list.

Specified by:
getLast in interface List<E>
Returns:
A reference to last element of list.
Precondition:
list is not empty
Postcondition:
returns last value in list

removeFirst

public E removeFirst()
Remove a value from first element of list.

Specified by:
removeFirst in interface List<E>
Returns:
value actually removed.
Precondition:
list is not empty
Postcondition:
removes first value from list

removeLast

public E removeLast()
Remove last value from list.

Specified by:
removeLast in interface List<E>
Returns:
value actually removed.
Precondition:
list is not empty
Postcondition:
removes last value from list

add

public void add(E value)
Add an object to tail of list.

Specified by:
add in interface List<E>
Specified by:
add in interface Structure<E>
Parameters:
value - The value to be added to tail of list.
See Also:
addLast(E)
Postcondition:
value is added to tail of list

remove

public E remove()
Removes value from tail of list.

Specified by:
remove in interface List<E>
Returns:
object removed.
Precondition:
list has at least one element
Postcondition:
removes last value found in list

get

public E get()
Retrieves value from tail of list.

Specified by:
get in interface List<E>
Returns:
object found at end of list
Precondition:
list has at least one element
Postcondition:
returns last value found in list

contains

public boolean contains(E value)
Check to see if a value is in list.

Specified by:
contains in interface List<E>
Specified by:
contains in interface Structure<E>
Overrides:
contains in class AbstractStructure<E>
Parameters:
value - value sought.
Returns:
True if value is within list.
Precondition:
value is not null
Postcondition:
returns true iff list contains an object equal to value