eu.gressly.util
Class BitWorm

java.lang.Object
  extended by eu.gressly.util.BitWorm
All Implemented Interfaces:
java.io.Serializable

public class BitWorm
extends java.lang.Object
implements java.io.Serializable

Array of Bits with a simple interface: get() and put(). A 1-Bit is represented by the boolean value "true" (0 is represented by "false").

Author:
Philipp Gressly (phi@gressly.ch)
See Also:
Serialized Form

Constructor Summary
BitWorm()
          Generate a bitworm with an initial capacity of 32 bits.
BitWorm(int initialCapacity)
          Generate a BitWorm with a initial Capacity of bits.
 
Method Summary
 boolean get(int pos)
          Read a boolean from a given position.
static void main(java.lang.String[] args)
          Test Method
 void set(int pos, boolean value)
          Set Bit[pos] to 1 (true) or 0 (false) If a "true (1)"-Bit is set in a position higher (or same) as the size(), the size of the Bitworm will be enlarged.
 int size()
          Return the number of bits that have been assigned.
 boolean[] toBooleanArray()
          Return the bitWorm in a boolean[] representation (0 = false ; 1 = true)
 java.lang.String toString()
          Human readable form of this BitWorm.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitWorm

public BitWorm()
Generate a bitworm with an initial capacity of 32 bits.


BitWorm

public BitWorm(int initialCapacity)
Generate a BitWorm with a initial Capacity of bits. initalCapacity will be at least 1.

Parameters:
initialCapacity -
Method Detail

get

public boolean get(int pos)
Read a boolean from a given position. If the bit was not set already, or if the position is bigger than the size, "false" will be returned.

Parameters:
pos -
Returns:
true, iff the bit was set earlier.

set

public void set(int pos,
                boolean value)
Set Bit[pos] to 1 (true) or 0 (false) If a "true (1)"-Bit is set in a position higher (or same) as the size(), the size of the Bitworm will be enlarged.

Parameters:
pos - The first possible position is 0.
value - true for a 1 bit and false for a 0 bit

toString

public java.lang.String toString()
Human readable form of this BitWorm. 1 indicates "true", o indicates "false".

Overrides:
toString in class java.lang.Object

size

public int size()
Return the number of bits that have been assigned. The highes "true" bit that ever was assigned will be at position [size() - 1]. To remove that bit (seting to false) will NOT affect the size!

Returns:
return the number of bits in this worm.

toBooleanArray

public boolean[] toBooleanArray()
Return the bitWorm in a boolean[] representation (0 = false ; 1 = true)

Returns:
new boolean array.

main

public static void main(java.lang.String[] args)
Test Method

Parameters:
args - are not used