weiss.util
Class LinkedList

java.lang.Object
  |
  +--weiss.util.AbstractCollection
        |
        +--weiss.util.LinkedList
All Implemented Interfaces:
Collection, List, java.io.Serializable

public class LinkedList
extends AbstractCollection
implements List

LinkedList class implements a doubly-linked list.

See Also:
Serialized Form

Constructor Summary
LinkedList()
          Construct an empty LinkedList.
LinkedList(Collection other)
          Construct a LinkedList with same items as another Collection.
 
Method Summary
 void add(int idx, java.lang.Object x)
          Adds an item to this collection, at specified position.
 boolean add(java.lang.Object x)
          Adds an item to this collection, at the end.
 void addFirst(java.lang.Object x)
          Adds an item to this collection, at front.
 void addLast(java.lang.Object x)
          Adds an item to this collection, at 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.
 java.lang.Object get(int idx)
          Returns the item at position idx.
 java.lang.Object getFirst()
          Returns the first item in the list.
 java.lang.Object getLast()
          Returns the last item in the list.
 Iterator iterator()
          Obtains an Iterator object used to traverse the collection.
 ListIterator listIterator(int idx)
          Obtains a ListIterator object used to traverse the collection bidirectionally.
 java.lang.Object remove(int idx)
          Removes an item from this collection.
 boolean remove(java.lang.Object x)
          Removes an item from this collection.
 java.lang.Object removeFirst()
          Removes the first item in the list.
 java.lang.Object removeLast()
          Removes the last item in the list.
 java.lang.Object set(int idx, java.lang.Object newVal)
          Changes the item at position idx.
 int size()
          Returns the number of items in this collection.
 
Methods inherited from class weiss.util.AbstractCollection
equals, hashCode, isEmpty, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface weiss.util.Collection
isEmpty, toArray
 

Constructor Detail

LinkedList

public LinkedList()
Construct an empty LinkedList.

LinkedList

public LinkedList(Collection other)
Construct a LinkedList with same items as another Collection.
Method Detail

size

public int size()
Returns the number of items in this collection.
Specified by:
size in interface Collection
Returns:
the number of items in this collection.

contains

public boolean contains(java.lang.Object x)
Tests if some item is in this collection.
Specified by:
contains in interface Collection
Overrides:
contains in class AbstractCollection
Parameters:
x - any object.
Returns:
true if this collection contains an item equal to x.

add

public boolean add(java.lang.Object x)
Adds an item to this collection, at the end.
Specified by:
add in interface Collection
Parameters:
x - any object.
Returns:
true.

add

public void add(int idx,
                java.lang.Object x)
Adds an item to this collection, at specified position. Items at or after that position are slid one position higher.
Parameters:
x - any object.
idx - position to add at.
Throws:
IndexOutOfBoundsException - if idx is not between 0 and size(), inclusive.

addFirst

public void addFirst(java.lang.Object x)
Adds an item to this collection, at front. Other items are slid one position higher.
Parameters:
x - any object.

addLast

public void addLast(java.lang.Object x)
Adds an item to this collection, at end.
Parameters:
x - any object.

getFirst

public java.lang.Object getFirst()
Returns the first item in the list.
Throws:
NoSuchElementException - if the list is empty.

getLast

public java.lang.Object getLast()
Returns the last item in the list.
Throws:
NoSuchElementException - if the list is empty.

removeFirst

public java.lang.Object removeFirst()
Removes the first item in the list.
Returns:
the item was removed from the collection.
Throws:
NoSuchElementException - if the list is empty.

removeLast

public java.lang.Object removeLast()
Removes the last item in the list.
Returns:
the item was removed from the collection.
Throws:
NoSuchElementException - if the list is empty.

remove

public boolean remove(java.lang.Object x)
Removes an item from this collection.
Specified by:
remove in interface Collection
Overrides:
remove in class AbstractCollection
Parameters:
x - any object.
Returns:
true if this item was removed from the collection.

get

public java.lang.Object get(int idx)
Returns the item at position idx.
Specified by:
get in interface List
Parameters:
idx - the index to search in.
Throws:
IndexOutOfBoundsException - if index is out of range.

set

public java.lang.Object set(int idx,
                            java.lang.Object newVal)
Changes the item at position idx.
Specified by:
set in interface List
Parameters:
idx - the index to change.
newVal - the new value.
Returns:
the old value.
Throws:
IndexOutOfBoundsException - if index is out of range.

remove

public java.lang.Object 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
Overrides:
clear in class AbstractCollection

iterator

public Iterator iterator()
Obtains an Iterator object used to traverse the collection.
Specified by:
iterator in interface Collection

listIterator

public ListIterator listIterator(int idx)
Obtains a ListIterator object used to traverse the collection bidirectionally.
Specified by:
listIterator in interface List
Parameters:
idx - the index to start the iterator. Use size() to do complete reverse traversal. Use 0 to do complete forward traversal.
Throws:
IndexOutOfBoundsException - if idx is not between 0 and size(), inclusive.