Interface List12

All Superinterfaces:
java.lang.Iterable

public interface List12
extends java.lang.Iterable

Abstract data type for a dynamically growing list. The Iterator returned by iterator() must support the remove() method.


Method Summary
 void add(java.lang.Object o)
          Equivalent to addToBack.
 void addToBack(java.lang.Object o)
          Adds the specified Object o, which may be null, to the back of the list (i.e., at the tail).
 void addToFront(java.lang.Object o)
          Adds the specified Object o, which may be null, to the front of the list (i.e., at the head).
 void clear()
          Removes all elements from the list.
 boolean contains(java.lang.Object o)
          Returns whether the specified Object o is contained in the list.
 java.lang.Object get(int index)
          Returns the element stored at location index, where index 0 is the element stored at the head of the list and size()-1 is the index of the element at the tail of the list.
 boolean remove(java.lang.Object o)
          Removes the first occurrence (ordered from front to back, i.e., head to tail of the list) of the specified Object o from the list, if it exists.
 java.lang.Object removeBack()
          Removes and returns the element at the back of the list.
 java.lang.Object removeFront()
          Removes and returns the element at the front of the list.
 int size()
          Returns the number of elements (null or otherwise) currently stored in the list.
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

addToFront

void addToFront(java.lang.Object o)
Adds the specified Object o, which may be null, to the front of the list (i.e., at the head).

Parameters:
o - the object to add to the list.

addToBack

void addToBack(java.lang.Object o)
Adds the specified Object o, which may be null, to the back of the list (i.e., at the tail).

Parameters:
o - the object to add to the list.

add

void add(java.lang.Object o)
Equivalent to addToBack.

Parameters:
o - the object to add to the list.

removeFront

java.lang.Object removeFront()
                             throws java.util.NoSuchElementException
Removes and returns the element at the front of the list.

Returns:
the element that was removed from the front of the list.
Throws:
java.util.NoSuchElementException - if the list was empty.

removeBack

java.lang.Object removeBack()
                            throws java.util.NoSuchElementException
Removes and returns the element at the back of the list.

Returns:
the element that was removed from the back of the list.
Throws:
java.util.NoSuchElementException - if the list was empty.

remove

boolean remove(java.lang.Object o)
Removes the first occurrence (ordered from front to back, i.e., head to tail of the list) of the specified Object o from the list, if it exists. o may be null; if it is, then this method removes the first element in the list that is null. Otherwise, this method removes the first element in the list that equals() o (if any such element exists).

Returns:
true if an element was removed, or false otherwise.

clear

void clear()
Removes all elements from the list.


get

java.lang.Object get(int index)
                     throws java.lang.IndexOutOfBoundsException
Returns the element stored at location index, where index 0 is the element stored at the head of the list and size()-1 is the index of the element at the tail of the list.

Parameters:
index - the index of the element to retrieve.
Returns:
the Object at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid.

size

int size()
Returns the number of elements (null or otherwise) currently stored in the list.

Returns:
the number of elements stored in the list.

contains

boolean contains(java.lang.Object o)
Returns whether the specified Object o is contained in the list. o may be null.

Parameters:
o - the object whose presence in the list should be determined.
Returns:
whether o is contained in the list.