structure
Class AbstractList<ELTTYPE>

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

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

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(ELTTYPE value)
          Add an object to tail of list.
 void addFirst(ELTTYPE value)
          Add a value to head of list.
 void addLast(ELTTYPE value)
          Add a value to tail of list.
 boolean contains(ELTTYPE value)
          Check to see if a value is in list.
 ELTTYPE get()
          Retrieves value from tail of list.
 ELTTYPE getFirst()
          Fetch first element of list.
 ELTTYPE getLast()
          Fetch last element of list.
 boolean isEmpty()
          Determine if list is empty.
 ELTTYPE remove()
          Removes value from tail of list.
 ELTTYPE removeFirst()
          Remove a value from first element of list.
 ELTTYPE removeLast()
          Remove last value from list.
 
Methods inherited from class structure.AbstractStructure
elements, hashCode, values
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface structure.List
add, clear, get, indexOf, iterator, lastIndexOf, remove, remove, set, size
 
Methods inherited from interface structure.Structure
elements, values
 

Constructor Detail

AbstractList

public AbstractList()
Default constructor for AbstractLists

Post:
does nothing
Method Detail

isEmpty

public boolean isEmpty()
Determine if list is empty.

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

addFirst

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

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

addLast

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

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

getFirst

public ELTTYPE getFirst()
Fetch first element of list.

Specified by:
getFirst in interface List<ELTTYPE>
Returns:
A reference to first element of list.
Pre:
list is not empty
Post:
returns first value in list

getLast

public ELTTYPE getLast()
Fetch last element of list.

Specified by:
getLast in interface List<ELTTYPE>
Returns:
A reference to last element of list.
Pre:
list is not empty
Post:
returns last value in list

removeFirst

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

Specified by:
removeFirst in interface List<ELTTYPE>
Returns:
value actually removed.
Pre:
list is not empty
Post:
removes first value from list

removeLast

public ELTTYPE removeLast()
Remove last value from list.

Specified by:
removeLast in interface List<ELTTYPE>
Returns:
value actually removed.
Pre:
list is not empty
Post:
removes last value from list

add

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

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

remove

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

Specified by:
remove in interface List<ELTTYPE>
Returns:
object removed.
Pre:
list has at least one element
Post:
removes last value found in list

get

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

Specified by:
get in interface List<ELTTYPE>
Returns:
object found at end of list
Pre:
list has at least one element
Post:
returns last value found in list

contains

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

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