Package com.topjohnwu.superuser
Class CallbackList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
com.topjohnwu.superuser.CallbackList<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
An
AbstractList
that calls onAddElement
when a new element is added to the list.
To simplify the API of Shell
, both STDOUT and STDERR will output to List
s.
This class is useful if you want to trigger a callback every time Shell
outputs a new line.
The CallbackList
itself does not have a data store. If you need one, you can provide a
base List
, and this class will delegate its calls to it.
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ModifierConstructorDescriptionprotected
onAddElement(Object)
runs on the main thread; no backing list.protected
CallbackList
(Executor executor) onAddElement(Object)
runs with the executor; no backing list.protected
CallbackList
(Executor executor, List<E> base) onAddElement(Object)
runs with the executor; sets a backing list.protected
CallbackList
(List<E> base) onAddElement(Object)
runs on the main thread; sets a backing list. -
Method Summary
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
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
-
Field Details
-
mBase
-
mExecutor
-
-
Constructor Details
-
CallbackList
protected CallbackList()onAddElement(Object)
runs on the main thread; no backing list. -
CallbackList
onAddElement(Object)
runs on the main thread; sets a backing list. -
CallbackList
onAddElement(Object)
runs with the executor; no backing list. -
CallbackList
onAddElement(Object)
runs with the executor; sets a backing list.
-
-
Method Details
-
onAddElement
The callback when a new element is added.This method will be called after
add
is called. Which thread it runs on depends on which constructor is used to construct the instance.- Parameters:
e
- the new element added to the list.
-
get
-
set
-
add
-
remove
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
- See Also:
-