ca.odell.glazedlists

Class SeparatorList<E>

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

public class SeparatorList<E>
extends TransformedList<S,E>

A list that adds separator objects before each group of elements.

SeparatorList is writable, however, attempts to write over separators will always produce an IllegalArgumentException. For example, calling add(int, Object), set(int, Object) or remove(int) with a an index that actually corresponds to a separator in this list will produce an IllegalArgumentException. This is because there is no corresponding index for separators in the source list; separators are added by this SeparatorList. All index-based write operations must be performed on indexes known to correspond to non-separator elements.

Warning: this class won't work very well with generics because separators are mixed in, which will be a different class than the other list elements.

Warning: This class is thread ready but not thread safe. See EventList for an example of thread safe code.

Developer Preview this class is still under heavy development and subject to API changes. It's also really slow at the moment and won't scale to lists of size larger than a hundred or so efficiently.

Author:
Jesse Wilson

Nested Class Summary

static interface
SeparatorList.Separator
A separator heading the elements of a group.

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

SeparatorList(EventList source, E> comparator, int minimumSizeForSeparator, int defaultLimit)
Construct a SeparatorList overtop of the source list by using the given comparator to compute groups of similar source items.

Method Summary

protected int
getSourceIndex(int mutationIndex)
protected boolean
isWritable()
void
listChanged(ListEvent listChanges)
void
setComparator(Comparator comparator)
Set the Comparator used to determine how elements are split into groups.
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

SeparatorList

public SeparatorList(EventList source,
                     E> comparator,
                     int minimumSizeForSeparator,
                     int defaultLimit)
Construct a SeparatorList overtop of the source list by using the given comparator to compute groups of similar source items. For each group a single separator will be present in this SeparatorList provided the group contains at least the minimumSizeForSeparator number of items (otherwise they are left without a separator). In addition this SeparatorList will never show more than the defaultLimit number of group elements from any given group.
Parameters:
source - the list containing the raw items to be grouped
comparator - the Comparator which defines the grouping logic
minimumSizeForSeparator - the number of elements which must exist in a group in order for a separator to be created
defaultLimit - the maximum number of element to display for a group; extra elements are truncated

Method Details

getSourceIndex

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

isWritable

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

listChanged

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

setComparator

public void setComparator(Comparator comparator)

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