com.beans.observables.binding.SingleDirectionBinding Maven / Gradle / Ivy
package com.beans.observables.binding;
import com.beans.observables.ObservableValue;
import com.beans.observables.listeners.ChangeEvent;
import com.beans.observables.listeners.ChangeListener;
import java.util.function.Consumer;
public class SingleDirectionBinding implements ObservableBinding {
private final ObservableValue mBound;
private final ChangeListener mListener;
public SingleDirectionBinding(ObservableValue bound, Consumer> onObservableValueChange) {
mBound = bound;
mListener = onObservableValueChange::accept;
mBound.addChangeListener(mListener);
}
@Override
public void set(T value) {
throw new IllegalStateException("Cannot set for single-direction bind");
}
@Override
public T get() {
return mBound.get();
}
@Override
public void onUnbind() {
mBound.removeChangeListener(mListener);
}
}