Package com.firebase.ui.common
Class BaseObservableSnapshotArray<S,E,L extends BaseChangeEventListener<S,E>,T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<T>
-
- com.firebase.ui.common.BaseObservableSnapshotArray<S,E,L,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:
Iterable<T>,Collection<T>,List<T>
public abstract class BaseObservableSnapshotArray<S,E,L extends BaseChangeEventListener<S,E>,T> extends AbstractList<T>
Exposes a collection ofBaseObservableSnapshotArrayitems in a database as aListofBaseObservableSnapshotArrayobjects. To observe the list, attach anBaseObservableSnapshotArraylistener.
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description BaseObservableSnapshotArray(BaseCachingSnapshotParser<S,T> parser)Create an BaseObservableSnapshotArray with a customBaseSnapshotParser.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description LaddChangeEventListener(L listener)Attach aBaseChangeEventListenerto this array.voidclear()Clear data and notify all listeners.Tget(int index)SgetSnapshot(int index)Returns the snapshot at the specified position in this list.protected abstract List<S>getSnapshots()Get the list of snapshots mirroring the server's data.booleanisListening()booleanisListening(L listener)protected voidnotifyOnChildChanged(ChangeEventType type, S snapshot, int newIndex, int oldIndex)protected voidnotifyOnDataChanged()protected voidnotifyOnError(E e)protected voidonCreate()Called when theBaseObservableSnapshotArrayis active and should start listening to the Firebase database.protected voidonDestroy()Called when theBaseObservableSnapshotArrayis inactive and should stop listening to the Firebase database.voidremoveAllListeners()Remove all listeners from the array and reset its state.voidremoveChangeEventListener(L listener)Remove a listener from the array.intsize()-
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.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
BaseObservableSnapshotArray
public BaseObservableSnapshotArray(@NonNull BaseCachingSnapshotParser<S,T> parser)Create an BaseObservableSnapshotArray with a customBaseSnapshotParser.- Parameters:
parser- theBaseSnapshotParserto use
-
-
Method Detail
-
getSnapshots
@NonNull protected abstract 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)
-
size
public int size()
- Specified by:
sizein interfaceCollection<S>- Specified by:
sizein interfaceList<S>- Specified by:
sizein classAbstractCollection<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:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
addChangeEventListener
@CallSuper @NonNull public L addChangeEventListener(@NonNull L listener)
Attach aBaseChangeEventListenerto this array. The listener will receive oneChangeEventType.ADDEDevent for each item that already exists in the array at the time of attachment, aBaseChangeEventListener.onDataChanged()event if one has occurred, and then receive all future child events.If this is the first listener,
onCreate()will be called.
-
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 theBaseObservableSnapshotArrayis active and should start listening to the Firebase database.
-
onDestroy
@CallSuper protected void onDestroy()
Called when theBaseObservableSnapshotArrayis 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:
clearin interfaceCollection<S>- Specified by:
clearin interfaceList<S>- Overrides:
clearin classAbstractList<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)
-
-