ca.odell.glazedlists

Class GroupingList<E>

Implemented Interfaces:
EventListener, EventList<E>, List, ListEventListener<E>

public final class GroupingList<E>
extends TransformedList<S,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
Author:
James Lemieux

Field Summary

Fields inherited from class ca.odell.glazedlists.TransformedList<S,E>

source

Fields inherited from class ca.odell.glazedlists.AbstractEventList<E>

publisher, readWriteLock, updates

Constructor Summary

GroupingList(EventList source)
Creates a GroupingList that determines groupings via the Comparable interface which all elements of the source are assumed to implement.
GroupingList(EventList source, E> comparator)
Creates a GroupingList that determines groups using the specified Comparator.

Method Summary

void
add(int index, List value)
This version of add will distribute all elements within the given value List into groups.
void
dispose()
static
extends Comparable> GroupingList create(EventList source)
Creates a GroupingList that determines groupings via the Comparable interface which all elements of the source are assumed to implement.
List
get(int index)
protected int
getSourceIndex(int 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()
void
listChanged(ListEvent listChanges)
List
remove(int index)
List
set(int index, List value)
void
setComparator(E> comparator)
Change the Comparator which determines the groupings presented by this List
int
size()

Methods inherited from class ca.odell.glazedlists.TransformedList<S,E>

add, addAll, clear, dispose, get, getSourceIndex, isWritable, listChanged, remove, removeAll, retainAll, set, size

Methods inherited from class ca.odell.glazedlists.AbstractEventList<E>

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

Constructor Details

GroupingList

public GroupingList(EventList source)
Creates a 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.


GroupingList

public GroupingList(EventList source,
                    E> comparator)
Creates a GroupingList that determines groups using the specified Comparator.
Parameters:
source - the EventList containing elements to be grouped
comparator - the Comparator used to determine groupings

Method Details

add

public void add(int index,
                List value)
This version of add will distribute all elements within the given 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).


dispose

public void dispose()
Specified by:
dispose in interface EventList<E>
Overrides:
dispose in interface TransformedList<S,E>

extends Comparable> GroupingList create

public static > GroupingList create(EventList source)
Creates a GroupingList that determines groupings via the Comparable interface which all elements of the source are assumed to implement.

get

public List get(int index)
Overrides:
get in interface TransformedList<S,E>

getSourceIndex

protected int getSourceIndex(int index)
Overrides:
getSourceIndex in interface TransformedList<S,E>

indexOfGroup

public 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. 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.
Parameters:
groupElement - a prototype element of the group to locate
Returns:
the index of the group that would contain groupElement if it were added to the source list or -1 if no currently existing group would contain the groupElement

isWritable

protected boolean isWritable()
Overrides:
isWritable in interface TransformedList<S,E>

listChanged

public void listChanged(ListEvent listChanges)
Specified by:
listChanged in interface ListEventListener<E>

remove

public List remove(int index)
Overrides:
remove in interface TransformedList<S,E>

set

public List set(int index,
                   List value)

setComparator

public void setComparator(E> comparator)
Change the Comparator which determines the groupings presented by this List
Parameters:
comparator - the Comparator used to determine groupings; null will be treated as GlazedLists.comparableComparator()

size

public int size()
Overrides:
size in interface TransformedList<S,E>

Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2009-07-14 22:05