Class SeparatorList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.SeparatorList<E>
-
- All Implemented Interfaces:
ListEventListener<E>,EventList<E>,java.lang.Iterable<E>,java.util.Collection<E>,java.util.EventListener,java.util.List<E>
public class SeparatorList<E> extends TransformedList<E,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, callingTransformedList.add(int, Object),TransformedList.set(int, Object)orTransformedList.remove(int)with a an index that actually corresponds to a separator in this list will produce anIllegalArgumentException. 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
EventListfor 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
Nested Classes Modifier and Type Class Description static interfaceSeparatorList.Separator<E>A separator heading the elements of a group.
-
Field Summary
-
Fields inherited from class ca.odell.glazedlists.TransformedList
source
-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Constructor Summary
Constructors Constructor Description SeparatorList(EventList<E> source, java.util.Comparator<? super E> comparator, int minimumSizeForSeparator, int defaultLimit)Construct a SeparatorList overtop of thesourcelist by using the givencomparatorto compute groups of similar source items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Releases the resources consumed by thisTransformedListso that it may eventually be garbage collected.protected intgetSourceIndex(int mutationIndex)Gets the index in the sourceEventListthat corresponds to the specified index.protected booleanisWritable()Gets whether the sourceEventListis writable via this API.voidlistChanged(ListEvent<E> listChanges)When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.voidsetComparator(java.util.Comparator<E> comparator)Set theComparatorused to determine how elements are split into groups.intsize()Returns the number of elements in this list.-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, get, remove, removeAll, retainAll, set
-
Methods inherited from class ca.odell.glazedlists.AbstractEventList
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
SeparatorList
public SeparatorList(EventList<E> source, java.util.Comparator<? super E> comparator, int minimumSizeForSeparator, int defaultLimit)
Construct a SeparatorList overtop of thesourcelist by using the givencomparatorto compute groups of similar source items. For each group a single separator will be present in this SeparatorList provided the group contains at least theminimumSizeForSeparatornumber of items (otherwise they are left without a separator). In addition this SeparatorList will never show more than thedefaultLimitnumber of group elements from any given group.- Parameters:
source- the list containing the raw items to be groupedcomparator- the Comparator which defines the grouping logicminimumSizeForSeparator- the number of elements which must exist in a group in order for a separator to be createddefaultLimit- the maximum number of element to display for a group; extra elements are truncated
-
-
Method Detail
-
size
public int size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
-
getSourceIndex
protected int getSourceIndex(int mutationIndex)
Gets the index in the sourceEventListthat corresponds to the specified index. More formally, returns the index such thatthis.get(i) == source.get(getSourceIndex(i))for all legal values ofi.- Overrides:
getSourceIndexin classTransformedList<E,E>
-
isWritable
protected boolean isWritable()
Gets whether the sourceEventListis writable via this API.Extending classes must override this method in order to make themselves writable.
- Specified by:
isWritablein classTransformedList<E,E>
-
setComparator
public void setComparator(java.util.Comparator<E> comparator)
Set theComparatorused to determine how elements are split into groups.Performance Note: sorting will take
O(N * Log N)time.Warning: This method is thread ready but not thread safe. See
EventListfor an example of thread safe code.
-
listChanged
public void listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.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.
- Specified by:
listChangedin interfaceListEventListener<E>- Specified by:
listChangedin classTransformedList<E,E>- Parameters:
listChanges- aListEventdescribing the changes to the list
-
dispose
public void dispose()
Releases the resources consumed by thisTransformedListso that it may eventually be garbage collected.A
TransformedListwill be garbage collected without a call toTransformedList.dispose(), but not before its sourceEventListis garbage collected. By callingTransformedList.dispose(), you allow theTransformedListto be garbage collected before its sourceEventList. This is necessary for situations where aTransformedListis short-lived but its sourceEventListis long-lived.Warning: It is an error to call any method on a
TransformedListafter it has been disposed.
-
-