structure
Interface List<ELTTYPE>

All Superinterfaces:
java.lang.Iterable<ELTTYPE>, Structure<ELTTYPE>
All Known Implementing Classes:
AbstractList, CircularList, DoublyLinkedList, SinglyLinkedList, Vector

public interface List<ELTTYPE>
extends Structure<ELTTYPE>

Interface describing lists. Lists are collections of data with a head and tail. Values may be added or removed from either end, as well as by value from the middle. The structure package provides several implementations of the List interface, 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)
 {
     List 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:
SinglyLinkedList, DoublyLinkedList, CircularList

Method Summary
 void add(ELTTYPE value)
          Add an object to tail of list.
 void add(int i, ELTTYPE o)
          Insert value at location.
 void addFirst(ELTTYPE value)
          Add a value to the head of the list.
 void addLast(ELTTYPE value)
          Add a value to tail of list.
 void clear()
          Remove all elements of list.
 boolean contains(ELTTYPE value)
          Check to see if a value is in list.
 ELTTYPE get()
          Retrieves value from tail of list.
 ELTTYPE get(int i)
          Get value at location i.
 ELTTYPE getFirst()
          Fetch first element of list.
 ELTTYPE getLast()
          Fetch last element of list.
 int indexOf(ELTTYPE value)
          Determine first location of a value in list.
 boolean isEmpty()
          Determine if list is empty.
 java.util.Iterator<ELTTYPE> iterator()
          Construct an iterator to traverse elements of list from head to tail, in order.
 int lastIndexOf(ELTTYPE value)
          Determine last location of a value in list.
 ELTTYPE remove()
          Removes value from tail of list.
 ELTTYPE remove(ELTTYPE value)
          Remove a value from list.
 ELTTYPE remove(int i)
          Remove and return value at location i.
 ELTTYPE removeFirst()
          Remove a value from first element of list.
 ELTTYPE removeLast()
          Remove last value from list.
 ELTTYPE set(int i, ELTTYPE o)
          Set value stored at location i to object o, returning old value.
 int size()
          Determine size of list.
 
Methods inherited from interface structure.Structure
elements, values
 

Method Detail

size

int size()
Determine size of list.

Specified by:
size in interface Structure<ELTTYPE>
Returns:
The number of elements in list.
Post:
returns number of elements in list

isEmpty

boolean isEmpty()
Determine if list is empty.

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

clear

void clear()
Remove all elements of list.

Specified by:
clear in interface Structure<ELTTYPE>
Post:
empties list

addFirst

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

Parameters:
value - The value to be added to the head of the list.
Post:
value is added to beginning of list

addLast

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

Parameters:
value - The value to be added to tail of list.
Post:
value is added to end of list

getFirst

ELTTYPE getFirst()
Fetch first element of list.

Returns:
A reference to first element of list.
Pre:
list is not empty
Post:
returns first value in list

getLast

ELTTYPE getLast()
Fetch last element of list.

Returns:
A reference to last element of list.
Pre:
list is not empty
Post:
returns last value in list

removeFirst

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

Returns:
The value actually removed.
Pre:
list is not empty
Post:
removes first value from list

removeLast

ELTTYPE removeLast()
Remove last value from list.

Returns:
The value actually removed.
Pre:
list is not empty
Post:
removes last value from list

remove

ELTTYPE remove(ELTTYPE value)
Remove a value from list. At most one of value will be removed.

Specified by:
remove in interface Structure<ELTTYPE>
Parameters:
value - The value to be removed.
Returns:
The actual value removed.
Post:
removes and returns element equal to value otherwise returns null

add

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

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

ELTTYPE remove()
Removes value from tail of list.

Returns:
object removed.
Pre:
list has at least one element
Post:
removes last value found in list

get

ELTTYPE get()
Retrieves value from tail of list.

Returns:
object found at end of list
Pre:
list has at least one element
Post:
returns last value found in list

contains

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

Specified by:
contains in interface Structure<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

indexOf

int indexOf(ELTTYPE value)
Determine first location of a value in list.

Parameters:
value - The value sought.
Returns:
index (0 is first element) of value, or -1
Pre:
value is not null
Post:
returns (0-origin) index of value, or -1 if value is not found

lastIndexOf

int lastIndexOf(ELTTYPE value)
Determine last location of a value in list.

Parameters:
value - value sought.
Returns:
index (0 is first element) of value, or -1
Pre:
value is not null
Post:
returns (0-origin) index of value, or -1 if value is not found

get

ELTTYPE get(int i)
Get value at location i.

Parameters:
i - position of value to be retrieved.
Returns:
value retrieved from location i (returns null if i invalid)
Pre:
0 <= i < size()
Post:
returns object found at that location

set

ELTTYPE set(int i,
            ELTTYPE o)
Set value stored at location i to object o, returning old value.

Parameters:
i - location of entry to be changed.
o - new value
Returns:
former value of ith entry of list.
Pre:
0 <= i < size()
Post:
sets ith entry of list to value o; returns old value

add

void add(int i,
         ELTTYPE o)
Insert value at location.

Parameters:
i - index of this new value
o - value to be stored
Pre:
0 <= i <= size()
Post:
adds ith entry of list to value o

remove

ELTTYPE remove(int i)
Remove and return value at location i.

Parameters:
i - position of value to be retrieved.
Returns:
value retrieved from location i (returns null if i invalid)
Pre:
0 <= i < size()
Post:
removes and returns object found at that location

iterator

java.util.Iterator<ELTTYPE> iterator()
Construct an iterator to traverse elements of list from head to tail, in order.

Specified by:
iterator in interface java.lang.Iterable<ELTTYPE>
Specified by:
iterator in interface Structure<ELTTYPE>
Returns:
Iterator that traverses list.
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()
Post:
returns an iterator allowing ordered traversal of elements in list