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

com.beans.observables.properties.SimpleObservableProperty Maven / Gradle / Ivy

package com.beans.observables.properties;

import com.beans.observables.binding.AtomicPropertyBindingController;
import com.beans.observables.binding.PropertyBindingController;
import com.beans.observables.listeners.ObservableEventController;
import com.notifier.Controllers;
import com.notifier.EventController;

import java.util.Objects;
import java.util.Optional;

/**
 * 

* A simple implementation of {@link ObservableProperty}, holding a * variable which is accessed for writing or reading through {@link #set(Object)} * and {@link #get()}. *

* * @param type of the property data. * * @since JavaBeans 1.0 */ public class SimpleObservableProperty extends ObservablePropertyBase { private T mValue; public SimpleObservableProperty(ObservableEventController eventController, PropertyBindingController bindingController, T initialValue) { super(eventController, bindingController); mValue = initialValue; } public SimpleObservableProperty(EventController eventController, PropertyBindingController bindingController, T initialValue) { super(eventController, bindingController); mValue = initialValue; } public SimpleObservableProperty(ObservableEventController eventController, PropertyBindingController bindingController) { this(eventController, bindingController, null); } public SimpleObservableProperty(EventController eventController, T initialValue) { this(eventController, new AtomicPropertyBindingController<>(), initialValue); } public SimpleObservableProperty(EventController eventController) { this(eventController, null); } public SimpleObservableProperty(T initialValue) { this(Controllers.newSyncExecutionController(), initialValue); } public SimpleObservableProperty() { this((T) null); } @Override protected void setInternalDirect(T value) { mValue = value; } @Override public void set(T value) { if (!setIfBound(value)) { if (!Objects.equals(mValue, value)) { T oldValue = mValue; mValue = value; fireValueChangedEvent(oldValue, value); } } } @Override public T get() { Optional boundOptional = getIfBound(); return boundOptional.orElse(mValue); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy