/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A packed array of booleans.
*
* @author Joshua Bloch
* @author Douglas Hoover
*/
public class BitArray {
private byte[] repn;
private int length;
return idx / BITS_PER_UNIT;
}
}
/**
* Creates a BitArray of the specified size, initialized to zeros.
*/
if (length < 0) {
throw new IllegalArgumentException("Negative length for BitArray");
}
}
/**
* 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.
*/
if (length < 0) {
throw new IllegalArgumentException("Negative length for BitArray");
}
throw new IllegalArgumentException("Byte array too short to represent " +
"bit array of given length");
}
/*
normalize the representation:
1. discard extra bytes
2. zero out extra bits in the last byte
*/
if (repLength > 0) {
}
}
/**
* Create a BitArray whose bits are those of the given array
* of Booleans.
*/
for (int i=0; i < length; i++) {
}
}
/**
* Copy constructor (for cloning).
*/
}
/**
* Returns the indexed bit in this BitArray.
*/
}
}
/**
* Sets the indexed bit in this BitArray.
*/
throws ArrayIndexOutOfBoundsException {
}
if (value) {
} else {
}
}
/**
* Returns the length of this BitArray.
*/
public int length() {
return length;
}
/**
* 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.)
*/
public byte[] toByteArray() {
}
if (obj == this) return true;
}
return true;
}
/**
* Return a boolean array with the same bit values a this BitArray.
*/
public boolean[] toBooleanArray() {
for (int i=0; i < length; i++) {
}
return bits;
}
/**
* Returns a hash code value for this bit array.
*
* @return a hash code value for this bit array.
*/
public int hashCode() {
int hashCode = 0;
}
return new BitArray(this);
}
private static final byte[][] NYBBLE = {
{ (byte)'0',(byte)'0',(byte)'0',(byte)'0'},
{ (byte)'0',(byte)'0',(byte)'0',(byte)'1'},
{ (byte)'0',(byte)'0',(byte)'1',(byte)'0'},
{ (byte)'0',(byte)'0',(byte)'1',(byte)'1'},
{ (byte)'0',(byte)'1',(byte)'0',(byte)'0'},
{ (byte)'0',(byte)'1',(byte)'0',(byte)'1'},
{ (byte)'0',(byte)'1',(byte)'1',(byte)'0'},
{ (byte)'0',(byte)'1',(byte)'1',(byte)'1'},
{ (byte)'1',(byte)'0',(byte)'0',(byte)'0'},
{ (byte)'1',(byte)'0',(byte)'0',(byte)'1'},
{ (byte)'1',(byte)'0',(byte)'1',(byte)'0'},
{ (byte)'1',(byte)'0',(byte)'1',(byte)'1'},
{ (byte)'1',(byte)'1',(byte)'0',(byte)'0'},
{ (byte)'1',(byte)'1',(byte)'0',(byte)'1'},
{ (byte)'1',(byte)'1',(byte)'1',(byte)'0'},
{ (byte)'1',(byte)'1',(byte)'1',(byte)'1'}
};
/**
* Returns a string representation of this BitArray.
*/
} else {
}
}
// in last byte of repn, use only the valid bits
}
}
if (get(i)) {
}
}
return new BitArray(1);
}
}