Class SynchronizedBoolean
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
- All Implemented Interfaces:
Executor, Cloneable, Comparable
- Direct Known Subclasses:
WaitableBoolean
A class useful for offloading synch for boolean instance variables.
-
Field Summary
FieldsFields inherited from class SynchronizedVariable
lock_ -
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedBoolean(boolean initialValue) Make a new SynchronizedBoolean with the given initial value, and using its own internal lock.SynchronizedBoolean(boolean initialValue, Object lock) Make a new SynchronizedBoolean with the given initial value, and using the supplied lock. -
Method Summary
Modifier and TypeMethodDescriptionbooleanand(boolean b) Set value to value & b.booleancommit(boolean assumedValue, boolean newValue) Set value to newValue only if it is currently assumedValue.intcompareTo(boolean other) intcompareTo(SynchronizedBoolean other) intbooleanSet the value to its complementbooleanfinal booleanget()Return the current valueinthashCode()booleanor(boolean b) Set value to value | b.booleanset(boolean newValue) Set to newValue.booleanswap(SynchronizedBoolean other) Atomically swap values with another SynchronizedBoolean.toString()booleanxor(boolean b) Set value to value ^ b.Methods inherited from class SynchronizedVariable
execute, getLock
-
Field Details
-
value_
protected boolean value_
-
-
Constructor Details
-
SynchronizedBoolean
public SynchronizedBoolean(boolean initialValue) Make a new SynchronizedBoolean with the given initial value, and using its own internal lock. -
SynchronizedBoolean
Make a new SynchronizedBoolean with the given initial value, and using the supplied lock.
-
-
Method Details
-
get
public final boolean get()Return the current value -
set
public boolean set(boolean newValue) Set to newValue.- Returns:
- the old value
-
commit
public boolean commit(boolean assumedValue, boolean newValue) Set value to newValue only if it is currently assumedValue.- Returns:
- true if successful
-
swap
Atomically swap values with another SynchronizedBoolean. Uses identityHashCode to avoid deadlock when two SynchronizedBooleans attempt to simultaneously swap with each other. (Note: Ordering via identyHashCode is not strictly guaranteed by the language specification to return unique, orderable values, but in practice JVMs rely on them being unique.)- Returns:
- the new value
-
complement
public boolean complement()Set the value to its complement- Returns:
- the new value
-
and
public boolean and(boolean b) Set value to value & b.- Returns:
- the new value
-
or
public boolean or(boolean b) Set value to value | b.- Returns:
- the new value
-
xor
public boolean xor(boolean b) Set value to value ^ b.- Returns:
- the new value
-
compareTo
public int compareTo(boolean other) -
compareTo
-
compareTo
- Specified by:
compareToin interfaceComparable
-
equals
-
hashCode
-
toString
-