uwcse.collections
Interface SimpleList

All Known Implementing Classes:
SimpleAbstractList, SimpleArrayList, SimpleLinkedList

public interface SimpleList

A simple list interface. A list is an ordered collection of objects, which may contain duplicates.


Method Summary
 void add(int index, java.lang.Object o)
          Add the given object at the given location, shifting elements as necessary.
 void addAll(SimpleList c)
          Add the items in the given list to the end of the receiver.
 void addFirst(java.lang.Object o)
          Add the given object to the front of the list.
 void addLast(java.lang.Object o)
          Add the given object to the rear of the list.
 void clear()
          Remove all elements.
 boolean contains(java.lang.Object o)
          Answer true iff the given object is in the list.
 java.lang.Object get(int index)
          Answer the element at the given location.
 java.lang.Object getFirst()
          Answer the first element in the list.
 java.lang.Object getLast()
          Answer the last element in the list.
 int indexOf(java.lang.Object o)
          Answer the index of the first occurrence of the object in the list.
 boolean isEmpty()
          Answer size() == 0
 SimpleIterator iterator()
          Answer an iterator over the elements of the list.
 java.lang.Object remove(int i)
          Remove the item at the given index, shifting elements as necessary.
 boolean remove(java.lang.Object o)
          Remove the first occurrence of the given object.
 java.lang.Object removeFirst()
          Remove the first element.
 java.lang.Object removeLast()
          Remove the last element.
 java.lang.Object set(int index, java.lang.Object o)
          Replace the element at the given location.
 int size()
          Answer the number of elements in the collection.
 

Method Detail

add

public void add(int index,
                java.lang.Object o)
Add the given object at the given location, shifting elements as necessary.
Parameters:
index - must be >= 0 && <= length

addAll

public void addAll(SimpleList c)
Add the items in the given list to the end of the receiver.

addFirst

public void addFirst(java.lang.Object o)
Add the given object to the front of the list.

addLast

public void addLast(java.lang.Object o)
Add the given object to the rear of the list.

clear

public void clear()
Remove all elements.

contains

public boolean contains(java.lang.Object o)
Answer true iff the given object is in the list.

get

public java.lang.Object get(int index)
Answer the element at the given location.
Parameters:
index - must be >= 0 && < length

getFirst

public java.lang.Object getFirst()
Answer the first element in the list.

getLast

public java.lang.Object getLast()
Answer the last element in the list.

indexOf

public int indexOf(java.lang.Object o)
Answer the index of the first occurrence of the object in the list. Answer -1 if the object is not found.

isEmpty

public boolean isEmpty()
Answer size() == 0

iterator

public SimpleIterator iterator()
Answer an iterator over the elements of the list.

remove

public java.lang.Object remove(int i)
Remove the item at the given index, shifting elements as necessary.

remove

public boolean remove(java.lang.Object o)
Remove the first occurrence of the given object.
Returns:
the result of contains(o) before the removal takes place

removeFirst

public java.lang.Object removeFirst()
Remove the first element.

removeLast

public java.lang.Object removeLast()
Remove the last element.

set

public java.lang.Object set(int index,
                            java.lang.Object o)
Replace the element at the given location.
Parameters:
index - must be >= 0 && < length

size

public int size()
Answer the number of elements in the collection.