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

java.util.concurrent.atomic.AtomicBoolean Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

The newest version!
package java.util.concurrent.atomic;

public class AtomicBoolean implements java.io.Serializable {
	private boolean value;

	public AtomicBoolean(boolean initialValue) {
		value = initialValue;
	}

	public AtomicBoolean() {
	}

	public final boolean get() {
		return value;
	}

	public final void set(boolean newValue) {
		this.value = newValue;
	}

	public final boolean getAndSet(boolean newValue) {
		boolean old = get();
		this.value = newValue;
		return old;
	}

	public final boolean compareAndSet(boolean expect, boolean update) {
		if (this.value != expect) return false; // Should return true too to avoid infinite loops?
		this.value = update;
		return true;
	}

	public boolean weakCompareAndSet(boolean expect, boolean update) {
		return compareAndSet(expect, update);
	}

	public final void lazySet(boolean newValue) {
		set(newValue);
	}

	public String toString() {
		return Boolean.toString(get());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy