csli.util.collections
Class SparseList
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList
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
|
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 |
SparseList
public SparseList()
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: