ca.odell.glazedlists
Class SortedList<E>
- EventListener, EventList<E>, List, ListEventListener<E>
public final class SortedList<E>
An
EventList
that shows its source
EventList
in sorted order.
The sorting strategy is specified with a
Comparator
. If no
Comparator
is specified, all of the elements of the source
EventList
must implement
Comparable
.
This
EventList
supports all write operations.
Warning: This class
breaks the contract required by
List
. See
EventList
for an example.
EventList Overview |
Writable: | yes |
Concurrency: | thread ready, not thread safe |
Performance: | reads: O(log N), writes O(log N), change comparator O(N log N) |
Memory: | 72 bytes per element |
Unit Tests: | N/A |
Issues: |
39
40
58
60
62
66
161
170
206
239
255
261
|
static int | AVOID_MOVING_ELEMENTS - Sorting mode where elements aren't moved when their value is changed,
even if this means they are no longer in perfect sorted order.
|
static int | STRICT_SORT_ORDER - Sorting mode where elements are always in sorted order, even if this
requires that elements be moved from one index to another when their
value is changed.
|
add , addAll , clear , dispose , get , getSourceIndex , isWritable , listChanged , remove , removeAll , retainAll , set , size |
T[] toArray , add , add , addAll , addAll , addListEventListener , clear , contains , containsAll , equals , get , getPublisher , getReadWriteLock , hashCode , indexOf , isEmpty , iterator , lastIndexOf , listIterator , listIterator , remove , remove , removeAll , removeListEventListener , retainAll , set , size , subList , toArray , toString |
AVOID_MOVING_ELEMENTS
public static final int AVOID_MOVING_ELEMENTS
Sorting mode where elements aren't moved when their value is changed,
even if this means they are no longer in perfect sorted order. This mode
is useful in editable lists and tables because it is annoying
for the current element to move if its value changes.
STRICT_SORT_ORDER
public static final int STRICT_SORT_ORDER
Sorting mode where elements are always in sorted order, even if this
requires that elements be moved from one index to another when their
value is changed.
SortedList
public SortedList(EventList source)
Creates a
SortedList
that sorts the specified
EventList
.
Because this constructor takes no
Comparator
argument, all
elements in the specified
EventList
must implement
Comparable
or a
ClassCastException
will be thrown.
SortedList
public SortedList(EventList source,
E> comparator)
Creates a
SortedList
that sorts the specified
EventList
using the specified
Comparator
to determine sort order. If the
specified
Comparator
is
null
, then this
List
will be unsorted.
getMode
public int getMode()
indexOfSimulated
public int indexOfSimulated(Object object)
Deprecated as of 12/11/2005. Replaced with sortIndex(Object)
which has cleaner semantics.
Returns the index in this list of the first occurrence of the specified
element, or the index where that element would be in the list if it were
inserted.
- the index in this list of the first occurrence of the specified
element, or the index where that element would be in the list if it
were inserted. This will return a value in [0, size()],
inclusive.
lastSortIndex
public int lastSortIndex(Object object)
Returns the last index of the
object
's sort location or
the last index at which the
object
could be positioned if
inserted.
Unlike
lastIndexOf(Object)
this method does not guarantee the given
object
equals
the element at
the returned index. Instead, they are indistinguishable according to the
sorting
Comparator
.
- a value in [0, size()] inclusive
setComparator
public void setComparator(E> comparator)
Set the
Comparator
in use in this
EventList
. This will
sort the
EventList
into a new order.
Performance Note: sorting will take
O(N * Log N)
time.
Warning: This method is
thread ready but not thread safe. See
EventList
for an example
of thread safe code.
comparator
- the Comparator
to specify how to sort the list. If
the source EventList
elements implement Comparable
,
you may use a GlazedLists.comparableComparator()
to sort them
in their natural order. You may also specify null
to put
this SortedList
in unsorted order.
setMode
public void setMode(int mode)
Modify the behaviour of this
SortedList
to one of the predefined modes.
sortIndex
public int sortIndex(Object object)
Returns the first index of the
object
's sort location or
the first index at which the
object
could be positioned if
inserted.
Unlike
indexOf(Object)
this method does not guarantee the given
object
equals
the element at
the returned index. Instead, they are indistinguishable according to the
sorting
Comparator
.
- a value in [0, size()] inclusive
super E> getComparator
public Comparator super E> getComparator()
Gets the Comparator
that is being used to sort this list.
- the
Comparator
in use, or null if this list is
currently unsorted. If this is an EventList
of Comparable
elements in natural order, then a ComparableComparator} will
be returned.
Glazed Lists, Copyright © 2003-2006 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2007-12-21 23:49