BRUtil - Making Java a Kinder, Gentler, Place to be.

brutil
Class ArrayList

java.lang.Object
  |
  +--brutil.ArrayList
All Implemented Interfaces:
Collection, List

public class ArrayList
extends java.lang.Object
implements List

This is circular buffer implementation of a list with a standard java array as the underlying data structure. All operations to the ends of the ArrayList take constant time, while any modification operations to the middle of the ArrayList (using ListIterator or ReverseListIterator) take linear time.


Constructor Summary
ArrayList(int maxSize)
          An ArrayList of size maxSize
 
Method Summary
 void append(java.lang.Object elt)
          Appends the given element to the end of the list.
 void clean()
          Use this method when you want to fully clear the underlying array and free up all objects for collection.
 void clear()
          This clear method simply removes the pointer to the first item and resets the size Functionally, this clears the list, but the objects in the list are not freed for collection.
 java.lang.Object getFirst()
          Returns the first element of the list
 java.lang.Object getLast()
          Returns the element at the end of the list.
 void initMemory()
           
 boolean isEmpty()
          Returns true if there are no elements in the list (size == 0).
 ListIterator iterator()
          Returns a ListIterator pointing to the head of the list.
static void main(java.lang.String[] args)
           
 int maxLength()
           
 void prepend(java.lang.Object elt)
          Prepends the given element to the beginning of the list.
 void printArray()
           
 java.lang.Object removeFirst()
          Removes the first element of the list.
 java.lang.Object removeLast()
          Removes the last element of the list.
 ReverseListIterator reverseIterator()
          Returns a ReverseListIterator pointing to the end of the list.
 int size()
          Returns the number of elements in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayList

public ArrayList(int maxSize)
An ArrayList of size maxSize
Method Detail

initMemory

public void initMemory()

append

public void append(java.lang.Object elt)
Appends the given element to the end of the list.
Specified by:
append in interface List
Parameters:
elt - The element that is to be appended.
Throws:
IllegalStateException - if the list has reached maximum length.

prepend

public void prepend(java.lang.Object elt)
Prepends the given element to the beginning of the list.
Specified by:
prepend in interface List
Parameters:
elt - The element to be prepended.
Throws:
IllegalStateException - if the list has reached maximum length.

getFirst

public java.lang.Object getFirst()
Returns the first element of the list
Specified by:
getFirst in interface List
Returns:
the element at the beginning of the list (index = 0).
Throws:
NoSuchElementException - if the list is empty.

getLast

public java.lang.Object getLast()
Returns the element at the end of the list.
Specified by:
getLast in interface List
Returns:
the element at the end of the list.
Throws:
NoSuchElementException - if the list is empty.

removeFirst

public java.lang.Object removeFirst()
Removes the first element of the list.
Specified by:
removeFirst in interface List
Throws:
NoSuchElementException - if the list is empty.

removeLast

public java.lang.Object removeLast()
Removes the last element of the list. The index to the last element to the list is decremented.
Specified by:
removeLast in interface List
Throws:
NoSuchElementException - if the list is empty.

clear

public void clear()
This clear method simply removes the pointer to the first item and resets the size Functionally, this clears the list, but the objects in the list are not freed for collection. To free all of these items up, use the method clean. The clean method, however takes O(n) time, while clear is O(1)
Specified by:
clear in interface List

clean

public void clean()
Use this method when you want to fully clear the underlying array and free up all objects for collection. This method takes O(n) time, where n is the current size of the array. If you want better timing guarantees, use the clear method.

isEmpty

public boolean isEmpty()
Returns true if there are no elements in the list (size == 0).
Specified by:
isEmpty in interface List
Returns:
true if there are no elements in the list, false otherwise.

size

public int size()
Returns the number of elements in the list.
Specified by:
size in interface List
Returns:
the number of elements in the list.

iterator

public ListIterator iterator()
Returns a ListIterator pointing to the head of the list.
Specified by:
iterator in interface List

reverseIterator

public ReverseListIterator reverseIterator()
Returns a ReverseListIterator pointing to the end of the list.
Specified by:
reverseIterator in interface List
Following copied from interface: brutil.List
Throws:
UnsupportedMethodException -  

printArray

public void printArray()

main

public static void main(java.lang.String[] args)

maxLength

public int maxLength()


BRUtil - Making Java a Kinder, Gentler, Place to be.