Top Description Fields Constructors Methods
io.reactivex.disposables

public final Class CompositeDisposable

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

A disposable container that can hold onto multiple other disposables and offers O(1) add and removal complexity.

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(Disposable...
the array of Disposables to start with
disposables
)

Creates a CompositeDisposables with the given array of initial elements.

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

Creates a CompositeDisposables with the given Iterable sequence of initial elements.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

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

Implements io.reactivex.internal.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
(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
(Disposable
the disposable to remove, not null
disposable
)

Implements io.reactivex.internal.disposables.DisposableContainer.delete.

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

Implements io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
pack-priv void
dispose(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.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public boolean

Returns:

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

Implements io.reactivex.internal.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(Disposable... disposables)

Creates a CompositeDisposables with the given array of initial elements.

Parameters
disposables: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(Iterable<? extends Disposable> disposables)

Creates a CompositeDisposables with the given Iterable sequence of initial elements.

Parameters
disposables:Iterable<? extends Disposable>

the Iterable sequence of Disposables to start with

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

Method Detail

addback to summary
public boolean add(Disposable disposable)

Implements io.reactivex.internal.disposables.DisposableContainer.add.

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

Parameters
disposable: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(Disposable... disposables)

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

Parameters
disposables: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(Disposable disposable)

Implements io.reactivex.internal.disposables.DisposableContainer.delete.

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

Parameters
disposable: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.disposables.Disposable.dispose.

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

Dispose the resource, the operation should be idempotent.

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

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

Parameters
set:OpenHashSet<Disposable>

the OpenHashSet to dispose elements of

isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Doc from io.reactivex.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(Disposable disposable)

Implements io.reactivex.internal.disposables.DisposableContainer.remove.

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

Parameters
disposable:Disposable

the disposable to remove and dispose, not null

Returns:boolean

true if the operation was successful

Annotations
@Override
sizeback to summary
public int size()

Returns the number of currently held Disposables.

Returns:int

the number of currently held Disposables