Class CompositeDisposable
java.lang.Object
io.reactivex.rxjava4.disposables.CompositeDisposable
- All Implemented Interfaces:
Disposable, DisposableContainer
A disposable container that can hold onto multiple other
Disposables and
offers O(1) time complexity for add(Disposable), remove(Disposable) and delete(Disposable)
operations.-
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyCompositeDisposable.CompositeDisposable(@NonNull Disposable... disposables) Creates aCompositeDisposablewith the given array of initialDisposableelements.CompositeDisposable(@NonNull Iterable<? extends Disposable> disposables) -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(@NonNull Disposable disposable) Adds aDisposableto this container or disposes it if the container has been disposed.booleanaddAll(@NonNull Disposable... disposables) Atomically adds the given array ofDisposables to the container or disposes them all if the container has been disposed.voidclear()Atomically clears the container, then disposes all the previously containedDisposables.booleandelete(@NonNull Disposable disposable) Removes (but does not dispose) the givenDisposableif it is part of this container.voiddispose()Dispose the resource, the operation should be idempotent.booleanReturns true if this resource has been disposed.booleanremove(@NonNull Disposable disposable) Removes and disposes the givenDisposableif it is part of this container.intsize()Returns the number of currently heldDisposables.
-
Constructor Details
-
CompositeDisposable
public CompositeDisposable()Creates an emptyCompositeDisposable. -
CompositeDisposable
Creates aCompositeDisposablewith the given array of initialDisposableelements.- Parameters:
disposables- the array ofDisposables to start with- Throws:
NullPointerException- ifdisposablesor any of its array items isnull
-
CompositeDisposable
- Parameters:
disposables- theIterablesequence ofDisposableto start with- Throws:
NullPointerException- ifdisposablesor any of its items isnull
-
-
Method Details
-
dispose
public void dispose()Description copied from interface:DisposableDispose the resource, the operation should be idempotent.- Specified by:
disposein interfaceDisposable
-
isDisposed
public boolean isDisposed()Description copied from interface:DisposableReturns true if this resource has been disposed.- Specified by:
isDisposedin interfaceDisposable- Returns:
- true if this resource has been disposed
-
add
Adds aDisposableto this container or disposes it if the container has been disposed.- Specified by:
addin interfaceDisposableContainer- Parameters:
disposable- theDisposableto add, notnull- Returns:
trueif successful,falseif this container has been disposed- Throws:
NullPointerException- ifdisposableisnull
-
addAll
Atomically adds the given array ofDisposables to the container or disposes them all if the container has been disposed.- Parameters:
disposables- the array ofDisposables- Returns:
trueif the operation was successful,falseif the container has been disposed- Throws:
NullPointerException- ifdisposablesor any of its array items isnull
-
remove
Removes and disposes the givenDisposableif it is part of this container.- Specified by:
removein interfaceDisposableContainer- Parameters:
disposable- the disposable to remove and dispose, notnull- Returns:
trueif the operation was successful- Throws:
NullPointerException- ifdisposableisnull
-
delete
Removes (but does not dispose) the givenDisposableif it is part of this container.- Specified by:
deletein interfaceDisposableContainer- Parameters:
disposable- the disposable to remove, notnull- Returns:
trueif the operation was successful- Throws:
NullPointerException- ifdisposableisnull
-
clear
public void clear()Atomically clears the container, then disposes all the previously containedDisposables. -
size
public int size()Returns the number of currently heldDisposables.- Returns:
- the number of currently held
Disposables
-