com.ibm.security12.sun.security.util
Class BitArray

java.lang.Object
  |
  +--com.ibm.security12.sun.security.util.BitArray

public class BitArray
extends Object

A packed array of booleans.

Version:
1.3 98/07/22
Author:
Joshua Bloch, Douglas Hoover

Constructor Summary
BitArray(boolean[] bits)
          Create a BitArray whose bits are those of the given array of Booleans.
BitArray(int length)
          Creates a BitArray of the specified size, initialized to zeros.
BitArray(int length, byte[] a)
          Creates a BitArray of the specified size, initialized from the specified byte array.
 
Method Summary
 Object clone()
           
 boolean equals(Object obj)
           
 boolean get(int index)
          Returns the indexed bit in this BitArray.
 int hashCode()
          Returns a hash code value for this bit array.
 int length()
          Returns the length of this BitArray.
 void set(int index, boolean value)
          Sets the indexed bit in this BitArray.
 boolean[] toBooleanArray()
          Return a boolean array with the same bit values a this BitArray.
 byte[] toByteArray()
          Returns a Byte array containing the contents of this BitArray.
 String toString()
          Returns a string representation of this BitArray.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitArray

public BitArray(int length)
         throws IllegalArgumentException
Creates a BitArray of the specified size, initialized to zeros.

BitArray

public BitArray(int length,
                byte[] a)
         throws IllegalArgumentException
Creates a BitArray of the specified size, initialized from the specified byte array. The most significant bit of a[0] gets index zero in the BitArray. The array a must be large enough to specify a value for every bit in the BitArray. In other words, 8*a.length <= length.

BitArray

public BitArray(boolean[] bits)
Create a BitArray whose bits are those of the given array of Booleans.
Method Detail

get

public boolean get(int index)
            throws ArrayIndexOutOfBoundsException
Returns the indexed bit in this BitArray.

set

public void set(int index,
                boolean value)
         throws ArrayIndexOutOfBoundsException
Sets the indexed bit in this BitArray.

length

public int length()
Returns the length of this BitArray.

toByteArray

public byte[] toByteArray()
Returns a Byte array containing the contents of this BitArray. The bit stored at index zero in this BitArray will be copied into the most significant bit of the zeroth element of the returned byte array. The last byte of the returned byte array will be contain zeros in any bits that do not have corresponding bits in the BitArray. (This matters only if the BitArray's size is not a multiple of 8.)

equals

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

toBooleanArray

public boolean[] toBooleanArray()
Return a boolean array with the same bit values a this BitArray.

hashCode

public int hashCode()
Returns a hash code value for this bit array.
Returns:
a hash code value for this bit array.
Overrides:
hashCode in class Object

clone

public Object clone()
Overrides:
clone in class Object

toString

public String toString()
Returns a string representation of this BitArray.
Overrides:
toString in class Object