org.rutil.collection
Class SingleLinkedList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by org.rutil.collection.SingleLinkedList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>

public class SingleLinkedList<E>
extends java.util.AbstractCollection<E>
implements java.lang.Iterable<E>, java.util.Collection<E>

A light-weight one-way linked list. The size of this list is limited only by the amount of memory available. It implments the collection interface. In addition the size and toArray methods are NOT guranteed to return correct results (in some scenarios).

size: size is tracked by an "int" value and the actual size could exceed Intger.MAX_VALUE, in which case size always return Integer.MAX_VALUE
toArray: the max size of an array is Integer.MAX_VALUE. if the actual size is larger than that, toArray methods will truncate.

Author:
mohan

Field Summary
protected  SingleLinkedEntry<E> headEntry
           
protected  int size
           
protected  SingleLinkedEntry<E> tailEntry
           
 
Constructor Summary
SingleLinkedList()
           
 
Method Summary
 boolean add(E element)
          Add element to end of the list.
 boolean addAll(java.util.Collection<? extends E> c)
          Invokes addAll(SingleLinkedList) or addAll(Iterator), depending on the input arg type.
 boolean addAll(java.util.Iterator<? extends E> c)
          Adds all elements in the iterator.
 void addAll(SingleLinkedList<E> list)
          Very fast bulk add implementation.
 void clear()
           
protected  void incrementSize(int incrBy)
           
 boolean isEmpty()
           
 java.util.Iterator<E> iterator()
          A mutable Iterator.
 int size()
           
 org.rutil.collection.SingleLinkedList.UnmodifiableIterator unmodifiableIterator()
           
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

size

protected int size

headEntry

protected SingleLinkedEntry<E> headEntry

tailEntry

protected SingleLinkedEntry<E> tailEntry
Constructor Detail

SingleLinkedList

public SingleLinkedList()
Method Detail

add

public boolean add(E element)
Add element to end of the list.

Specified by:
add in interface java.util.Collection<E>
Overrides:
add in class java.util.AbstractCollection<E>
Parameters:
element -
Returns:
true, always.

incrementSize

protected void incrementSize(int incrBy)

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Invokes addAll(SingleLinkedList) or addAll(Iterator), depending on the input arg type.

Specified by:
addAll in interface java.util.Collection<E>
Overrides:
addAll in class java.util.AbstractCollection<E>
Parameters:
c - collection of elements
Returns:
true, always

addAll

public boolean addAll(java.util.Iterator<? extends E> c)
Adds all elements in the iterator. Invoking this method is similar to invoking add multiple times with one item/invocation.

Parameters:
c - iterator with elements to add.
Returns:
returns true, always

addAll

public void addAll(SingleLinkedList<E> list)
Very fast bulk add implementation. Updates the tail pointer and size only.

Parameters:
list -

size

public int size()
Specified by:
size in interface java.util.Collection<E>
Specified by:
size in class java.util.AbstractCollection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<E>
Overrides:
isEmpty in class java.util.AbstractCollection<E>

iterator

public java.util.Iterator<E> iterator()
A mutable Iterator.

Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in class java.util.AbstractCollection<E>
Returns:
an iterator that implements remove.

unmodifiableIterator

public org.rutil.collection.SingleLinkedList.UnmodifiableIterator unmodifiableIterator()

clear

public void clear()
Specified by:
clear in interface java.util.Collection<E>
Overrides:
clear in class java.util.AbstractCollection<E>