Class ObservableList<E>

  • Type Parameters:
    E - the type of the elements in this list
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, IObservable, IObservableCollection<E>, IObservableList<E>
    Direct Known Subclasses:
    WritableList

    public abstract class ObservableList<E>
    extends AbstractObservable
    implements IObservableList<E>
    Abstract implementation of IObservableList, based on an underlying regular list.

    This class is thread safe. All state accessing methods must be invoked from the current realm. Methods for adding and removing listeners may be invoked from any thread.

    Since:
    1.0
    • Field Detail

      • wrappedList

        protected java.util.List<E> wrappedList
    • Constructor Detail

      • ObservableList

        protected ObservableList​(java.util.List<E> wrappedList,
                                 java.lang.Object elementType)
      • ObservableList

        protected ObservableList​(Realm realm,
                                 java.util.List<E> wrappedList,
                                 java.lang.Object elementType)
    • Method Detail

      • addListChangeListener

        public void addListChangeListener​(IListChangeListener<? super E> listener)
        Description copied from interface: IObservableList
        Adds the given list change listener to the list of list change listeners.
        Specified by:
        addListChangeListener in interface IObservableList<E>
        Parameters:
        listener - the change listener to add; not null
      • removeListChangeListener

        public void removeListChangeListener​(IListChangeListener<? super E> listener)
        Description copied from interface: IObservableList
        Removes the given list change listener from the list of list change listeners. Has no effect if the given listener is not registered as a list change listener.
        Specified by:
        removeListChangeListener in interface IObservableList<E>
        Parameters:
        listener - the change listener to remove; not null
      • fireListChange

        protected void fireListChange​(ListDiff<E> diff)
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface IObservableList<E>
        Specified by:
        contains in interface java.util.List<E>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface IObservableList<E>
        Specified by:
        containsAll in interface java.util.List<E>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface IObservableList<E>
        Specified by:
        equals in interface java.util.List<E>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface IObservableList<E>
        Specified by:
        hashCode in interface java.util.List<E>
        Overrides:
        hashCode in class java.lang.Object
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface IObservableList<E>
        Specified by:
        isEmpty in interface java.util.List<E>
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface IObservableList<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface IObservableList<E>
        Specified by:
        size in interface java.util.List<E>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface IObservableList<E>
        Specified by:
        toArray in interface java.util.List<E>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface IObservableList<E>
        Specified by:
        toArray in interface java.util.List<E>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • get

        public E get​(int index)
        Specified by:
        get in interface IObservableList<E>
        Specified by:
        get in interface java.util.List<E>
        "TrackedGetter"
      • indexOf

        public int indexOf​(java.lang.Object o)
        Specified by:
        indexOf in interface IObservableList<E>
        Specified by:
        indexOf in interface java.util.List<E>
        "TrackedGetter"
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)
        Specified by:
        lastIndexOf in interface IObservableList<E>
        Specified by:
        lastIndexOf in interface java.util.List<E>
        "TrackedGetter"
      • listIterator

        public java.util.ListIterator<E> listIterator()
        Specified by:
        listIterator in interface IObservableList<E>
        Specified by:
        listIterator in interface java.util.List<E>
        "TrackedGetter"
      • listIterator

        public java.util.ListIterator<E> listIterator​(int index)
        Specified by:
        listIterator in interface IObservableList<E>
        Specified by:
        listIterator in interface java.util.List<E>
        "TrackedGetter"
      • subList

        public java.util.List<E> subList​(int fromIndex,
                                         int toIndex)
        Specified by:
        subList in interface IObservableList<E>
        Specified by:
        subList in interface java.util.List<E>
      • getterCalled

        protected void getterCalled()
      • set

        public E set​(int index,
                     E element)
        Specified by:
        set in interface IObservableList<E>
        Specified by:
        set in interface java.util.List<E>
      • move

        public E move​(int oldIndex,
                      int newIndex)
        Moves the element located at oldIndex to newIndex. This method is equivalent to calling add(newIndex, remove(oldIndex)).

        Subclasses should override this method to deliver list change notification for the remove and add operations in the same ListChangeEvent, as this allows ListDiff.accept(ListDiffVisitor) to recognize the operation as a move.

        Specified by:
        move in interface IObservableList<E>
        Parameters:
        oldIndex - the element's position before the move. Must be within the range 0 <= oldIndex < size().
        newIndex - the element's position after the move. Must be within the range 0 <= newIndex < size().
        Returns:
        the element that was moved.
        Throws:
        java.lang.IndexOutOfBoundsException - if either argument is out of range ( 0 <= index < size()).
        Since:
        1.1
        See Also:
        ListDiffVisitor.handleMove(int, int, Object), ListDiff.accept(ListDiffVisitor)
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface IObservableList<E>
        Specified by:
        remove in interface java.util.List<E>
      • add

        public boolean add​(E o)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface IObservableList<E>
        Specified by:
        add in interface java.util.List<E>
      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface java.util.List<E>
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface IObservableList<E>
        Specified by:
        addAll in interface java.util.List<E>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface IObservableList<E>
        Specified by:
        addAll in interface java.util.List<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface IObservableList<E>
        Specified by:
        remove in interface java.util.List<E>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface IObservableList<E>
        Specified by:
        removeAll in interface java.util.List<E>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface IObservableList<E>
        Specified by:
        retainAll in interface java.util.List<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
      • isStale

        public boolean isStale()
        Returns the stale state. Must be invoked from the current realm.
        Specified by:
        isStale in interface IObservable
        Returns:
        stale state
      • setStale

        public void setStale​(boolean stale)
        Sets the stale state. Must be invoked from the current realm.
        Parameters:
        stale - The stale state to list. This will fire a stale event if the given boolean is true and this observable list was not already stale.
      • updateWrappedList

        protected void updateWrappedList​(java.util.List<E> newList)
      • addListener

        protected void addListener​(java.lang.Object listenerType,
                                   IObservablesListener listener)
        Parameters:
        listenerType - arbitrary object to identify a type of the listener
        listener - the listener to add; not null
      • removeListener

        protected void removeListener​(java.lang.Object listenerType,
                                      IObservablesListener listener)
        Parameters:
        listenerType - arbitrary object to identify a type of the listener
        listener - the listener to remove; not null
      • hasListeners

        protected boolean hasListeners()
      • firstListenerAdded

        protected void firstListenerAdded()
      • lastListenerRemoved

        protected void lastListenerRemoved()
      • getRealm

        public Realm getRealm()
        Returns:
        Returns the realm.
      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException