net.rim.device.api.collection.util
Class BigSortedReadableList

java.lang.Object
  extended by net.rim.device.api.collection.util.BigUnsortedReadableList
      extended by net.rim.device.api.collection.util.BigSortedReadableList
All Implemented Interfaces:
ChainableCollection, Collection, CollectionEventSource, CollectionListener, LoadableCollection, ReadableList, SortableCollection

public class BigSortedReadableList
extends BigUnsortedReadableList
implements SortableCollection

Maintains a large collection of elements in a sorted order.

When building one of these objects, you must pass it a Comparator object this collection will use to assist in sorting its elements.


Field Summary
 
Fields inherited from class net.rim.device.api.collection.util.BigUnsortedReadableList
_elements, _lastInsertedUpdated, _lastInsertedUpdatedIndex, _listenerManager
 
Constructor Summary
BigSortedReadableList(Comparator comparator)
          Constructs a new BigSortedReadableList instance.
BigSortedReadableList(CollectionEventSource sourceCollection, Comparator comparator)
          Constructs a new BigSortedReadableList instance and initialize with source.
 
Method Summary
protected  int binarySearch(Object key, int startIndex, int endIndex)
          Does binary search to locate an element.
protected  void doAdd(Object element)
          Adds an element to this collection without sending an add event.
protected  boolean doUpdate(Object oldElement, Object newElement)
          Updates an element in this collection without sending an update element.
 Comparator getComparator()
          Retrieves this collection's comparator object.
protected  void reload(Object collection)
          Reloads from another collection.
 void setComparator(Comparator comparator)
          Sets this collection's comparator, and resorts this collection.
protected  void sort()
          Sorts this collection.
 
Methods inherited from class net.rim.device.api.collection.util.BigUnsortedReadableList
addCollectionListener, doRemove, elementAdded, elementRemoved, elementUpdated, fireElementAdded, fireElementRemoved, fireElementUpdated, fireReset, getAt, getAt, getIndex, insertAt, loadFrom, removeCollectionListener, replaceAt, reset, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.rim.device.api.collection.SortableCollection
setComparator
 
Methods inherited from interface net.rim.device.api.collection.CollectionListener
elementAdded, elementRemoved, elementUpdated, reset
 



Constructor Detail

BigSortedReadableList

public BigSortedReadableList(Comparator comparator)
Constructs a new BigSortedReadableList instance.

Parameters:
comparator - Comparator to use for ordering the elements.
Since:
BlackBerry API 4.0.2

BigSortedReadableList

public BigSortedReadableList(CollectionEventSource sourceCollection,
                             Comparator comparator)
Constructs a new BigSortedReadableList instance and initialize with source.

Use this constructor to build a collection that reads its initial contents from another.

Parameters:
sourceCollection - Collection used as the initial source of data for this collection.
comparator - Comparator to use for ordering elements.
Since:
BlackBerry API 4.0.2


Method Detail

getComparator

public Comparator getComparator()
Retrieves this collection's comparator object.

Specified by:
getComparator in interface SortableCollection
Returns:
Comparator for this collection.

setComparator

public void setComparator(Comparator comparator)
Sets this collection's comparator, and resorts this collection.

Parameters:
comparator - New comparator for sorting this collection.
Since:
BlackBerry API 4.0.2

sort

protected void sort()
Sorts this collection.

Subclasses can override this method in order to know when they are being sorted.


reload

protected void reload(Object collection)
Reloads from another collection.

Invoke this method to replace this collection's current list of elements with elements from another collection. After reloading, this method sorts this collection.

Overrides:
reload in class BigUnsortedReadableList
Parameters:
collection - Collection to use as source.

binarySearch

protected int binarySearch(Object key,
                           int startIndex,
                           int endIndex)
Does binary search to locate an element.

Parameters:
key - Element to locate.
startIndex - Position within list at which to start.
endIndex - Position after last element to include in search.
Returns:
If greater than or equal to zero, the position of the first located element matching your key; if the element does not exist in this collection, this method returns a negative integer, the absolute value of which indicates the position your element would occupy in this collection.
Throws:
ArrayIndexOutOfBoundsException - Thrown if the start and end indexes are outside the bounds of the array. Note that the method will not throw an exception when searching for a null argument in an EMPTY list.

doAdd

protected void doAdd(Object element)
Adds an element to this collection without sending an add event.

This method adds the element in the appropriate, sorted place in this collection.

Overrides:
doAdd in class BigUnsortedReadableList
Parameters:
element - Element to add.

doUpdate

protected boolean doUpdate(Object oldElement,
                           Object newElement)
Updates an element in this collection without sending an update element.

Since this method sends no event, the update operation must either not affect the sort order of this list, or you must synchronize around this method and an invocation of BigSortedReadableList.sort().

Overrides:
doUpdate in class BigUnsortedReadableList
Parameters:
oldElement - Old element to replace.
newElement - New element to take old element's place.
Returns:
True if an update to this collection occured; false if the old element does not exist in this collection.





Copyright 1999-2010 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. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.