public Disposable replaceResource(int index, Disposable resource) {
    """
	Replaces the resource at the specified index and returns the old resource.
	@param index the index of the resource to replace
	@param resource the new resource
	@return the old resource, can be null
    """
        for (;;) {
            Disposable o = get(index);
            if (o == DisposableHelper.DISPOSED) {
                resource.dispose();
                return null;
            }
            if (compareAndSet(index, o, resource)) {
                return o;
            }
        }
    }
public Disposable replaceResource(int index, Disposable resource) {
        for (;;) {
            Disposable o = get(index);
            if (o == DisposableHelper.DISPOSED) {
                resource.dispose();
                return null;
            }
            if (compareAndSet(index, o, resource)) {
                return o;
            }
        }
    }
public Disposable replaceResource ( int index , Disposable resource ) { for ( ; ; ) { Disposable o = get ( index ) ; if ( o == DisposableHelper . DISPOSED ) { resource . dispose ( ) ; return null ; } if ( compareAndSet ( index , o , resource ) ) { return o ; } } }
Replaces the resource at the specified index and returns the old resource.
@param index the index of the resource to replace
@param resource the new resource
@return the old resource, can be null
Replaces the resource at the specified index and returns the old resource .