ch.javasoft.util.concurrent
Class ConcurrentBitSet

java.lang.Object
  extended by ch.javasoft.util.concurrent.ConcurrentBitSet

public class ConcurrentBitSet
extends Object

An ConcurrentBitSet is pretty much the same as a BitSet, but operations on the set are performed in a thread-safe manner.


Constructor Summary
ConcurrentBitSet()
           
ConcurrentBitSet(BitSet bitSet)
           
ConcurrentBitSet(int bitCapacity)
           
ConcurrentBitSet(String bitString)
           
 
Method Summary
 void and(ConcurrentBitSet with)
           
 void andNot(ConcurrentBitSet with)
          This set becomes this & not with
 int cardinality()
           
 int cardinality(int fromBit, int toBit)
           
 void clear()
           
 void clear(int bit)
           
 ConcurrentBitSet clone()
           
 boolean compareAndSet(int bit, boolean expect, boolean update)
          Atomically sets the value to the given updated value if the current value == the expected value.
 boolean equals(Object obj)
           
 void flip(int bit)
           
 boolean get(int bit)
           
static ConcurrentBitSet getAnd(ConcurrentBitSet setA, ConcurrentBitSet setB)
           
static ConcurrentBitSet getAndNot(ConcurrentBitSet setA, ConcurrentBitSet setB)
          Returns setA and not setB
static ConcurrentBitSet getOr(ConcurrentBitSet setA, ConcurrentBitSet setB)
           
static ConcurrentBitSet getXor(ConcurrentBitSet setA, ConcurrentBitSet setB)
           
 int hashCode()
           
 boolean isEmpty()
           
 boolean isSubSetOf(ConcurrentBitSet of)
           
 int length()
           
static void main(String[] args)
           
 int nextClearBit(int from)
           
 int nextSetBit(int from)
           
 void or(ConcurrentBitSet with)
           
static ConcurrentBitSet readFrom(InputStream in)
           
 void set(int bit)
           
 void set(int bit, boolean value)
           
 BitSet toBitSet()
           
 long[] toLongArray()
           
 long[] toLongArray(long[] arr, int offset)
           
 String toString()
           
 void writeTo(OutputStream out)
           
 void xor(ConcurrentBitSet with)
          This set becomes this ^ with
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConcurrentBitSet

public ConcurrentBitSet()

ConcurrentBitSet

public ConcurrentBitSet(int bitCapacity)

ConcurrentBitSet

public ConcurrentBitSet(BitSet bitSet)

ConcurrentBitSet

public ConcurrentBitSet(String bitString)
Method Detail

set

public void set(int bit,
                boolean value)

set

public void set(int bit)

compareAndSet

public boolean compareAndSet(int bit,
                             boolean expect,
                             boolean update)
Atomically sets the value to the given updated value if the current value == the expected value.

Parameters:
bit - the bit index
expect - the expected value
update - the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

clear

public void clear(int bit)

clear

public void clear()

flip

public void flip(int bit)

get

public boolean get(int bit)

isSubSetOf

public boolean isSubSetOf(ConcurrentBitSet of)

and

public void and(ConcurrentBitSet with)

or

public void or(ConcurrentBitSet with)

xor

public void xor(ConcurrentBitSet with)
This set becomes this ^ with


andNot

public void andNot(ConcurrentBitSet with)
This set becomes this & not with


getXor

public static ConcurrentBitSet getXor(ConcurrentBitSet setA,
                                      ConcurrentBitSet setB)

getOr

public static ConcurrentBitSet getOr(ConcurrentBitSet setA,
                                     ConcurrentBitSet setB)

getAnd

public static ConcurrentBitSet getAnd(ConcurrentBitSet setA,
                                      ConcurrentBitSet setB)

getAndNot

public static ConcurrentBitSet getAndNot(ConcurrentBitSet setA,
                                         ConcurrentBitSet setB)
Returns setA and not setB


length

public int length()

isEmpty

public boolean isEmpty()

clone

public ConcurrentBitSet clone()
Overrides:
clone in class Object

cardinality

public int cardinality()

cardinality

public int cardinality(int fromBit,
                       int toBit)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

nextSetBit

public int nextSetBit(int from)

nextClearBit

public int nextClearBit(int from)

toBitSet

public BitSet toBitSet()

writeTo

public void writeTo(OutputStream out)
             throws IOException
Throws:
IOException

readFrom

public static ConcurrentBitSet readFrom(InputStream in)
                                 throws IOException
Throws:
IOException

toLongArray

public long[] toLongArray()

toLongArray

public long[] toLongArray(long[] arr,
                          int offset)

main

public static void main(String[] args)