Package org.dbunit.util.concurrent
Class SynchronizedInt
java.lang.Object
org.dbunit.util.concurrent.SynchronizedVariable
org.dbunit.util.concurrent.SynchronizedInt
- All Implemented Interfaces:
Cloneable,Comparable,Executor
A class useful for offloading synch for int instance variables.
- Since:
- ? (pre 2.1)
- Version:
- $Revision$ $Date$
- Author:
- Doug Lea, Last changed by: $Author$
-
Field Summary
FieldsFields inherited from class org.dbunit.util.concurrent.SynchronizedVariable
lock_ -
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedInt(int initialValue) Make a new SynchronizedInt with the given initial value, and using its own internal lock.SynchronizedInt(int initialValue, Object lock) Make a new SynchronizedInt with the given initial value, and using the supplied lock. -
Method Summary
Modifier and TypeMethodDescriptionintadd(int amount) Add amount to value (i.e., set value += amount)intand(int b) Set value to value & b.booleancommit(int assumedValue, int newValue) Set value to newValue only if it is currently assumedValue.intcompareTo(int other) Compares the current value to the given int.intintcompareTo(SynchronizedInt other) Compares the current value to anotherSynchronizedInt's value.intSet the value to its complementintDecrement the value.intdivide(int factor) Divide value by factor (i.e., set value /= factor)booleanfinal intget()Return the current valueinthashCode()intIncrement the value.intmultiply(int factor) Multiply value by factor (i.e., set value *= factor)intnegate()Set the value to the negative of its old valueintor(int b) Set value to value | b.intset(int newValue) Set to newValue.intsubtract(int amount) Subtract amount from value (i.e., set value -= amount)intswap(SynchronizedInt other) Atomically swap values with another SynchronizedInt.toString()intxor(int b) Set value to value ^ b.Methods inherited from class org.dbunit.util.concurrent.SynchronizedVariable
execute, getLock
-
Field Details
-
value_
protected int value_The current value.
-
-
Constructor Details
-
SynchronizedInt
public SynchronizedInt(int initialValue) Make a new SynchronizedInt with the given initial value, and using its own internal lock.- Parameters:
initialValue- the initial value.
-
SynchronizedInt
Make a new SynchronizedInt with the given initial value, and using the supplied lock.- Parameters:
initialValue- the initial value.lock- the synchronization lock to use.
-
-
Method Details
-
get
public final int get()Return the current value- Returns:
- the current value.
-
set
public int set(int newValue) Set to newValue.- Parameters:
newValue- the new value.- Returns:
- the old value
-
commit
public boolean commit(int assumedValue, int newValue) Set value to newValue only if it is currently assumedValue.- Parameters:
assumedValue- the value the current value must equal for the update to happen.newValue- the new value.- Returns:
- true if successful
-
swap
Atomically swap values with another SynchronizedInt. Uses identityHashCode to avoid deadlock when two SynchronizedInts 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.)- Parameters:
other- the SynchronizedInt to swap values with.- Returns:
- the new value
-
increment
public int increment()Increment the value.- Returns:
- the new value
-
decrement
public int decrement()Decrement the value.- Returns:
- the new value
-
add
public int add(int amount) Add amount to value (i.e., set value += amount)- Parameters:
amount- the amount to add.- Returns:
- the new value
-
subtract
public int subtract(int amount) Subtract amount from value (i.e., set value -= amount)- Parameters:
amount- the amount to subtract.- Returns:
- the new value
-
multiply
public int multiply(int factor) Multiply value by factor (i.e., set value *= factor)- Parameters:
factor- the factor to multiply by.- Returns:
- the new value
-
divide
public int divide(int factor) Divide value by factor (i.e., set value /= factor)- Parameters:
factor- the factor to divide by.- Returns:
- the new value
-
negate
public int negate()Set the value to the negative of its old value- Returns:
- the new value
-
complement
public int complement()Set the value to its complement- Returns:
- the new value
-
and
public int and(int b) Set value to value & b.- Parameters:
b- the value to AND with.- Returns:
- the new value
-
or
public int or(int b) Set value to value | b.- Parameters:
b- the value to OR with.- Returns:
- the new value
-
xor
public int xor(int b) Set value to value ^ b.- Parameters:
b- the value to XOR with.- Returns:
- the new value
-
compareTo
public int compareTo(int other) Compares the current value to the given int.- Parameters:
other- the value to compare against.- Returns:
- a negative, zero, or positive integer as the current value is less than, equal to,
or greater than
other.
-
compareTo
Compares the current value to anotherSynchronizedInt's value.- Parameters:
other- the instance to compare against.- Returns:
- a negative, zero, or positive integer as the current value is less than, equal to,
or greater than
other's value.
-
compareTo
- Specified by:
compareToin interfaceComparable
-
equals
-
hashCode
public int hashCode() -
toString
-