Class FreezableList<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 FreezableList<E>
    extends TransformedList<E,​E>
    An EventList that shows the current contents of its source EventList.

    When this EventList is frozen, changes to its source EventList will not be reflected. Instead, the FreezableList will continue to show the state of its source EventList at the time it was frozen.

    When this EventList is thawed, changes to its source EventList will be reflected.

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

    EventList Overview
    Writable:writable when thawed (default), not writable when frozen
    Concurrency:thread ready, not thread safe
    Performance:reads: O(1), writes O(1), freezes O(N)
    Memory:frozen: 4 bytes per element, thawed: 0 bytes per element
    Unit Tests:N/A
    Issues:N/A
    Issues:
    Author:
    Jesse Wilson
    • Method Detail

      • get

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

        public boolean isFrozen()
        Gets whether this EventList is showing a previous state of the source EventList.
        Returns:
        true if this list is showing a previous state of the source EventList or false if this is showing the current state of the source EventList.
      • freeze

        public void freeze()
        Locks this FreezableList on the current state of the source EventList. While frozen, changes to the source EventList will not be reflected by this list.

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

      • thaw

        public void thaw()
        Unlocks this FreezableList to show the same contents of the source EventList. When thawed, changes to the source EventList will be reflected by this list.

        Warning: This method is thread ready but not thread safe. See EventList for 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:
        listChanged in interface ListEventListener<E>
        Specified by:
        listChanged in class TransformedList<E,​E>
        Parameters:
        listChanges - a ListEvent describing the changes to the list