Class BitArray
- java.lang.Object
-
- com.github.toolarium.security.pki.impl.rsa.data.BitArray
-
public class BitArray extends java.lang.ObjectA packed array of booleans.
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()booleanequals(java.lang.Object obj)booleanget(int index)Returns the indexed bit in this BitArray.inthashCode()Returns a hash code value for this bit array.intlength()Returns the length of this BitArray.voidset(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.java.lang.StringtoString()
-
-
-
Constructor Detail
-
BitArray
public BitArray(int length) throws java.lang.IllegalArgumentExceptionCreates a BitArray of the specified size, initialized to zeros.- Parameters:
length- the length- Throws:
java.lang.IllegalArgumentException- in case of error
-
BitArray
public BitArray(int length, byte[] a) throws java.lang.IllegalArgumentExceptionCreates 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.- Parameters:
length- the lengtha- the array- Throws:
java.lang.IllegalArgumentException- in case of error
-
BitArray
public BitArray(boolean[] bits)
Create a BitArray whose bits are those of the given array of Booleans.- Parameters:
bits- the bits
-
-
Method Detail
-
get
public boolean get(int index) throws java.lang.ArrayIndexOutOfBoundsExceptionReturns the indexed bit in this BitArray.- Parameters:
index- the index- Returns:
- the value
- Throws:
java.lang.ArrayIndexOutOfBoundsException- in case of error
-
set
public void set(int index, boolean value) throws java.lang.ArrayIndexOutOfBoundsExceptionSets the indexed bit in this BitArray.- Parameters:
index- the indexvalue- the value to set- Throws:
java.lang.ArrayIndexOutOfBoundsException- in case of error
-
length
public int length()
Returns the length of this BitArray.- Returns:
- the length
-
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.)- Returns:
- the array
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
toBooleanArray
public boolean[] toBooleanArray()
Return a boolean array with the same bit values a this BitArray.- Returns:
- the boolean array
-
hashCode
public int hashCode()
Returns a hash code value for this bit array.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this bit array.
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object- See Also:
Object.clone()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
-