Top Description Fields Constructors Methods
io.reactivex.rxjava3.disposables

public final Class CompositeDisposable

extends Object
implements Disposable, DisposableContainer
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.DisposableContainer, io.reactivex.rxjava3.disposables.Disposable
Imports
java.util.*, io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.exceptions.*, io.reactivex.rxjava3.internal.util.*

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.

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv OpenHashSet<Disposable>

Constructor Summary

AccessConstructor and Description
public
CompositeDisposable()

Creates an empty CompositeDisposable.

public
CompositeDisposable(@NonNull Disposable...
the array of Disposables to start with
disposables
)

Creates a CompositeDisposable with the given array of initial Disposable elements.

public
CompositeDisposable(@NonNull Iterable<? extends Disposable>
the Iterable sequence of Disposable to start with
disposables
)

Creates a CompositeDisposable with the given Iterable sequence of initial Disposable elements.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if successful, false if this container has been disposed
add
(@NonNull Disposable
the Disposable to add, not null
disposable
)

Implements io.reactivex.rxjava3.disposables.DisposableContainer.add.

Adds a Disposable to this container or disposes it if the container has been disposed.
public boolean

Returns:

true if the operation was successful, false if the container has been disposed
addAll
(@NonNull Disposable...
the array of Disposables
disposables
)

Atomically adds the given array of Disposables to the container or disposes them all if the container has been disposed.

public void
clear()

Atomically clears the container, then disposes all the previously contained Disposables.

public boolean

Returns:

true if the operation was successful
delete
(@NonNull Disposable
the disposable to remove, not null
disposable
)

Implements io.reactivex.rxjava3.disposables.DisposableContainer.delete.

Removes (but does not dispose) the given Disposable if it is part of this container.
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
pack-priv void
dispose(@Nullable OpenHashSet<Disposable>
the OpenHashSet to dispose elements of
set
)

Dispose the contents of the OpenHashSet by suppressing non-fatal Throwables till the end.

public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public boolean

Returns:

true if the operation was successful
remove
(@NonNull Disposable
the disposable to remove and dispose, not null
disposable
)

Implements io.reactivex.rxjava3.disposables.DisposableContainer.remove.

Removes and disposes the given Disposable if it is part of this container.
public int

Returns:

the number of currently held Disposables
size
()

Returns the number of currently held Disposables.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

disposedback to summary
pack-priv volatile boolean disposed
resourcesback to summary
pack-priv OpenHashSet<Disposable> resources

Constructor Detail

CompositeDisposableback to summary
public CompositeDisposable()

Creates an empty CompositeDisposable.

CompositeDisposableback to summary
public CompositeDisposable(@NonNull Disposable... disposables)

Creates a CompositeDisposable with the given array of initial Disposable elements.

Parameters
disposables:@NonNull Disposable[]

the array of Disposables to start with

Exceptions
NullPointerException:
if disposables or any of its array items is null
CompositeDisposableback to summary
public CompositeDisposable(@NonNull Iterable<? extends Disposable> disposables)

Creates a CompositeDisposable with the given Iterable sequence of initial Disposable elements.

Parameters
disposables:@NonNull Iterable<? extends Disposable>

the Iterable sequence of Disposable to start with

Exceptions
NullPointerException:
if disposables or any of its items is null

Method Detail

addback to summary
public boolean add(@NonNull Disposable disposable)

Implements io.reactivex.rxjava3.disposables.DisposableContainer.add.

Adds a Disposable to this container or disposes it if the container has been disposed.

Parameters
disposable:@NonNull Disposable

the Disposable to add, not null

Returns:boolean

true if successful, false if this container has been disposed

Annotations
@Override
Exceptions
NullPointerException:
if disposable is null
addAllback to summary
public boolean addAll(@NonNull Disposable... disposables)

Atomically adds the given array of Disposables to the container or disposes them all if the container has been disposed.

Parameters
disposables:@NonNull Disposable[]

the array of Disposables

Returns:boolean

true if the operation was successful, false if the container has been disposed

Exceptions
NullPointerException:
if disposables or any of its array items is null
clearback to summary
public void clear()

Atomically clears the container, then disposes all the previously contained Disposables.

deleteback to summary
public boolean delete(@NonNull Disposable disposable)

Implements io.reactivex.rxjava3.disposables.DisposableContainer.delete.

Removes (but does not dispose) the given Disposable if it is part of this container.

Parameters
disposable:@NonNull Disposable

the disposable to remove, not null

Returns:boolean

true if the operation was successful

Annotations
@Override
Exceptions
NullPointerException:
if disposable is null
disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
disposeback to summary
pack-priv void dispose(@Nullable OpenHashSet<Disposable> set)

Dispose the contents of the OpenHashSet by suppressing non-fatal Throwables till the end.

Parameters
set:@Nullable OpenHashSet<Disposable>

the OpenHashSet to dispose elements of

isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
removeback to summary
public boolean remove(@NonNull Disposable disposable)

Implements io.reactivex.rxjava3.disposables.DisposableContainer.remove.

Removes and disposes the given Disposable if it is part of this container.

Parameters
disposable:@NonNull Disposable

the disposable to remove and dispose, not null

Returns:boolean

true if the operation was successful

Annotations
@Override
Exceptions
NullPointerException:
if disposable is null
sizeback to summary
public int size()

Returns the number of currently held Disposables.

Returns:int

the number of currently held Disposables