Class FunctionList<S,​E>

  • All Implemented Interfaces:
    ListEventListener<S>, EventList<E>, java.lang.Iterable<E>, java.util.Collection<E>, java.util.EventListener, java.util.List<E>, java.util.RandomAccess

    public final class FunctionList<S,​E>
    extends TransformedList<S,​E>
    implements java.util.RandomAccess
    This List is meant to simplify the task of transforming each element of a source list to an element stored at the same index in this FunctionList. The logic of precisely how to transform the source elements is contained within a FunctionList.Function that must be supplied at the time of construction but can be changed afterward using setForwardFunction(ca.odell.glazedlists.FunctionList.Function<S, E>). This FunctionList.Function is called the forward function because it creates elements in this FunctionList from elements that have been added or mutated within the source list. The forward function may be an implementation of either FunctionList.Function or FunctionList.AdvancedFunction.

    An optional reverse FunctionList.Function which is capable of mapping the elements of this FunctionList back to the corresponding source element may be supplied in order to use the following mutating methods:

    If the reverse FunctionList.Function is not supplied then callers of those methods will receive an IllegalStateException explaining that those operations are not available without the reverse FunctionList.Function.

    If specified, the reverse FunctionList.Function should do its best to maintain the invariant:

    o.equals(reverseFunction.evaluate(forwardFunction.evaluate(o))) for any o that is non-null.

    Note: if two source elements share the same identity (i.e. source.get(i) == source.get(j) when i != j), it is up to author of the FunctionList.Function to decide if and how to preserve the relationship of their identities after their transformation.

    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(1), writes O(1) amortized
    Memory:
    Unit Tests:FunctionList
    Issues: 282
    • Method Detail

      • 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<S,​E>
      • listChanged

        public void listChanged​(ListEvent<S> 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<S>
        Specified by:
        listChanged in class TransformedList<S,​E>
        Parameters:
        listChanges - a ListEvent describing the changes to the list
      • get

        public E get​(int index)
        Returns the element at the specified position in this list.
        Specified by:
        get in interface java.util.List<S>
        Overrides:
        get in class TransformedList<S,​E>
        Parameters:
        index - index of element to return.
        Returns:
        the element at the specified position in this list.
      • remove

        public E remove​(int index)
        Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
        Specified by:
        remove in interface java.util.List<S>
        Overrides:
        remove in class TransformedList<S,​E>
        Parameters:
        index - the index of the element to removed.
        Returns:
        the element previously at the specified position.
      • set

        public E set​(int index,
                     E value)
        Replaces the element at the specified position in this list with the specified element (optional operation).
        Specified by:
        set in interface java.util.List<S>
        Overrides:
        set in class TransformedList<S,​E>
        Parameters:
        index - index of element to replace.
        value - element to be stored at the specified position.
        Returns:
        the element previously at the specified position.
      • add

        public void add​(int index,
                        E value)
        Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
        Specified by:
        add in interface java.util.List<S>
        Overrides:
        add in class TransformedList<S,​E>
        Parameters:
        index - index at which the specified element is to be inserted.
        value - element to be inserted.