ist.palcom.base
Class ArrayList

java.lang.Object
  extended by ist.palcom.base.Object
      extended by ist.palcom.base.ArrayList

public class ArrayList
extends Object

ArrayList is an array based list that supports most of the interface of Java ArrayList. The storage is automatically extended to make room for new elements. Adding elements to the front or back takes time amortized O(1).


Constructor Summary
ArrayList()
          Creates a new ArrayList.
ArrayList(int n)
          Creates a new ArrayList.
 
Method Summary
 void add(Object value)
          Adds the specified value after the last element of this ArrayList.
 void addFirst(Object value)
          Adds the specified value before the first element of this ArrayList.
 void addLast(Object value)
          Adds the specified value after the last element of this ArrayList.
 Array asArray()
          Returns an array containing all elements in this ArrayList in the correct order.
 Object at(int index)
          Returns the element at the specified position.
 void at(int index, Object value)
          Replaces the element at the specified position with the specified value.
 void clear()
          Removes all elements from this ArrayList giving an empty list.
 boolean contains(Object value)
          Tests if this ArrayList contains the specified value.
 int indexOf(Object value)
          Returns the index of the first occurrence of the specified value in this ArrayList.
 void init()
          Initializes this ArrayList.
 boolean isEmpty()
          Tests if this ArrayList is empty.
 int lastIndexOf(Object value)
          Returns the index of the last occurrence of the specified value in this ArrayList.
 void remove(Object value)
          Removes on instance of the specified value from this ArrayList.
 void removeAt(index index)
          Removes the element at the specified position while sliding all elements to the right of the position leftward.
 Object removeFirst()
          Removes the first element of this ArrayList.
 Object removeLast()
          Removes the last element of this ArrayList.
 int size()
          Returns the number of elements in this ArrayList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayList

public ArrayList(int n)
Creates a new ArrayList.

Parameters:
n - int initial capacity

ArrayList

public ArrayList()
Creates a new ArrayList.

Method Detail

asArray

public Array asArray()
Returns an array containing all elements in this ArrayList in the correct order.

Returns:
Array an array containing all elements in this ArrayList.

lastIndexOf

public int lastIndexOf(Object value)
Returns the index of the last occurrence of the specified value in this ArrayList. If the value does not exist in this ArrayList, -1 will be returned.

Parameters:
value - Object the value to search for.
Returns:
int the index of the last occurrence of the value.

addLast

public void addLast(Object value)
Adds the specified value after the last element of this ArrayList.

Parameters:
value - Object the value to add after last element.

at

public Object at(int index)
Returns the element at the specified position.

Parameters:
index - int index of element to return.
Returns:
Object element at the specified position.

size

public int size()
Returns the number of elements in this ArrayList.

Returns:
int the number of elements in this ArrayList

indexOf

public int indexOf(Object value)
Returns the index of the first occurrence of the specified value in this ArrayList. If the value does not exist in this ArrayList, -1 will be returned.

Parameters:
value - Object the value to search for.
Returns:
int the index of the first occurrence of the value.

addFirst

public void addFirst(Object value)
Adds the specified value before the first element of this ArrayList.

Parameters:
value - Object the value to add before the first element..

remove

public void remove(Object value)
Removes on instance of the specified value from this ArrayList.

Parameters:
value - Object value to remove.

removeLast

public Object removeLast()
Removes the last element of this ArrayList.

Returns:
Object the removed element.

removeFirst

public Object removeFirst()
Removes the first element of this ArrayList.

Returns:
Object the removed element.

removeAt

public void removeAt(index index)
Removes the element at the specified position while sliding all elements to the right of the position leftward.

Parameters:
index - index of the element to remove.

clear

public void clear()
Removes all elements from this ArrayList giving an empty list.


add

public void add(Object value)
Adds the specified value after the last element of this ArrayList.

Parameters:
value - Object the value to add after last element.

contains

public boolean contains(Object value)
Tests if this ArrayList contains the specified value.

Parameters:
value - Object value to search for.
Returns:
boolean true if the value is contained in this ArrayList, false otherwise.

at

public void at(int index,
               Object value)
Replaces the element at the specified position with the specified value.

Parameters:
index - int index of element to replace
value - Object new value to store at specified position

init

public void init()
Initializes this ArrayList.


isEmpty

public boolean isEmpty()
Tests if this ArrayList is empty.

Returns:
boolean true if this ArrayList has no elements, false otherwise