java.util
Class AbstractList

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
All Implemented Interfaces:
Iterable, Collection, List
Direct Known Subclasses:
ArrayList

public abstract class AbstractList
extends AbstractCollection
implements List

AbstractList is an abstract implementation of the List interface, optimized for a backing store which supports random access. This implementation does not support adding or replacing. A subclass must implement the abstract methods get() and size().

Since:
1.2

Constructor Summary
protected AbstractList()
          Constructs a new instance of this AbstractList.
 
Method Summary
 void add(int location, Object object)
          Inserts the specified object into this List at the specified location.
 boolean add(Object object)
          Adds the specified object at the end of this List.
 boolean addAll(int location, Collection collection)
          Inserts the objects in the specified Collection at the specified location in this List.
 void clear()
          Removes all elements from this List, leaving it empty.
 boolean equals(Object object)
          Compares the specified object to this List and answer if they are equal.
abstract  Object get(int location)
          Answers the element at the specified location in this List.
 int hashCode()
          Answers an integer hash code for the receiver.
 int indexOf(Object object)
          Searches this List for the specified object and returns the index of the first occurrence.
 Iterator iterator()
          Answers an Iterator on the elements of this List.
 Object remove(int location)
          Removes the object at the specified location from this List.
protected  void removeRange(int start, int end)
          Removes the objects in the specified range from the start to the, but not including, end index.
 Object set(int location, Object object)
          Replaces the element at the specified location in this List with the specified object.
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, getClass, println
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, lastIndexOf, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

AbstractList

protected AbstractList()
Constructs a new instance of this AbstractList.

Method Detail

add

public void add(int location,
                Object object)
Inserts the specified object into this List at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this List, the object is added at the end.

Specified by:
add in interface List
Parameters:
location - the index at which to insert
object - the object to add
Throws:
UnsupportedOperationException - when adding to this List is not supported
ClassCastException - when the class of the object is inappropriate for this List
IllegalArgumentException - when the object cannot be added to this List
IndexOutOfBoundsException - when location < 0 || >= size()

add

public boolean add(Object object)
Adds the specified object at the end of this List.

Specified by:
add in interface Collection
Specified by:
add in interface List
Overrides:
add in class AbstractCollection
Parameters:
object - the object to add
Returns:
true
Throws:
UnsupportedOperationException - when adding to this List is not supported
ClassCastException - when the class of the object is inappropriate for this List
IllegalArgumentException - when the object cannot be added to this List

addAll

public boolean addAll(int location,
                      Collection collection)
Inserts the objects in the specified Collection at the specified location in this List. The objects are added in the order they are returned from the Collection iterator.

Specified by:
addAll in interface List
Parameters:
location - the index at which to insert
collection - the Collection of objects
Returns:
true if this List is modified, false otherwise
Throws:
UnsupportedOperationException - when adding to this List is not supported
ClassCastException - when the class of an object is inappropriate for this List
IllegalArgumentException - when an object cannot be added to this List
IndexOutOfBoundsException - when location < 0 || >= size()

clear

public void clear()
Removes all elements from this List, leaving it empty.

Specified by:
clear in interface Collection
Specified by:
clear in interface List
Overrides:
clear in class AbstractCollection
Throws:
UnsupportedOperationException - when removing from this List is not supported
See Also:
List#isEmpty, List#size

equals

public boolean equals(Object object)
Compares the specified object to this List and answer if they are equal. The object must be a List which contains the same objects in the same order.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the specified object is equal to this List, false otherwise
See Also:
hashCode()

get

public abstract Object get(int location)
Answers the element at the specified location in this List.

Specified by:
get in interface List
Parameters:
location - the index of the element to return
Returns:
the element at the specified index
Throws:
IndexOutOfBoundsException - when location < 0 || >= size()

hashCode

public int hashCode()
Answers an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

indexOf

public int indexOf(Object object)
Searches this List for the specified object and returns the index of the first occurrence.

Specified by:
indexOf in interface List
Parameters:
object - the object to search for
Returns:
the index of the first occurrence of the object

iterator

public Iterator iterator()
Answers an Iterator on the elements of this List. The elements are iterated in the same order that they occur in the List.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List
Specified by:
iterator in class AbstractCollection
Returns:
an Iterator on the elements of this List
See Also:
Iterator

remove

public Object remove(int location)
Removes the object at the specified location from this List.

Specified by:
remove in interface List
Parameters:
location - the index of the object to remove
Returns:
the removed object
Throws:
UnsupportedOperationException - when removing from this List is not supported
IndexOutOfBoundsException - when location < 0 || >= size()

removeRange

protected void removeRange(int start,
                           int end)
Removes the objects in the specified range from the start to the, but not including, end index.

Parameters:
start - the index at which to start removing
end - the index one past the end of the range to remove
Throws:
UnsupportedOperationException - when removing from this List is not supported
IndexOutOfBoundsException - when start < 0

set

public Object set(int location,
                  Object object)
Replaces the element at the specified location in this List with the specified object.

Specified by:
set in interface List
Parameters:
location - the index at which to put the specified object
object - the object to add
Returns:
the previous element at the index
Throws:
UnsupportedOperationException - when replacing elements in this List is not supported
ClassCastException - when the class of an object is inappropriate for this List
IllegalArgumentException - when an object cannot be added to this List
IndexOutOfBoundsException - when location < 0 || >= size()