Package io.reactivex.rxjava3.disposables
Class CompositeDisposable
java.lang.Object
io.reactivex.rxjava3.disposables.CompositeDisposable
- All Implemented Interfaces:
Disposable
,DisposableContainer
A disposable container that can hold onto multiple other
Disposable
s and
offers O(1) time complexity for add(Disposable)
, remove(Disposable)
and delete(Disposable)
operations.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
(package private) OpenHashSet
<Disposable> -
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyCompositeDisposable
.CompositeDisposable
(@NonNull Disposable... disposables) Creates aCompositeDisposable
with the given array of initialDisposable
elements.CompositeDisposable
(@NonNull Iterable<? extends Disposable> disposables) -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(@NonNull Disposable disposable) Adds aDisposable
to this container or disposes it if the container has been disposed.boolean
addAll
(@NonNull Disposable... disposables) Atomically adds the given array ofDisposable
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 containedDisposable
s.boolean
delete
(@NonNull Disposable disposable) Removes (but does not dispose) the givenDisposable
if it is part of this container.void
dispose()
Dispose the resource, the operation should be idempotent.(package private) void
Dispose the contents of theOpenHashSet
by suppressing non-fatalThrowable
s till the end.boolean
Returns true if this resource has been disposed.boolean
remove
(@NonNull Disposable disposable) Removes and disposes the givenDisposable
if it is part of this container.int
size()
Returns the number of currently heldDisposable
s.
-
Field Details
-
resources
OpenHashSet<Disposable> resources -
disposed
volatile boolean disposed
-
-
Constructor Details
-
CompositeDisposable
public CompositeDisposable()Creates an emptyCompositeDisposable
. -
CompositeDisposable
Creates aCompositeDisposable
with the given array of initialDisposable
elements.- Parameters:
disposables
- the array ofDisposable
s to start with- Throws:
NullPointerException
- ifdisposables
or any of its array items isnull
-
CompositeDisposable
- Parameters:
disposables
- theIterable
sequence ofDisposable
to start with- Throws:
NullPointerException
- ifdisposables
or any of its items isnull
-
-
Method Details
-
dispose
public void dispose()Description copied from interface:Disposable
Dispose the resource, the operation should be idempotent.- Specified by:
dispose
in interfaceDisposable
-
isDisposed
public boolean isDisposed()Description copied from interface:Disposable
Returns true if this resource has been disposed.- Specified by:
isDisposed
in interfaceDisposable
- Returns:
- true if this resource has been disposed
-
add
Adds aDisposable
to this container or disposes it if the container has been disposed.- Specified by:
add
in interfaceDisposableContainer
- Parameters:
disposable
- theDisposable
to add, notnull
- Returns:
true
if successful,false
if this container has been disposed- Throws:
NullPointerException
- ifdisposable
isnull
-
addAll
Atomically adds the given array ofDisposable
s to the container or disposes them all if the container has been disposed.- Parameters:
disposables
- the array ofDisposable
s- Returns:
true
if the operation was successful,false
if the container has been disposed- Throws:
NullPointerException
- ifdisposables
or any of its array items isnull
-
remove
Removes and disposes the givenDisposable
if it is part of this container.- Specified by:
remove
in interfaceDisposableContainer
- Parameters:
disposable
- the disposable to remove and dispose, notnull
- Returns:
true
if the operation was successful- Throws:
NullPointerException
- ifdisposable
isnull
-
delete
Removes (but does not dispose) the givenDisposable
if it is part of this container.- Specified by:
delete
in interfaceDisposableContainer
- Parameters:
disposable
- the disposable to remove, notnull
- Returns:
true
if the operation was successful- Throws:
NullPointerException
- ifdisposable
isnull
-
clear
public void clear()Atomically clears the container, then disposes all the previously containedDisposable
s. -
size
public int size()Returns the number of currently heldDisposable
s.- Returns:
- the number of currently held
Disposable
s
-
dispose
Dispose the contents of theOpenHashSet
by suppressing non-fatalThrowable
s till the end.- Parameters:
set
- theOpenHashSet
to dispose elements of
-