uwcse.collections
Class SimpleAbstractList

java.lang.Object
  |
  +--uwcse.collections.SimpleAbstractList
All Implemented Interfaces:
SimpleList
Direct Known Subclasses:
SimpleArrayList, SimpleLinkedList

public abstract class SimpleAbstractList
extends java.lang.Object
implements SimpleList

An abstract superclass for list implementations. Implements several of the basic operations in terms of operations that are left to concrete implementations


Constructor Summary
SimpleAbstractList()
           
 
Method Summary
abstract  void add(int index, java.lang.Object o)
          Add the given object at the given location, shifting elements as necessary.
 void addAll(SimpleList c)
          Iterates over the given collection, adding each item to the end of the receiver.
abstract  void addFirst(java.lang.Object o)
          Add the given object to the front of the list.
abstract  void addLast(java.lang.Object o)
          Add the given object to the rear of the list.
abstract  void clear()
          Remove all elements.
 boolean contains(java.lang.Object o)
          Answers indexOf(o) != -1
abstract  java.lang.Object get(int index)
          Answer the element at the given location.
 java.lang.Object getFirst()
          Answers get(0)
 java.lang.Object getLast()
          Answers get(size() - 1)
 int indexOf(java.lang.Object o)
          Iterates over the items, answering the index of the first occurrence of o.
 boolean isEmpty()
          Answer size() == 0
abstract  SimpleIterator iterator()
          Answer an iterator over the elements of the list.
abstract  java.lang.Object remove(int i)
          Remove the item at the given index, shifting elements as necessary.
 boolean remove(java.lang.Object o)
          Relies on indexOf(o) and remove(index).
abstract  java.lang.Object removeFirst()
          Remove the first element.
abstract  java.lang.Object removeLast()
          Remove the last element.
abstract  java.lang.Object set(int index, java.lang.Object o)
          Replace the element at the given location.
abstract  int size()
          Answer the number of elements in the collection.
static void test(SimpleList list)
          A generalized test method which can be used by subclasses.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleAbstractList

public SimpleAbstractList()
Method Detail

add

public abstract void add(int index,
                         java.lang.Object o)
Description copied from interface: SimpleList
Add the given object at the given location, shifting elements as necessary.
Specified by:
add in interface SimpleList
Following copied from interface: uwcse.collections.SimpleList
Parameters:
index - must be >= 0 && <= length

addAll

public void addAll(SimpleList c)
Iterates over the given collection, adding each item to the end of the receiver.
Specified by:
addAll in interface SimpleList

addFirst

public abstract void addFirst(java.lang.Object o)
Description copied from interface: SimpleList
Add the given object to the front of the list.
Specified by:
addFirst in interface SimpleList

addLast

public abstract void addLast(java.lang.Object o)
Description copied from interface: SimpleList
Add the given object to the rear of the list.
Specified by:
addLast in interface SimpleList

clear

public abstract void clear()
Description copied from interface: SimpleList
Remove all elements.
Specified by:
clear in interface SimpleList

contains

public boolean contains(java.lang.Object o)
Answers indexOf(o) != -1
Specified by:
contains in interface SimpleList

get

public abstract java.lang.Object get(int index)
Description copied from interface: SimpleList
Answer the element at the given location.
Specified by:
get in interface SimpleList
Following copied from interface: uwcse.collections.SimpleList
Parameters:
index - must be >= 0 && < length

getFirst

public java.lang.Object getFirst()
Answers get(0)
Specified by:
getFirst in interface SimpleList

getLast

public java.lang.Object getLast()
Answers get(size() - 1)
Specified by:
getLast in interface SimpleList

indexOf

public int indexOf(java.lang.Object o)
Iterates over the items, answering the index of the first occurrence of o.
Specified by:
indexOf in interface SimpleList

isEmpty

public boolean isEmpty()
Description copied from interface: SimpleList
Answer size() == 0
Specified by:
isEmpty in interface SimpleList

iterator

public abstract SimpleIterator iterator()
Description copied from interface: SimpleList
Answer an iterator over the elements of the list.
Specified by:
iterator in interface SimpleList

remove

public abstract java.lang.Object remove(int i)
Description copied from interface: SimpleList
Remove the item at the given index, shifting elements as necessary.
Specified by:
remove in interface SimpleList

remove

public boolean remove(java.lang.Object o)
Relies on indexOf(o) and remove(index).
Specified by:
remove in interface SimpleList
Following copied from interface: uwcse.collections.SimpleList
Returns:
the result of contains(o) before the removal takes place

removeFirst

public abstract java.lang.Object removeFirst()
Description copied from interface: SimpleList
Remove the first element.
Specified by:
removeFirst in interface SimpleList

removeLast

public abstract java.lang.Object removeLast()
Description copied from interface: SimpleList
Remove the last element.
Specified by:
removeLast in interface SimpleList

set

public abstract java.lang.Object set(int index,
                                     java.lang.Object o)
Description copied from interface: SimpleList
Replace the element at the given location.
Specified by:
set in interface SimpleList
Following copied from interface: uwcse.collections.SimpleList
Parameters:
index - must be >= 0 && < length

size

public abstract int size()
Description copied from interface: SimpleList
Answer the number of elements in the collection.
Specified by:
size in interface SimpleList

test

public static void test(SimpleList list)
A generalized test method which can be used by subclasses. Takes a SimpleList and fires of a ListTester on it.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object