info.jonclark.lang
Class SparseArray<T>

java.lang.Object
  extended by info.jonclark.lang.SparseArray<T>
All Implemented Interfaces:
Serializable

public class SparseArray<T>
extends Object
implements Serializable

An array based on LinkedLists such that memory usage is minimized even for very large arrays Note: Array indices are constant; list indicies are subject to change. Created on January 30, 2006

See Also:
Serialized Form

Constructor Summary
SparseArray()
           
 
Method Summary
 T get(long arrIndex)
          Get an object at a specified array index
 boolean hasIndex(long arrIndex)
          Determine if the specified index has already been assigned a value in this sparse array
 void set(long arrIndex, T obj)
          Write an object at the given array index
 long size()
          Returns the number of elements that have been set to a non-null value
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SparseArray

public SparseArray()
Method Detail

set

public void set(long arrIndex,
                T obj)
Write an object at the given array index

Parameters:
arrIndex - The index of the object to add/replace
obj - The object to write

get

public T get(long arrIndex)
      throws RuntimeException
Get an object at a specified array index

Parameters:
arrIndex - The array index of the desired object
Returns:
The object at the specified array index
Throws:
RuntimeException

hasIndex

public boolean hasIndex(long arrIndex)
Determine if the specified index has already been assigned a value in this sparse array

Parameters:
arrIndex -
Returns:
True if the index already exists in this sparse array

size

public long size()
Returns the number of elements that have been set to a non-null value

Returns:

toString

public String toString()
Overrides:
toString in class Object