csli.util.collections
Class SparseList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by csli.util.collections.SparseList
All Implemented Interfaces:
Iterable, Collection, List

public class SparseList
extends AbstractList

Implements a sparse list. Implemented using a hashtable with Integers as keys. Size always returns Integer.MAX_VALUE. Use maxIndex() and minIndex() to determine the bounds of the list. By convention null value singifies no value at a specific index.

Author:
Danilo Mirkovic

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SparseList()
           
 
Method Summary
 void add(int index, Object obj)
           
 boolean add(Object obj)
          Adds an object at the position immediately after maxIndex.
 int count()
           
 Object get(int index)
          Returns the object at specified index, null if none.
 int maxIndex()
           
 int minIndex()
           
 Object remove(int index)
           
 int size()
          Always returns Integer.MAX_VALUE Use minIndex, maxIndex and count() to get info about the number of elements in the list.
 List toDenseList()
          Returns a regular list with no null entries corresponding to this sparse list.
 
Methods inherited from class java.util.AbstractList
addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

SparseList

public SparseList()
Method Detail

get

public Object get(int index)
Returns the object at specified index, null if none. Never throws an exception.

Specified by:
get in interface List
Specified by:
get in class AbstractList

add

public void add(int index,
                Object obj)
Specified by:
add in interface List
Overrides:
add in class AbstractList

add

public boolean add(Object obj)
Adds an object at the position immediately after maxIndex.

Specified by:
add in interface Collection
Specified by:
add in interface List
Overrides:
add in class AbstractList

remove

public Object remove(int index)
Specified by:
remove in interface List
Overrides:
remove in class AbstractList

size

public int size()
Always returns Integer.MAX_VALUE Use minIndex, maxIndex and count() to get info about the number of elements in the list.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection

minIndex

public int minIndex()
Returns:
the minimum index, -1 if none

maxIndex

public int maxIndex()
Returns:
the maximum index, -1 if none

count

public int count()
Returns:
true number of elements in the sparse list

toDenseList

public List toDenseList()
Returns a regular list with no null entries corresponding to this sparse list. The elements in the dense list will have the same relative ordering, but possibly different indices than in the sparse one.

Returns: