© 1998-2002 McGraw-Hill

structure
Class AbstractList

java.lang.Object
  |
  +--structure.AbstractStructure
        |
        +--structure.AbstractList
All Implemented Interfaces:
List, Structure
Direct Known Subclasses:
CircularList, DoublyLinkedList, SinglyLinkedList, Vector

public abstract class AbstractList
extends AbstractStructure
implements List

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(Object value)
          Add an object to tail of list.
 void addFirst(Object value)
          Add a value to head of list.
 void addLast(Object value)
          Add a value to tail of list.
 boolean contains(Object value)
          Check to see if a value is in list.
 Object get()
          Retrieves value from tail of list.
 Object getFirst()
          Fetch first element of list.
 Object getLast()
          Fetch last element of list.
 boolean isEmpty()
          Determine if list is empty.
 Object remove()
          Removes value from tail of list.
 Object removeFirst()
          Remove a value from first element of list.
 Object removeLast()
          Remove last value from list.
 
Methods inherited from class structure.AbstractStructure
elements, hashCode, values
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, notify, notifyAll, registerNatives, 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
Method Detail

isEmpty

public boolean isEmpty()
Determine if list is empty.
Specified by:
isEmpty in interface List
Overrides:
isEmpty in class AbstractStructure
Postcondition:
returns true iff list has no elements
Returns:
True if list has no elements.

addFirst

public void addFirst(Object value)
Add a value to head of list.
Specified by:
addFirst in interface List
Parameters:
value - The value to be added to head of list.
Postcondition:
value is added to beginning of list

addLast

public void addLast(Object value)
Add a value to tail of list.
Specified by:
addLast in interface List
Parameters:
value - The value to be added to tail of list.
Postcondition:
value is added to end of list

getFirst

public Object getFirst()
Fetch first element of list.
Specified by:
getFirst in interface List
Precondition:
list is not empty
Postcondition:
returns first value in list
Returns:
A reference to first element of list.

getLast

public Object getLast()
Fetch last element of list.
Specified by:
getLast in interface List
Precondition:
list is not empty
Postcondition:
returns last value in list
Returns:
A reference to last element of list.

removeFirst

public Object removeFirst()
Remove a value from first element of list.
Specified by:
removeFirst in interface List
Precondition:
list is not empty
Postcondition:
removes first value from list
Returns:
value actually removed.

removeLast

public Object removeLast()
Remove last value from list.
Specified by:
removeLast in interface List
Precondition:
list is not empty
Postcondition:
removes last value from list
Returns:
value actually removed.

add

public void add(Object value)
Add an object to tail of list.
Specified by:
add in interface List
Parameters:
value - The value to be added to tail of list.
Postcondition:
value is added to tail of list
See Also:
addLast(java.lang.Object)

remove

public Object remove()
Removes value from tail of list.
Specified by:
remove in interface List
Precondition:
list has at least one element
Postcondition:
removes last value found in list
Returns:
object removed.

get

public Object get()
Retrieves value from tail of list.
Specified by:
get in interface List
Precondition:
list has at least one element
Postcondition:
returns last value found in list
Returns:
object found at end of list

contains

public boolean contains(Object value)
Check to see if a value is in list.
Specified by:
contains in interface List
Overrides:
contains in class AbstractStructure
Parameters:
value - value sought.
Precondition:
value is not null
Postcondition:
returns true iff list contains an object equal to value
Returns:
True if value is within list.

© 1998-2002 McGraw-Hill