Interface List<T>

Type Parameters:
T - The type of data that the list stores.
All Superinterfaces:
java.lang.Iterable<T>
All Known Implementing Classes:
MysteryListImplementation

public interface List<T>
extends java.lang.Iterable<T>

An interface for the List ADT.


Method Summary
 boolean add(int newPosition, T newItem)
          Adds newItem at the given index.
 void add(T newItem)
          Adds newItem to the end of the list.
 T at(int position)
          Returns the item at a given index.
 void clear()
          Removes all items from the list.
 boolean contains(T targetItem)
          Returns true if the list contains the target item.
 boolean isEmpty()
          Returns true if the list has no items stored in it.
 java.util.Iterator<T> iterator()
          Returns an iterator that begins just before index 0 in this list.
 int length()
          Returns the length of the list: the number of items stored in it.
 T remove(int position)
          Removes the item at the given index.
 boolean replace(int position, T newItem)
          Replaces the item at a given index.
 java.lang.Object[] toArray()
          Returns an array version of the list.
 

Method Detail

add

void add(T newItem)
Adds newItem to the end of the list.


add

boolean add(int newPosition,
            T newItem)
Adds newItem at the given index. Adds newItem at index newPosition, and shifts each item at or beyond that index to the next higher index. Note that L.add(L.length(), x) is a valid call, and its effect is equivalent to L.add(x). Postcondition: The item at newPosition is newItem.

Returns:
false if newPosition is out of bounds. For this method (and only this method), the length of the list is considered in bounds.

remove

T remove(int position)
Removes the item at the given index. Removes the item at the given index, shifts each item beyond that index to the next lower index.

Returns:
the removed item, or null if position is out of bounds.

clear

void clear()
Removes all items from the list.


at

T at(int position)
Returns the item at a given index.

Returns:
the item, or null if position is out of bounds.

replace

boolean replace(int position,
                T newItem)
Replaces the item at a given index.

Returns:
false if newPosition is out of bounds.

contains

boolean contains(T targetItem)
Returns true if the list contains the target item.


length

int length()
Returns the length of the list: the number of items stored in it.


isEmpty

boolean isEmpty()
Returns true if the list has no items stored in it.


toArray

java.lang.Object[] toArray()
Returns an array version of the list. Note that, for technical reasons, the type of the items contained in the list can't be communicated properly to the caller, so an array of Objects gets returned.

Returns:
an array of length length(), with the same items in it as are stored in the list, in the same order.

iterator

java.util.Iterator<T> iterator()
Returns an iterator that begins just before index 0 in this list.

Specified by:
iterator in interface java.lang.Iterable<T>