All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reactfx.SuspendableBoolean Maven / Gradle / Ivy

package org.reactfx;

import javafx.beans.value.ObservableBooleanValue;

import org.reactfx.value.ValBase;

abstract class SuspendableBoolean extends ValBase
implements ObservableBooleanValue, Toggle {

    private int suspenders = 0;

    @Override
    public final Guard suspend() {
        if(++suspenders == 1) {
            invalidate();
        }

        return ((Guard) this::release).closeableOnce();
    }

    private void release() {
        assert suspenders > 0;
        if(--suspenders == 0) {
            invalidate();
        }
    }

    public EventStream yeses() {
        return EventStreams.valuesOf(this).filterMap(val -> !val, val -> null);
    }

    public EventStream noes() {
        return EventStreams.valuesOf(this).filterMap(val -> val, val -> null);
    }

    protected final boolean isSuspended() {
        return suspenders > 0;
    }

    @Override
    protected final Subscription connect() {
        return Subscription.EMPTY;
    }

    @Override
    protected final Boolean computeValue() {
        return get();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy