com.beans.properties.atomic.AtomicBooleanProperty Maven / Gradle / Ivy
package com.beans.properties.atomic;
import com.beans.properties.BooleanPropertyBase;
/**
*
* A thread-safe implementation of {@link com.beans.BooleanProperty BooleanProperty}, holding a
* variable which is accessed for writing or reading through {@link #setAsBoolean(boolean)}
* and {@link #getAsBoolean()}.
*
*
* A boxed version of the access interface for writing and reading is available
* using {@link #set(Boolean)} and {@link #get()}, which are basically proxies
* for the primitive interface.
*
*
* This implementation relays on the fact that the Java Language Specifications guarantee that an access (read/write)
* to a volatile field is atomic, and will be visible to all threads.
*
*
* @since JavaBeans 1.0
*/
public class AtomicBooleanProperty extends BooleanPropertyBase {
private volatile boolean mValue;
public AtomicBooleanProperty(boolean value) {
mValue = value;
}
/**
* Initializes the property with a value of false.
*/
public AtomicBooleanProperty() {
this(false);
}
@Override
public void setAsBoolean(boolean value) {
mValue = value;
}
@Override
public boolean getAsBoolean() {
return mValue;
}
}