APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.util

public Class BitArray

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, java.util.Arrays, jdk.internal.util.Preconditions

A packed array of booleans.
Authors
Joshua Bloch, Douglas Hoover

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private final int
private static final byte[][]
private final byte[]

Constructor Summary

AccessConstructor and Description
public
BitArray(int length)

Creates a BitArray of the specified size, initialized to zeros.

public
BitArray(int length, byte[] a)

Creates a BitArray of the specified size, initialized from the specified byte array.

public
BitArray(int length, byte[] a, int ofs)

Creates a BitArray of the specified size, initialized from the specified byte array starting at the specified offset.

public
BitArray(boolean[] bits)

Create a BitArray whose bits are those of the given array of Booleans.

private
BitArray(BitArray ba)

Copy constructor (for cloning).

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean
get(int index)

Returns the indexed bit in this BitArray.

public int

Returns:

a hash code value for this bit array
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this bit array.

public int
length()

Returns the length of this BitArray.

private static int
position(int idx)

public void
set(int index, boolean value)

Sets the indexed bit in this BitArray.

private static int
subscript(int idx)

public boolean[]
toBooleanArray()

Return a boolean array with the same bit values in this BitArray.

public byte[]
toByteArray()

Returns a Byte array containing the contents of this BitArray.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this BitArray.

public BitArray
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

BITS_PER_UNITback to summary
private static final int BITS_PER_UNIT
BYTES_PER_LINEback to summary
private static final int BYTES_PER_LINE
lengthback to summary
private final int length
NYBBLEback to summary
private static final byte[][] NYBBLE
repnback to summary
private final byte[] repn

Constructor Detail

BitArrayback to summary
public BitArray(int length) throws IllegalArgumentException

Creates a BitArray of the specified size, initialized to zeros.

BitArrayback to summary
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 must be large enough to specify a value for every bit of the BitArray, i.e. 8*a.length >= length.

BitArrayback to summary
public BitArray(int length, byte[] a, int ofs) throws IllegalArgumentException

Creates a BitArray of the specified size, initialized from the specified byte array starting at the specified offset. The most significant bit of a[ofs] gets index zero in the BitArray. The array must be large enough to specify a value for every bit of the BitArray, i.e. 8*(a.length - ofs) >= length.

BitArrayback to summary
public BitArray(boolean[] bits)

Create a BitArray whose bits are those of the given array of Booleans.

Annotations
@SuppressWarnings:this-escape
BitArrayback to summary
private BitArray(BitArray ba)

Copy constructor (for cloning).

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getback to summary
public boolean get(int index) throws ArrayIndexOutOfBoundsException

Returns the indexed bit in this BitArray.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this bit array.

Returns:int

a hash code value for this bit array

Annotations
@Override
lengthback to summary
public int length()

Returns the length of this BitArray.

positionback to summary
private static int position(int idx)
setback to summary
public void set(int index, boolean value) throws ArrayIndexOutOfBoundsException

Sets the indexed bit in this BitArray.

subscriptback to summary
private static int subscript(int idx)
toBooleanArrayback to summary
public boolean[] toBooleanArray()

Return a boolean array with the same bit values in this BitArray.

toByteArrayback to summary
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 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.)

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this BitArray.

truncateback to summary
public BitArray truncate()