weiss.util
Class ArrayList<AnyType>

java.lang.Object
  extended by weiss.util.AbstractCollection<AnyType>
      extended by weiss.util.ArrayList<AnyType>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<AnyType>, Collection<AnyType>, List<AnyType>

public class ArrayList<AnyType>
extends AbstractCollection<AnyType>
implements List<AnyType>

The ArrayList implements a growable array. Insertions are always done at the end.

See Also:
Serialized Form

Constructor Summary
ArrayList()
          Construct an empty ArrayList.
ArrayList(Collection<? extends AnyType> other)
          Construct an ArrayList with same items as another Collection.
 
Method Summary
 boolean add(AnyType x)
          Adds an item to this collection, at the end.
 void clear()
          Change the size of this collection to zero.
 boolean contains(java.lang.Object x)
          Tests if some item is in this collection.
 AnyType get(int idx)
          Returns the item at position idx.
 Iterator<AnyType> iterator()
          Obtains an Iterator object used to traverse the collection.
 ListIterator<AnyType> listIterator(int idx)
          Obtains a ListIterator object used to traverse the collection bidirectionally.
 AnyType remove(int idx)
          Removes an item from this collection.
 boolean remove(java.lang.Object x)
          Removes an item from this collection.
 AnyType set(int idx, AnyType newVal)
          Changes the item at position idx.
 int size()
          Returns the number of items in this collection.
 ArrayList<AnyType> subList(int from, int to)
           
 
Methods inherited from class weiss.util.AbstractCollection
equals, hashCode, isEmpty, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface weiss.util.Collection
isEmpty, toArray, toArray
 

Constructor Detail

ArrayList

public ArrayList()
Construct an empty ArrayList.


ArrayList

public ArrayList(Collection<? extends AnyType> other)
Construct an ArrayList with same items as another Collection.

Method Detail

subList

public ArrayList<AnyType> subList(int from,
                                  int to)

size

public int size()
Returns the number of items in this collection.

Specified by:
size in interface Collection<AnyType>
Returns:
the number of items in this collection.

get

public AnyType get(int idx)
Returns the item at position idx.

Specified by:
get in interface List<AnyType>
Parameters:
idx - the index to search in.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of range.

set

public AnyType set(int idx,
                   AnyType newVal)
Changes the item at position idx.

Specified by:
set in interface List<AnyType>
Parameters:
idx - the index to change.
newVal - the new value.
Returns:
the old value.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of range.

contains

public boolean contains(java.lang.Object x)
Tests if some item is in this collection.

Specified by:
contains in interface Collection<AnyType>
Overrides:
contains in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true if this collection contains an item equal to x.

add

public boolean add(AnyType x)
Adds an item to this collection, at the end.

Specified by:
add in interface Collection<AnyType>
Overrides:
add in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true.

remove

public boolean remove(java.lang.Object x)
Removes an item from this collection.

Specified by:
remove in interface Collection<AnyType>
Overrides:
remove in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true if this item was removed from the collection.

remove

public AnyType remove(int idx)
Removes an item from this collection.

Parameters:
idx - the index of the object.
Returns:
the item was removed from the collection.

clear

public void clear()
Change the size of this collection to zero.

Specified by:
clear in interface Collection<AnyType>
Overrides:
clear in class AbstractCollection<AnyType>

iterator

public Iterator<AnyType> iterator()
Obtains an Iterator object used to traverse the collection.

Specified by:
iterator in interface java.lang.Iterable<AnyType>
Specified by:
iterator in interface Collection<AnyType>
Returns:
an iterator positioned prior to the first element.

listIterator

public ListIterator<AnyType> listIterator(int idx)
Obtains a ListIterator object used to traverse the collection bidirectionally.

Specified by:
listIterator in interface List<AnyType>
Parameters:
idx - the index to start the iterator. Use size() to do complete reverse traversal. Use 0 to do complete forward traversal.
Returns:
an iterator positioned prior to the requested element.
Throws:
java.lang.IndexOutOfBoundsException - if idx is not between 0 and size(), inclusive.