|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.util.base.glazedlists.AbstractEventList<E> com.levigo.util.base.glazedlists.TransformedList<E,List<E>> com.levigo.util.base.glazedlists.GroupingList<E>
public final class GroupingList<E>
A grouping list contains elements which are themselves Lists. Those Lists are infact elements of the source list which have been grouped together into a List. The logic of how to group the source elements is specified via a Comparator. Elements for which the Comparator returns 0 are guaranteed to be contained within the same group within this GroupingList. This implies that source elements may only participate in a single group within this GroupingList.
Further transformations may be layered on top of this GroupingList to transform the group lists into any other desirable form.
Warning: This class is thread ready but not thread
safe. See EventList
for an example of thread safe code.
EventList Overview | |
Writable: | yes |
Concurrency: | thread ready, not thread safe |
Performance: | reads: O(log N), writes O(log N) |
Memory: | |
Unit Tests: | GroupingListTest |
Issues: | 281 |
Field Summary |
---|
Fields inherited from class com.levigo.util.base.glazedlists.TransformedList |
---|
source |
Fields inherited from class com.levigo.util.base.glazedlists.AbstractEventList |
---|
publisher, readWriteLock, updates |
Constructor Summary | |
---|---|
GroupingList(EventList<E> source)
Creates a GroupingList that determines groupings via the
Comparable interface which all elements of the source
are assumed to implement. |
|
GroupingList(EventList<E> source,
Comparator<? super E> comparator)
Creates a GroupingList that determines groups using the specified
Comparator . |
Method Summary | ||
---|---|---|
void |
add(int index,
List<E> value)
This version of add will distribute all elements within the given value List into groups. |
|
static
|
create(EventList<E> source)
Creates a GroupingList that determines groupings via the
Comparable interface which all elements of the source
are assumed to implement. |
|
void |
dispose()
Releases the resources consumed by this TransformedList so that it
may eventually be garbage collected. |
|
List<E> |
get(int index)
Returns the element at the specified position in this list. |
|
protected int |
getSourceIndex(int index)
Gets the index in the source EventList that corresponds to the
specified index. |
|
int |
indexOfGroup(E groupElement)
Return the index of the group to which the groupElement
would belong if it were hypothetically added to the source list. |
|
protected boolean |
isWritable()
Gets whether the source EventList is writable via this API. |
|
void |
listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary. |
|
List<E> |
remove(int index)
Removes the element at the specified position in this list (optional operation). |
|
List<E> |
set(int index,
List<E> value)
Replaces the element at the specified position in this list with the specified element (optional operation). |
|
void |
setComparator(Comparator<? super E> comparator)
Change the Comparator which determines the groupings presented
by this List |
|
int |
size()
Returns the number of elements in this list. |
Methods inherited from class com.levigo.util.base.glazedlists.TransformedList |
---|
addAll, clear, removeAll, retainAll |
Methods inherited from class com.levigo.util.base.glazedlists.AbstractEventList |
---|
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GroupingList(EventList<E> source)
GroupingList
that determines groupings via the
Comparable
interface which all elements of the source
are assumed to implement.
Usage of factory method create(EventList)
is preferable.
public GroupingList(EventList<E> source, Comparator<? super E> comparator)
GroupingList
that determines groups using the specified
Comparator
.
source
- the EventList
containing elements to be groupedcomparator
- the Comparator
used to determine groupingsMethod Detail |
---|
public static <E extends Comparable<? super E>> GroupingList<E> create(EventList<E> source)
GroupingList
that determines groupings via the
Comparable
interface which all elements of the source
are assumed to implement.
public int indexOfGroup(E groupElement)
groupElement
would belong if it were hypothetically added to the source list. Note
that groupElement
does NOT have to exist
in a group. This method is essentially a convenient way to locate a
group based on a prototypical element of that group.
groupElement
- a prototype element of the group to locate
groupElement
if it were added to the source list or -1
if no
currently existing group would contain the groupElement
public void setComparator(Comparator<? super E> comparator)
Comparator
which determines the groupings presented
by this List
comparator
- the Comparator
used to determine groupings;
null will be treated as GlazedLists.comparableComparator()
protected int getSourceIndex(int index)
EventList
that corresponds to the
specified index. More formally, returns the index such that
this.get(i) == source.get(getSourceIndex(i))
for all
legal values of i
.
getSourceIndex
in class TransformedList<E,List<E>>
protected boolean isWritable()
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList<E,List<E>>
public void listChanged(ListEvent<E> listChanges)
It is mandatory that the calling thread has obtained the write lock on the source list. This is because the calling thread will have written to the source list to cause this event. This condition guarantees that no writes can occur while the listener is handling this event. It is an error to write to the source list while processing an event.
listChanged
in interface ListEventListener<E>
listChanged
in class TransformedList<E,List<E>>
public List<E> get(int index)
get
in interface List<List<E>>
get
in class TransformedList<E,List<E>>
index
- index of element to return.
public List<E> remove(int index)
remove
in interface List<List<E>>
remove
in class TransformedList<E,List<E>>
index
- the index of the element to removed.
public List<E> set(int index, List<E> value)
set
in interface List<List<E>>
set
in class TransformedList<E,List<E>>
index
- index of element to replace.value
- element to be stored at the specified position.
public void add(int index, List<E> value)
value
List into groups. Existing groups will be reused and
new groups will be created as needed. As such, the index
argument is meaningless.
Warning: This method
breaks the contract required by List.add(int, Object)
.
add
in interface List<List<E>>
add
in class TransformedList<E,List<E>>
index
- index at which the specified element is to be inserted.value
- element to be inserted.public int size()
size
in interface Collection<List<E>>
size
in interface List<List<E>>
size
in class TransformedList<E,List<E>>
public void dispose()
TransformedList
so that it
may eventually be garbage collected.
A TransformedList
will be garbage collected without a call to
TransformedList.dispose()
, but not before its source EventList
is garbage
collected. By calling TransformedList.dispose()
, you allow the TransformedList
to be garbage collected before its source EventList
. This is
necessary for situations where a TransformedList
is short-lived but
its source EventList
is long-lived.
Warning: It is an error
to call any method on a TransformedList
after it has been disposed.
dispose
in interface EventList<List<E>>
dispose
in class TransformedList<E,List<E>>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |