Class FilterList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.FilterList<E>
-
- All Implemented Interfaces:
ListEventListener<E>,EventList<E>,java.lang.Iterable<E>,java.util.Collection<E>,java.util.EventListener,java.util.List<E>
public final class FilterList<E> extends TransformedList<E,E>
AnEventListthat shows a subset of the elements of a sourceEventList. This subset is composed of all elements of the sourceEventListthat match the filter.The filter can be static or dynamic. Changing the behaviour of the filter will change which elements of the source list are included.
Warning: This class breaks the contract required by
List. SeeEventListfor an example.Warning: This class is thread ready but not thread safe. See
EventListfor 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), filter changes O(N) Memory: 0 to 26 bytes per element Unit Tests: N/A Issues: 1 2 7 46 187 254 312 - Author:
- Jesse Wilson, James Lemieux
-
-
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 FilterList(EventList<E> source)Creates aFilterListthat includes a subset of the specified sourceEventList.FilterList(EventList<E> source, Matcher<? super E> matcher)Convenience constructor for creating aFilterListand setting itsMatcher.FilterList(EventList<E> source, MatcherEditor<? super E> matcherEditor)Convenience constructor for creating aFilterListand setting itsMatcherEditor.
-
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.voidsetMatcher(Matcher<? super E> matcher)Set theMatcherwhich specifies which elements shall be filtered.voidsetMatcherEditor(MatcherEditor<? super E> editor)Set theMatcherEditorwhich provides a dynamicMatcherto determine which elements shall be filtered.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
-
FilterList
public FilterList(EventList<E> source)
Creates aFilterListthat includes a subset of the specified sourceEventList.
-
FilterList
public FilterList(EventList<E> source, Matcher<? super E> matcher)
Convenience constructor for creating aFilterListand setting itsMatcher.
-
FilterList
public FilterList(EventList<E> source, MatcherEditor<? super E> matcherEditor)
Convenience constructor for creating aFilterListand setting itsMatcherEditor.
-
-
Method Detail
-
setMatcher
public void setMatcher(Matcher<? super E> matcher)
Set theMatcherwhich specifies which elements shall be filtered.This will remove the current
MatcherorMatcherEditorand refilter the entire list.
-
setMatcherEditor
public void setMatcherEditor(MatcherEditor<? super E> editor)
Set theMatcherEditorwhich provides a dynamicMatcherto determine which elements shall be filtered.This will remove the current
MatcherorMatcherEditorand refilter the entire list.
-
dispose
public void dispose()
Description copied from class:TransformedListReleases 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.
-
listChanged
public final 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
-
size
public final 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 final 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>
-
-