org.wegra.util.bitset
Class BitSet

java.lang.Object
  extended byorg.wegra.util.bitset.BitSet
All Implemented Interfaces:
java.lang.Cloneable

public final class BitSet
extends java.lang.Object
implements java.lang.Cloneable

A class representation of specific bit pattern.

Author:
wegra (Bok-Youn Lee)

Constructor Summary
BitSet(boolean[] bits)
          Creates a BitSet has specific value.
BitSet(int bitLength)
          Creates a BitSet has specific length.
 
Method Summary
 void change(BitSet source)
          Changes current bitset to given source.
 void clear(int index)
          Clears (set as 0) a specific bit.
 void clear(int fromIndex, int toIndex)
          Clears the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to false.
 void clearAll()
          Clears all bits of current bitset.
 java.lang.Object clone()
          Clones this BitSet and returns it.
 boolean equals(java.lang.Object target)
          Indicates whether some other object is "equal to" this one.
 boolean getAt(int index)
          Returns the value of the bit with the specified index.
 int getLength()
          Returns the length of current bitset.
 BitSet getSubset(int fromIndex, int toIndex)
          Returns a subset of current bitset.
 void set(int index)
          Sets the bit at the specified index to true.
 void set(int fromIndex, BitSet src, int srcStart, int length)
          Copies part of current bitset from given src's.
 void set(int fromIndex, int toIndex)
          Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to true.
 void setAll()
          Sets all bits of current bitset to true.
 void setValue(int value)
           
 java.lang.String toString()
          Returns a string representation of this bitset.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitSet

public BitSet(boolean[] bits)
Creates a BitSet has specific value.


BitSet

public BitSet(int bitLength)
Creates a BitSet has specific length.

Method Detail

clear

public void clear(int index)
Clears (set as 0) a specific bit.

Parameters:
index - index of target bit.

clear

public void clear(int fromIndex,
                  int toIndex)
Clears the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to false.

Parameters:
fromIndex - index of the first bit to be cleared.
toIndex - index after the last bit to be cleared.

clearAll

public void clearAll()
Clears all bits of current bitset.


set

public void set(int index)
Sets the bit at the specified index to true.

Parameters:
index - a bit index to set.

set

public void set(int fromIndex,
                int toIndex)
Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to true.

Parameters:
fromIndex - index of the first bit to be cleared.
toIndex - index after the last bit to be cleared.

set

public void set(int fromIndex,
                BitSet src,
                int srcStart,
                int length)
Copies part of current bitset from given src's.

Parameters:
fromIndex - a position to start copy of current bitset.
src - source bitset.
srcStart - a position to start copy of source bitset.
length - length to copy.

setValue

public void setValue(int value)

setAll

public void setAll()
Sets all bits of current bitset to true.


clone

public java.lang.Object clone()
Clones this BitSet and returns it.

Returns:
cloned BitSet.

equals

public boolean equals(java.lang.Object target)
Indicates whether some other object is "equal to" this one.

Parameters:
target - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

getAt

public boolean getAt(int index)
Returns the value of the bit with the specified index. The value is true if the bit with the index bitIndex is currently set in this BitSet; otherwise, the result is false.

Parameters:
index - the bit index
Returns:
the value of the bit with the specified index. true if the bit is currently set; otherwise, false.

getLength

public int getLength()
Returns the length of current bitset.

Returns:
the length of current bitset.

getSubset

public BitSet getSubset(int fromIndex,
                        int toIndex)
Returns a subset of current bitset.


change

public void change(BitSet source)
Changes current bitset to given source. Current bitset will lost all old values, and be completly changed with new one.

Parameters:
source - source

toString

public java.lang.String toString()
Returns a string representation of this bitset.
a set bit represented by 1 and a clear bit will be 0.

Returns:
a string representation of this bitset.