|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--net.rim.device.api.collection.util.SparseList
Maintains a list where existing elements are guaranteed to keep their assigned index until they're removed from the list.
The index of any element is always guaranteed to be less than the number of elements contained in the collection (that is, when you remove an element from the list, its index gets reused by other new elements).
Also, if you remove an element from this list, its index is immediately placed in the list of free indices available for reallocation at any time. This collection is not guaranteed to reallocate indices in any particular order.
Note: It is more efficient to use
addAndGetIndex(java.lang.Object) to add an element to the collection and retrieve the
index of the element in a single step rather than using
add(java.lang.Object) and then getKey(java.lang.Object).
The collection is persistable as long as the elements in the list are persistable.
| Constructor Summary | ||
SparseList()
Constructs a new SparseList instance. |
||
SparseList(int n)
Constructs a new SparseList instance with an initial number of indices. |
||
| Method Summary | ||
void |
add(Object element)
Adds an element to this list. |
|
int |
addAndGetIndex(Object element)
Adds an element to this list and return its index. |
|
boolean |
contains(int index)
Determines if an index already has an associated element. |
|
Enumeration |
elements()
Return an enumeration of all elements in the list. |
|
Object |
get(int index)
Retrieves element by index. |
|
int |
getKey(Object element)
Retrieves index by element. |
|
void |
insertAt(int index,
Object element)
Replaces element by index. |
|
void |
remove(Object element)
Removes element. |
|
void |
removeAll()
Flush this collection. |
|
void |
removeAt(int index)
Removes element by index. |
|
int |
size()
Retrieves the number of elements in this collection. |
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public SparseList()
This method creates a new SparseList instance with no indices
pre-allocated for elements. If you know how many indices you require from
the start, it may be more efficient to invoke SparseList(int).
public SparseList(int n)
n - Initial number of indices for elements to allocate.| Method Detail |
public void add(Object element)
Note: this method simply invokes
addAndGetIndex(java.lang.Object). If you want to keep the a local record of the
index of elements as you add them, then you should invoke
addAndGetIndex(java.lang.Object) directly as it returns the index of the added element.
element - Element to add (must not be null).public int addAndGetIndex(Object element)
element - Element to add (must not be null).public boolean contains(int index)
index - Index in question.public Enumeration elements()
public Object get(int index)
index - Index of element you wish to retrieve.public int getKey(Object element)
Note: This operation is linear with respect to the number of elements in the list.
element - Element for which you want the index.
public void insertAt(int index,
Object element)
index - Index of the element to replace; this index must currently
be used by an element.element - New element to replace the old one; must not be null.public void remove(Object element)
Note: This operation is linear with respect to the number of elements in this list.
element - Element to remove.public void removeAt(int index)
index - Index of the element to remove.public int size()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2008 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.