Package com.attivio.concurrent
Class SynchronizedBoolean
- java.lang.Object
-
- com.attivio.concurrent.SynchronizedVariable
-
- com.attivio.concurrent.SynchronizedBoolean
-
- All Implemented Interfaces:
java.lang.Comparable<SynchronizedBoolean>
,java.util.concurrent.Executor
- Direct Known Subclasses:
WaitableBoolean
public class SynchronizedBoolean extends SynchronizedVariable implements java.lang.Comparable<SynchronizedBoolean>
A class useful for offloading synch for boolean instance variables.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
value
the actual value-
Fields inherited from class com.attivio.concurrent.SynchronizedVariable
lock
-
-
Constructor Summary
Constructors Constructor Description SynchronizedBoolean(boolean initialValue)
Make a new SynchronizedBoolean with the given initial value, and using its own internal lock.SynchronizedBoolean(boolean initialValue, java.util.concurrent.locks.ReadWriteLock lock)
Make a new SynchronizedBoolean with the given initial value, and using the supplied lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
and(boolean b)
Set value to value & b.boolean
commit(boolean assumedValue, boolean newValue)
Set value to newValue only if it is currently assumedValue.int
compareTo(boolean other)
int
compareTo(SynchronizedBoolean other)
boolean
complement()
Set the value to its complementboolean
equals(java.lang.Object other)
boolean
get()
Return the current valueint
hashCode()
boolean
or(boolean b)
Set value to value | b.boolean
set(boolean newValue)
Set to newValue.boolean
swap(SynchronizedBoolean other)
Atomically swap values with another SynchronizedBoolean.java.lang.String
toString()
boolean
xor(boolean b)
Set value to value ^ b.-
Methods inherited from class com.attivio.concurrent.SynchronizedVariable
execute, getLock
-
-
-
-
Constructor Detail
-
SynchronizedBoolean
public SynchronizedBoolean(boolean initialValue)
Make a new SynchronizedBoolean with the given initial value, and using its own internal lock.
-
SynchronizedBoolean
public SynchronizedBoolean(boolean initialValue, java.util.concurrent.locks.ReadWriteLock lock)
Make a new SynchronizedBoolean with the given initial value, and using the supplied lock.
-
-
Method Detail
-
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
public boolean swap(SynchronizedBoolean other)
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
public int compareTo(SynchronizedBoolean other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<SynchronizedBoolean>
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-