public boolean setResource(int index, Subscription resource) {
    """
	Sets the resource at the specified index and disposes the old resource.
	@param index the index of the resource to set
	@param resource the new resource
	@return true if the resource has ben set, false if the composite has been disposed
    """
        for (;;) {
            Subscription o = get(index);
            if (o == SubscriptionHelper.CANCELLED) {
                if (resource != null) {
                    resource.cancel();
                }
                return false;
            }
            if (compareAndSet(index, o, resource)) {
                if (o != null) {
                    o.cancel();
                }
                return true;
            }
        }
    }
public boolean setResource(int index, Subscription resource) {
        for (;;) {
            Subscription o = get(index);
            if (o == SubscriptionHelper.CANCELLED) {
                if (resource != null) {
                    resource.cancel();
                }
                return false;
            }
            if (compareAndSet(index, o, resource)) {
                if (o != null) {
                    o.cancel();
                }
                return true;
            }
        }
    }
public boolean setResource ( int index , Subscription resource ) { for ( ; ; ) { Subscription o = get ( index ) ; if ( o == SubscriptionHelper . CANCELLED ) { if ( resource != null ) { resource . cancel ( ) ; } return false ; } if ( compareAndSet ( index , o , resource ) ) { if ( o != null ) { o . cancel ( ) ; } return true ; } } }
Sets the resource at the specified index and disposes the old resource.
@param index the index of the resource to set
@param resource the new resource
@return true if the resource has ben set, false if the composite has been disposed
Sets the resource at the specified index and disposes the old resource .