java.io.Externalizable
, java.io.Serializable
, java.lang.Cloneable
, Formatable
, TypedFormat
public final class FormatableBitSet extends java.lang.Object implements Formatable, java.lang.Cloneable
Modifier and Type | Field | Description |
---|---|---|
private byte |
bitsInLastByte |
|
private int |
lengthAsBits |
|
private byte[] |
value |
Bits are stored as an array of bytes.
|
Constructor | Description |
---|---|
FormatableBitSet() |
Niladic Constructor
|
FormatableBitSet(byte[] newValue) |
Constructs a Bit from an array of bytes.
|
FormatableBitSet(int numBits) |
Constructs a Bit with the initial number of bits
|
FormatableBitSet(FormatableBitSet original) |
Copy constructor
|
Modifier and Type | Method | Description |
---|---|---|
void |
and(FormatableBitSet otherBit) |
Bitwise AND this FormatableBitSet with another
FormatableBitSet.
|
int |
anySetBit() |
If any bit is set, return the zero-based bit index of the first
bit that is set.
|
int |
anySetBit(int beyondBit) |
Like anySetBit(), but return any set bit whose number is bigger than
beyondBit.
|
private int |
calculateLength(int realByteLength) |
|
private void |
checkPosition(int p) |
|
void |
clear() |
Clear all the bits in this FormatableBitSet
|
void |
clear(int position) |
Bit clear
|
java.lang.Object |
clone() |
|
int |
compare(FormatableBitSet other) |
Bit comparison.
|
void |
copyFrom(FormatableBitSet that) |
Copy the bytes from another FormatableBitSet.
|
boolean |
equals(java.lang.Object other) |
Bit equivalence.
|
private static byte |
firstSet(byte v) |
A utility method which treats the byte argument as an 8-bit
bitset and finds the first set bit in that byte.
|
boolean |
get(int position) |
Bit get -- alias for isSet()
|
byte[] |
getByteArray() |
Get the value of the byte array
|
int |
getLength() |
Get the length in bits
|
int |
getLengthInBytes() |
Get the length in bytes of a Bit value
|
int |
getNumBitsSet() |
Get a count of the number of bits that are set.
|
int |
getTypeFormatId() |
Get the formatID which corresponds to this class.
|
void |
grow(int n) |
Grow (widen) a FormatableBitSet so that it contains at least N
bits.
|
int |
hashCode() |
Produce a hash code by putting the value bytes into an int, exclusive OR'ing
if there are more than 4 bytes.
|
private void |
initializeBits(int numBits) |
|
boolean |
invariantHolds() |
This method returns true if the following conditions hold:
1.
|
boolean |
isSet(int position) |
Bit isSet
|
static int |
maxBitsForSpace(int numBytes) |
Statically calculates how many bits can fit into the number of
bytes if this Bit object is externalized.
|
private static byte |
numBitsInLastByte(int bits) |
Figure out how many bits are in the last
byte from the total number of bits.
|
private static int |
numBytesFromBits(int bits) |
Figure out how many bytes are needed to
store the input number of bits.
|
void |
or(FormatableBitSet otherBit) |
Bitwise OR this FormatableBitSet with another
FormatableBitSet.
|
void |
readExternal(java.io.ObjectInput in) |
Note: gracefully handles zero length
bits -- will create a zero length array
with no bits being used.
|
void |
set(int position) |
Bit set
|
void |
shrink(int n) |
Shrink (narrow) a FormatableBitSet to N bits.
|
int |
size() |
Get the length in bits -- alias for getLength()
|
java.lang.String |
toString() |
Format the string into BitSet format: {0, 2, 4, 8} if bits 0, 2, 4, 8
are set.
|
private static int |
udiv8(int i) |
|
private static byte |
umod8(int i) |
|
private static int |
umul8(int i) |
|
void |
writeExternal(java.io.ObjectOutput out) |
Format:
int length in bits
byte[]
|
void |
xor(FormatableBitSet otherBit) |
Bitwise XOR this FormatableBitSet with another
FormatableBitSet.
|
private byte[] value
private byte bitsInLastByte
private transient int lengthAsBits
public FormatableBitSet()
public FormatableBitSet(int numBits)
public FormatableBitSet(byte[] newValue)
newValue
- The array of bytes to make up the new Bitpublic FormatableBitSet(FormatableBitSet original)
original
- the FormatableBitSet to make a copy fromprivate final void checkPosition(int p)
private static int udiv8(int i)
private static byte umod8(int i)
private static int umul8(int i)
private void initializeBits(int numBits)
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean invariantHolds()
public int getLengthInBytes()
public int getLength()
private int calculateLength(int realByteLength)
public int size()
public byte[] getByteArray()
public void grow(int n)
n
- The number of bits you want. The bits are
always added as 0 and are appended to the
least significant end of the bit array.public void shrink(int n)
n
- The number of bits the caller wants. The
bits are always removed from the
least significant end of the bit array.public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the other bit to compare topublic int compare(FormatableBitSet other)
other
- the other bit to compare topublic int hashCode()
hashCode
in class java.lang.Object
public final boolean isSet(int position)
position
- the bit to checkpublic final boolean get(int position)
position
- the bit to checkpublic void set(int position)
position
- the bit to setpublic void clear(int position)
position
- the bit to clearpublic void clear()
private static int numBytesFromBits(int bits)
bits
- bitsprivate static byte numBitsInLastByte(int bits)
bits
- bitspublic java.lang.String toString()
toString
in class java.lang.Object
public static int maxBitsForSpace(int numBytes)
private static byte firstSet(byte v)
v
- a non-zero byte to check for set bitspublic int anySetBit()
public int anySetBit(int beyondBit)
beyondBit
- Only look at bit that is greater than this bit number.
Supplying a value of -1 makes the call equivalent to
anySetBit().public void or(FormatableBitSet otherBit)
otherBit
- bitset operandpublic void copyFrom(FormatableBitSet that)
public void and(FormatableBitSet otherBit)
otherBit
- bitset operandpublic void xor(FormatableBitSet otherBit)
otherBit
- bitset operandpublic int getNumBitsSet()
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
Externalizable.writeExternal(java.io.ObjectOutput)
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
WARNING: this method cannot be changed w/o changing SQLBit because SQLBit calls this directly w/o calling read/writeObject(), so the format id is not stored in that case.
readExternal
in interface java.io.Externalizable
java.io.IOException
Externalizable.readExternal(java.io.ObjectInput)
public int getTypeFormatId()
getTypeFormatId
in interface TypedFormat
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.