com.timeindexing.util
Class DoubleLinkedList

java.lang.Object
  extended bycom.timeindexing.util.DoubleLinkedList

public class DoubleLinkedList
extends java.lang.Object

A doubly linked list. This is similar to java.util.LinkedList but it keeps its own current position. This allows access to consecutive nodes to be faster, particularly in large lists. LinkedList always starts a getItem() at node 0.


Constructor Summary
DoubleLinkedList()
          Construct a DoubleLinkedList.
 
Method Summary
 void add(long index, java.lang.Object element)
          Inserts the specified element at the specified position in this list.
 boolean add(java.lang.Object o)
          Appends the specified element to the end of this list.
 void addFirst(java.lang.Object o)
          Inserts the given element at the beginning of this list.
 void addLast(java.lang.Object o)
          Appends the given element to the end of this list.
 void clear()
          Removes all of the elements from this list.
 java.lang.Object get(long index)
          Returns the element at the specified position in this list.
 java.lang.Object getFirst()
          Returns the first element in this list.
 java.lang.Object getLast()
          Returns the last element in this list.
 long indexOf(java.lang.Object o)
          Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element.
 long lastIndexOf(java.lang.Object o)
          Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
 java.lang.Object remove(long index)
          Removes the element at the specified position in this list.
 boolean remove(java.lang.Object o)
          Removes the first occurrence of the specified element in this list.
 java.lang.Object removeFirst()
          Removes and returns the first element from this list.
 java.lang.Object removeLast()
          Removes and returns the last element from this list.
 java.lang.Object set(long index, java.lang.Object element)
          Replaces the element at the specified position in this list with the specified element.
 long size()
          Returns the number of elements in this list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleLinkedList

public DoubleLinkedList()
Construct a DoubleLinkedList.

Method Detail

getFirst

public java.lang.Object getFirst()
Returns the first element in this list.

Returns:
the first element in this list.
Throws:
java.util.NoSuchElementException - if this list is empty.

getLast

public java.lang.Object getLast()
Returns the last element in this list.

Returns:
the last element in this list.
Throws:
java.util.NoSuchElementException - if this list is empty.

removeFirst

public java.lang.Object removeFirst()
Removes and returns the first element from this list.

Returns:
the first element from this list.
Throws:
java.util.NoSuchElementException - if this list is empty.

removeLast

public java.lang.Object removeLast()
Removes and returns the last element from this list.

Returns:
the last element from this list.
Throws:
java.util.NoSuchElementException - if this list is empty.

addFirst

public void addFirst(java.lang.Object o)
Inserts the given element at the beginning of this list.

Parameters:
o - the element to be inserted at the beginning of this list.

addLast

public void addLast(java.lang.Object o)
Appends the given element to the end of this list. (Identical in function to the add method; included only for consistency.)

Parameters:
o - the element to be inserted at the end of this list.

size

public long size()
Returns the number of elements in this list.

Returns:
the number of elements in this list.

add

public boolean add(java.lang.Object o)
Appends the specified element to the end of this list.

Parameters:
o - element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).

remove

public boolean remove(java.lang.Object o)
Removes the first occurrence of the specified element in this list. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists).

Parameters:
o - element to be removed from this list, if present.
Returns:
true if the list contained the specified element.

clear

public void clear()
Removes all of the elements from this list.


get

public java.lang.Object get(long index)
Returns the element at the specified position in this list.

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is is out of range (index < 0 || index >= size()).

set

public java.lang.Object set(long index,
                            java.lang.Object element)
Replaces the element at the specified position in this list with the specified element.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).

add

public void add(long index,
                java.lang.Object element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index > size()).

remove

public java.lang.Object remove(long index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters:
index - the index of the element to removed.
Returns:
the element previously at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).

indexOf

public long indexOf(java.lang.Object o)
Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.

Parameters:
o - element to search for.
Returns:
the index in this list of the first occurrence of the specified element, or -1 if the list does not contain this element.

lastIndexOf

public long lastIndexOf(java.lang.Object o)
Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.

Parameters:
o - element to search for.
Returns:
the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.