jaga
Class BitSet

java.lang.Object
  |
  +--java.util.BitSet
        |
        +--jaga.BitSet
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
Genotype, SampleData

public class BitSet
extends java.util.BitSet

Extension of java.util.BitSet providing sets with defined length and constructors accepting encoded Strings.

See Also:
Serialized Form

Constructor Summary
BitSet()
          Creates new BitSet
BitSet(int length)
          Creates a new BitSet of the desired length
BitSet(java.lang.String bits)
          Creates a new BitSet from a string representation of the genotype which would look like: 0100101011101010010 (Anything which is not a 0 is taken as a 1)
BitSet(java.lang.String symbols, int length, int base)
          Creates a new BitSet from a string representation of the genotype which could look like: 9AB9873KJF83JD in any base.
 
Method Summary
 int bitsToInt(int first, int last)
          Takes two integers defining a range in the bitset and returns the integer represented by these bits.
 void flip(int index)
          Flips this bit (0->1, 1->0)
 boolean[] getBooleanChunk(int start, int seclen)
           
 BitSet getChunk(int start, int seclen)
          Takes two integers start,seclen and returns the BitSet of length seclen starting at position start of this bitset.
 int hashCode()
           
 int length()
           
 void setBits(int[] bitsToSet)
          Used to set many bits according to an array of integers indicating the positions of the bits to set.
static void setCodeBase(int base)
          Sets the current codebase which will be used to output BitSets as strings.
 void setLength(int newLength)
           
 void setTo(int index, boolean value)
          Sets a particular bit to a particular boolean value
 java.lang.String toString()
          Will convert the BitSet to a string using the current codebase.
 
Methods inherited from class java.util.BitSet
and, andNot, clear, clone, equals, get, or, set, size, xor
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitSet

public BitSet()
Creates new BitSet

BitSet

public BitSet(int length)
Creates a new BitSet of the desired length

BitSet

public BitSet(java.lang.String bits)
Creates a new BitSet from a string representation of the genotype which would look like: 0100101011101010010 (Anything which is not a 0 is taken as a 1)

BitSet

public BitSet(java.lang.String symbols,
              int length,
              int base)
Creates a new BitSet from a string representation of the genotype which could look like: 9AB9873KJF83JD in any base.
Method Detail

setTo

public void setTo(int index,
                  boolean value)
Sets a particular bit to a particular boolean value

flip

public void flip(int index)
Flips this bit (0->1, 1->0)

length

public int length()
Overrides:
length in class java.util.BitSet
Returns:
the length of this BitSet.

setLength

public void setLength(int newLength)

toString

public java.lang.String toString()
Will convert the BitSet to a string using the current codebase.
Overrides:
toString in class java.util.BitSet

setBits

public void setBits(int[] bitsToSet)
Used to set many bits according to an array of integers indicating the positions of the bits to set.

bitsToInt

public int bitsToInt(int first,
                     int last)
Takes two integers defining a range in the bitset and returns the integer represented by these bits. LSB last.
Parameters:
first - inclusive first bit in sequence to be converted
last - exclusive last bit in sequence to be converted

getChunk

public BitSet getChunk(int start,
                       int seclen)
Takes two integers start,seclen and returns the BitSet of length seclen starting at position start of this bitset. NOT ROBUST, assumes start + seclen <= length

getBooleanChunk

public boolean[] getBooleanChunk(int start,
                                 int seclen)

setCodeBase

public static void setCodeBase(int base)
Sets the current codebase which will be used to output BitSets as strings. This is bitWidth of codebase. Note this will set the codebase to 2^base. Eg: code base = 1 is binary, = 4 is hexadecimal.

hashCode

public int hashCode()
Overrides:
hashCode in class java.util.BitSet