Class 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>
    An EventList that shows a subset of the elements of a source EventList. This subset is composed of all elements of the source EventList that 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. See EventList for an example.

    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), 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
    • Method Detail

      • setMatcher

        public void setMatcher​(Matcher<? super E> matcher)
        Set the Matcher which specifies which elements shall be filtered.

        This will remove the current Matcher or MatcherEditor and refilter the entire list.

      • setMatcherEditor

        public void setMatcherEditor​(MatcherEditor<? super E> editor)
        Set the MatcherEditor which provides a dynamic Matcher to determine which elements shall be filtered.

        This will remove the current Matcher or MatcherEditor and refilter the entire list.

      • 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:
        listChanged in interface ListEventListener<E>
        Specified by:
        listChanged in class TransformedList<E,​E>
        Parameters:
        listChanges - a ListEvent describing 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.
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Overrides:
        size in class TransformedList<E,​E>
        Returns:
        the number of elements in this list.
      • getSourceIndex

        protected final int getSourceIndex​(int mutationIndex)
        Gets the index in the source 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.
        Overrides:
        getSourceIndex in class TransformedList<E,​E>
      • isWritable

        protected boolean isWritable()
        Gets whether the source EventList is writable via this API.

        Extending classes must override this method in order to make themselves writable.

        Specified by:
        isWritable in class TransformedList<E,​E>