Package io.reactivex.rxjava3.disposables
Class CompositeDisposable
- java.lang.Object
-
- io.reactivex.rxjava3.disposables.CompositeDisposable
-
- All Implemented Interfaces:
Disposable
,DisposableContainer
public final class CompositeDisposable extends java.lang.Object implements Disposable, DisposableContainer
A disposable container that can hold onto multiple otherDisposable
s and offers O(1) time complexity foradd(Disposable)
,remove(Disposable)
anddelete(Disposable)
operations.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
disposed
(package private) OpenHashSet<Disposable>
resources
-
Constructor Summary
Constructors Constructor Description CompositeDisposable()
Creates an emptyCompositeDisposable
.CompositeDisposable(@NonNull Disposable... disposables)
Creates aCompositeDisposable
with the given array of initialDisposable
elements.CompositeDisposable(@NonNull java.lang.Iterable<? extends Disposable> disposables)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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(@Nullable OpenHashSet<Disposable> set)
Dispose the contents of theOpenHashSet
by suppressing non-fatalThrowable
s till the end.boolean
isDisposed()
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 Detail
-
resources
OpenHashSet<Disposable> resources
-
disposed
volatile boolean disposed
-
-
Constructor Detail
-
CompositeDisposable
public CompositeDisposable()
Creates an emptyCompositeDisposable
.
-
CompositeDisposable
public CompositeDisposable(@NonNull @NonNull Disposable... disposables)
Creates aCompositeDisposable
with the given array of initialDisposable
elements.- Parameters:
disposables
- the array ofDisposable
s to start with- Throws:
java.lang.NullPointerException
- ifdisposables
or any of its array items isnull
-
CompositeDisposable
public CompositeDisposable(@NonNull @NonNull java.lang.Iterable<? extends Disposable> disposables)
- Parameters:
disposables
- theIterable
sequence ofDisposable
to start with- Throws:
java.lang.NullPointerException
- ifdisposables
or any of its items isnull
-
-
Method Detail
-
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
public boolean add(@NonNull @NonNull Disposable disposable)
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:
java.lang.NullPointerException
- ifdisposable
isnull
-
addAll
public boolean addAll(@NonNull @NonNull Disposable... disposables)
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:
java.lang.NullPointerException
- ifdisposables
or any of its array items isnull
-
remove
public boolean remove(@NonNull @NonNull Disposable disposable)
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:
java.lang.NullPointerException
- ifdisposable
isnull
-
delete
public boolean delete(@NonNull @NonNull Disposable disposable)
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:
java.lang.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
void dispose(@Nullable @Nullable OpenHashSet<Disposable> set)
Dispose the contents of theOpenHashSet
by suppressing non-fatalThrowable
s till the end.- Parameters:
set
- theOpenHashSet
to dispose elements of
-
-