/*
 * Copyright (c) 2015-2019 Uli Bubenheimer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.bubenheimer.android.rx

import io.reactivex.rxjava3.disposables.Disposable
import org.bubenheimer.android.Check

/** Cheaper replacement for `SerialDisposable`. Methods are not thread-safe.  */
public class DisposableWrapper {
    private var disposable: Disposable? = null

    public fun get(): Disposable? = disposable

    public fun set(disposable: Disposable) {
        Check.isNull(this.disposable)
        this.disposable = disposable
    }

    public fun clear() {
        disposable?.let {
            it.dispose()
            disposable = null
        }
    }
}

/*
 * Copyright (c) 2015-2019 Uli Bubenheimer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.bubenheimer.android.rx

import io.reactivex.rxjava3.disposables.Disposable
import org.bubenheimer.util.examIsNull

/** Cheaper replacement for `SerialDisposable`. Methods are not thread-safe.  */
public class DisposableWrapper {
    private var disposable: Disposable? = null

    public fun get(): Disposable? = disposable

    public fun set(disposable: Disposable) {
        examIsNull(this.disposable)
        this.disposable = disposable
    }

    public fun clear() {
        disposable?.let {
            it.dispose()
            disposable = null
        }
    }
}

Refactor remaining general Check.kt functions
Refactor remaining general Check.kt functions

bubenheimer/androidrxutil,bubenheimer/androidrxutil