Class BaseObservableSnapshotArray<S,​E,​L extends BaseChangeEventListener<S,​E>,​T>

  • Type Parameters:
    S - the snapshot class.
    E - the error type raised for the listener.
    L - the listener class.
    T - the model object class.
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

    public abstract class BaseObservableSnapshotArray<S,​E,​L extends BaseChangeEventListener<S,​E>,​T>
    extends java.util.AbstractList<T>
    Exposes a collection of BaseObservableSnapshotArray items in a database as a List of BaseObservableSnapshotArray objects. To observe the list, attach an BaseObservableSnapshotArray listener.
    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      L addChangeEventListener​(L listener)
      Attach a BaseChangeEventListener to this array.
      void clear()
      Clear data and notify all listeners.
      T get​(int index)  
      S getSnapshot​(int index)
      Returns the snapshot at the specified position in this list.
      protected abstract java.util.List<S> getSnapshots()
      Get the list of snapshots mirroring the server's data.
      boolean isListening()  
      boolean isListening​(L listener)  
      protected void notifyOnChildChanged​(ChangeEventType type, S snapshot, int newIndex, int oldIndex)  
      protected void notifyOnDataChanged()  
      protected void notifyOnError​(E e)  
      protected void onCreate()
      Called when the BaseObservableSnapshotArray is active and should start listening to the Firebase database.
      protected void onDestroy()
      Called when the BaseObservableSnapshotArray is inactive and should stop listening to the Firebase database.
      void removeAllListeners()
      Remove all listeners from the array and reset its state.
      void removeChangeEventListener​(L listener)
      Remove a listener from the array.
      int size()  
      • Methods inherited from class java.util.AbstractList

        add, add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Method Detail

      • getSnapshots

        @NonNull
        protected abstract java.util.List<S> getSnapshots()
        Get the list of snapshots mirroring the server's data. Must be mutable and use a single instance over the lifetime of this class's active lifecycle.
        Returns:
        the local copy of the server's snapshots
      • get

        @NonNull
        public T get​(int index)
        Specified by:
        get in interface java.util.List<S>
        Specified by:
        get in class java.util.AbstractList<T>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<S>
        Specified by:
        size in interface java.util.List<S>
        Specified by:
        size in class java.util.AbstractCollection<T>
      • getSnapshot

        @NonNull
        public S getSnapshot​(int index)
        Returns the snapshot at the specified position in this list.
        Parameters:
        index - index of the snapshot to return
        Returns:
        the snapshot at the specified position in this list
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • removeChangeEventListener

        @CallSuper
        public void removeChangeEventListener​(@NonNull
                                              L listener)
        Remove a listener from the array.

        If no listeners remain, onDestroy() will be called.

      • removeAllListeners

        @CallSuper
        public void removeAllListeners()
        Remove all listeners from the array and reset its state.
      • onCreate

        @CallSuper
        protected void onCreate()
        Called when the BaseObservableSnapshotArray is active and should start listening to the Firebase database.
      • onDestroy

        @CallSuper
        protected void onDestroy()
        Called when the BaseObservableSnapshotArray is inactive and should stop listening to the Firebase database.

        All data and saved state should also be cleared here.

      • isListening

        public boolean isListening()
        Returns:
        true if the array is listening for change events from the Firebase database, false otherwise
      • isListening

        public boolean isListening​(@NonNull
                                   L listener)
        Returns:
        true if the provided listener is listening for changes
      • clear

        public void clear()
        Clear data and notify all listeners.
        Specified by:
        clear in interface java.util.Collection<S>
        Specified by:
        clear in interface java.util.List<S>
        Overrides:
        clear in class java.util.AbstractList<T>
      • notifyOnChildChanged

        protected final void notifyOnChildChanged​(@NonNull
                                                  ChangeEventType type,
                                                  @NonNull
                                                  S snapshot,
                                                  int newIndex,
                                                  int oldIndex)
      • notifyOnDataChanged

        protected final void notifyOnDataChanged()
      • notifyOnError

        protected final void notifyOnError​(@NonNull
                                           E e)