Class OrderedLinkedList<E>

java.lang.Object
  extended by OrderedLinkedList<E>

public class OrderedLinkedList<E>
extends java.lang.Object


Constructor Summary
OrderedLinkedList(java.util.Comparator<E> comparator)
          Constructs an empty OrderedLinkedList whose order is specified by the provided Comparable.
OrderedLinkedList(java.util.List<E> list, java.util.Comparator<E> comparator)
          Constructs an OrderedLinkedList containing the elements of the provided java.util.List in the order specified by the provided Comparator.
 
Method Summary
 void add(E element)
          Adds the element to the OrderedLinkedList in the position specified by the Comparator provided at construction.
 void clear()
          Empties the OrderedLinkedList so that is contains no elements.
 java.util.ArrayList<E> get()
          Builds and returns a java.util.ArrayList containing all elements in the same order as this OrderedLinkedList.
 E get(int index)
          Gets the specified element of the OrderedLinkedList
 int indexOf(E element)
          Returns the index of the first element in the list that is equal to the element passed in using the element's equals method inherited from.Object to determine equality.
 ListIterator<E> listIterator()
          Returns a ListIterator for this OrderedLinkedList.
 E remove(int index)
          Removes and returns the element at the specified index.
 int size()
          Returns the number of elements in the OrderedLinkedList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrderedLinkedList

public OrderedLinkedList(java.util.Comparator<E> comparator)
Constructs an empty OrderedLinkedList whose order is specified by the provided Comparable.


OrderedLinkedList

public OrderedLinkedList(java.util.List<E> list,
                         java.util.Comparator<E> comparator)
Constructs an OrderedLinkedList containing the elements of the provided java.util.List in the order specified by the provided Comparator.

Method Detail

add

public void add(E element)
Adds the element to the OrderedLinkedList in the position specified by the Comparator provided at construction.

Parameters:
element - The element to add to the OrderedLinkedList;

get

public E get(int index)
Gets the specified element of the OrderedLinkedList

Parameters:
index - The index of the element to get.
Returns:
the element at the specified index
Throws:
java.lang.IndexOutOfBoundsException - if the index if not valid.

get

public java.util.ArrayList<E> get()
Builds and returns a java.util.ArrayList containing all elements in the same order as this OrderedLinkedList.

Returns:
A list containing all of the elements in the same order as this OrderedLinkedList. Returns an empty list if this list is empty.

size

public int size()
Returns the number of elements in the OrderedLinkedList. Your implementation must be O(1) in performance.

Returns:
The number of elements in the OrderedLinkedList.

clear

public void clear()
Empties the OrderedLinkedList so that is contains no elements. Your implementation must be O(1) in performance.


indexOf

public int indexOf(E element)
Returns the index of the first element in the list that is equal to the element passed in using the element's equals method inherited from.Object to determine equality.

Parameters:
element - The element to search for.
Returns:
The index of the matching element.
Throws:
java.util.NoSuchElementException - if the list does not contain the specified element.

remove

public E remove(int index)
Removes and returns the element at the specified index.

Parameters:
index - The element to remove and return.
Returns:
The specified element.
Throws:
java.lang.IndexOutOfBoundsException - if the index if not valid.

listIterator

public ListIterator<E> listIterator()
Returns a ListIterator for this OrderedLinkedList.

Returns:
A ListIterator for this OrderedLinkedList.