com.epochx.util
Class BoolUtils

java.lang.Object
  extended by com.epochx.util.BoolUtils

public class BoolUtils
extends java.lang.Object

This class provides static utility methods for working with booleans and boolean arrays.


Constructor Summary
BoolUtils()
           
 
Method Summary
static boolean[] generateBoolSequence(int noBits, long index)
          Provides an alternative to BoolUtils.generateBoolSequences(int) particularly for larger numbers of bits greater than 30 which that method will struggle with.
static boolean[][] generateBoolSequences(int noBits)
          Generates an array of boolean arrays of all possible combinations of true/false values for the given number of elements.
static boolean[] toArray(java.lang.String input)
          Translates a String of zeros ('0') and ones ('1') to an array of booleans.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoolUtils

public BoolUtils()
Method Detail

toArray

public static boolean[] toArray(java.lang.String input)
Translates a String of zeros ('0') and ones ('1') to an array of booleans. '0' characters are translated to a boolean false, and '1' characters to boolean true.

Parameters:
input - An input String made up of 1s and 0s
Returns:
An equivalent array of booleans.

generateBoolSequences

public static boolean[][] generateBoolSequences(int noBits)
Generates an array of boolean arrays of all possible combinations of true/false values for the given number of elements.

This function will not cope with large values of noBits over about 30 due to the size limitations of the int datatype, and maximum array sizes. There are also likely to be issues with heap space. Alternatively users should use the BoolUtils.generateBoolSequence(int, long) method which generates the same boolean arrays on an individual basis.

Parameters:
noBits - The number of boolean values in which different combinations are made.
Returns:
An array of all the possible boolean arrays possible with the given number of elements. There will be 2^noBits combinations and so the returned array will have this many elements.

generateBoolSequence

public static boolean[] generateBoolSequence(int noBits,
                                             long index)
Provides an alternative to BoolUtils.generateBoolSequences(int) particularly for larger numbers of bits greater than 30 which that method will struggle with. The order of the bools generated by this method are identical to that method, so that calling it with an index parameter of n will return a boolean[] identical to the nth element of the boolean[][] returned by BoolUtils.generateBoolSequences(int).

Parameters:
noBits - The number of boolean values in which different combinations are made.
index - An index into the possible combinations to allow iteration through the possibilities. There will be 2^noBits combinations and so indexes up to 2^noBits-1 will be valid.
Returns:
An array of booleans. The value of the booleans is identical to the nth element of the result from BoolUtils.generateBoolSequences, where n == index. Each valid index value will return a unique combination of booleans.