public final class CompositeDisposable extends Object implements Disposable, DisposableContainer
Disposable
s and
offers O(1) time complexity for add(Disposable)
, remove(Disposable)
and delete(Disposable)
operations.Constructor and Description |
---|
CompositeDisposable()
Creates an empty
CompositeDisposable . |
CompositeDisposable(Disposable... disposables)
Creates a
CompositeDisposable with the given array of initial Disposable elements. |
CompositeDisposable(@NonNull Iterable<? extends Disposable> disposables)
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(@NonNull Disposable disposable)
Adds a
Disposable to this container or disposes it if the
container has been disposed. |
boolean |
addAll(Disposable... disposables)
Atomically adds the given array of
Disposable s to the container or
disposes them all if the container has been disposed. |
void |
clear()
Atomically clears the container, then disposes all the previously contained
Disposable s. |
boolean |
delete(@NonNull Disposable disposable)
Removes (but does not dispose) the given
Disposable if it is part of this
container. |
void |
dispose()
Dispose the resource, the operation should be idempotent.
|
boolean |
isDisposed()
Returns true if this resource has been disposed.
|
boolean |
remove(@NonNull Disposable disposable)
Removes and disposes the given
Disposable if it is part of this
container. |
int |
size()
Returns the number of currently held
Disposable s. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
disposed, empty, fromAction, fromAutoCloseable, fromFuture, fromFuture, fromRunnable, fromSubscription, toAutoCloseable
public CompositeDisposable()
CompositeDisposable
.public CompositeDisposable(@NonNull Disposable... disposables)
CompositeDisposable
with the given array of initial Disposable
elements.disposables
- the array of Disposable
s to start withNullPointerException
- if disposables
or any of its array items is null
public CompositeDisposable(@NonNull @NonNull Iterable<? extends Disposable> disposables)
disposables
- the Iterable
sequence of Disposable
to start withNullPointerException
- if disposables
or any of its items is null
public void dispose()
Disposable
dispose
in interface Disposable
public boolean isDisposed()
Disposable
isDisposed
in interface Disposable
public boolean add(@NonNull @NonNull Disposable disposable)
Disposable
to this container or disposes it if the
container has been disposed.add
in interface DisposableContainer
disposable
- the Disposable
to add, not null
true
if successful, false
if this container has been disposedNullPointerException
- if disposable
is null
public boolean addAll(@NonNull Disposable... disposables)
Disposable
s to the container or
disposes them all if the container has been disposed.disposables
- the array of Disposable
strue
if the operation was successful, false
if the container has been disposedNullPointerException
- if disposables
or any of its array items is null
public boolean remove(@NonNull @NonNull Disposable disposable)
Disposable
if it is part of this
container.remove
in interface DisposableContainer
disposable
- the disposable to remove and dispose, not null
true
if the operation was successfulNullPointerException
- if disposable
is null
public boolean delete(@NonNull @NonNull Disposable disposable)
Disposable
if it is part of this
container.delete
in interface DisposableContainer
disposable
- the disposable to remove, not null
true
if the operation was successfulNullPointerException
- if disposable
is null
public void clear()
Disposable
s.public int size()
Disposable
s.Disposable
s