Class MysteryListImplementation<T>

java.lang.Object
  extended by MysteryListImplementation<T>
Type Parameters:
T - The type of data that the list stores.
All Implemented Interfaces:
java.lang.Iterable<T>, List<T>

public class MysteryListImplementation<T>
extends java.lang.Object
implements List<T>

An implementation of the List ADT.


Constructor Summary
MysteryListImplementation()
          Default constructor: creates an empty list.
 
Method Summary
 boolean add(int newPosition, T newItem)
          Adds newItem at the given index, and shifts each item at or beyond that index to the next higher 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.
static void main(java.lang.String[] args)
           
 T remove(int position)
          Removes the item at the given index, and shifts each item beyond that index to the next lower 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MysteryListImplementation

public MysteryListImplementation()
Default constructor: creates an empty list.

Method Detail

add

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

Specified by:
add in interface List<T>

add

public boolean add(int newPosition,
                   T newItem)
Adds newItem at the given index, and shifts each item at or beyond that index to the next higher index.

Specified by:
add in interface List<T>
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

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

Specified by:
remove in interface List<T>
Returns:
the removed item, or null if position is out of bounds.

clear

public void clear()
Description copied from interface: List
Removes all items from the list.

Specified by:
clear in interface List<T>

replace

public boolean replace(int position,
                       T newItem)
Description copied from interface: List
Replaces the item at a given index.

Specified by:
replace in interface List<T>
Returns:
false if newPosition is out of bounds.

at

public T at(int position)
Description copied from interface: List
Returns the item at a given index.

Specified by:
at in interface List<T>
Returns:
the item, or null if position is out of bounds.

contains

public boolean contains(T targetItem)
Description copied from interface: List
Returns true if the list contains the target item.

Specified by:
contains in interface List<T>

length

public int length()
Description copied from interface: List
Returns the length of the list: the number of items stored in it.

Specified by:
length in interface List<T>

isEmpty

public boolean isEmpty()
Description copied from interface: List
Returns true if the list has no items stored in it.

Specified by:
isEmpty in interface List<T>

toArray

public java.lang.Object[] toArray()
Description copied from interface: List
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.

Specified by:
toArray in interface List<T>
Returns:
an array of length length(), with the same items in it as are stored in the list, in the same order.

iterator

public java.util.Iterator<T> iterator()
Description copied from interface: List
Returns an iterator that begins just before index 0 in this list.

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

main

public static void main(java.lang.String[] args)