| Modifier and Type | Field and Description |
|---|---|
| private byte | |
| private transient int | |
| private byte[] | value
Bits are stored as an array of bytes. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | FormatableBitSet(int
The number of bits in the set numBits)Constructs a Bit with the initial number of bits |
| public | FormatableBitSet(byte[]
The array of bytes to make up the new Bit newValue)Constructs a Bit from an array of bytes. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | and(FormatableBitSet
bitset operand otherBit)Bitwise AND this FormatableBitSet with another FormatableBitSet. |
| public int | Returns: the zero-based index of the first bit that is set, or -1 if no bit is setIf any bit is set, return the zero-based bit index of the first bit that is set. |
| public int | Returns: the bit number of a bit that is set, or -1 if no bit after beyondBit is setOnly look at bit that is greater than this bit number.
Supplying a value of -1 makes the call equivalent to
anySetBit(). beyondBit)Like anySetBit(), but return any set bit whose number is bigger than beyondBit. |
| private int | |
| private final void | |
| public void | |
| public void | |
| public Object | |
| public int | Returns: -1 - if other < this 0 - if other == this 1 - if other > thisthe other bit to compare to other)Bit comparison. |
| public void | |
| public boolean | Returns: TRUE|FALSEthe other bit to compare to other)Overrides java. Bit equivalence. |
| private static byte | Returns: the zero-based index of the first set bit in the argument bytea non-zero byte to check for set bits v)A utility method which treats the byte argument as an 8-bit bitset and finds the first set bit in that byte. |
| public final boolean | |
| public byte[] | |
| public int | Returns: The length in bits for this value NOTE: could possibly be changed to a long. As is we are restricted to 2^(31-3) -> 256meg instead of 2^31 (Integer.MAX_VALUE) like other datatypes (or 2 gig). If it is ever changed to a long be sure to change read/writeExternal which write out the length in bits.Get the length in bits |
| public int | |
| public int | Returns: The number of bits that are set.Get a count of the number of bits that are set. |
| public int | Returns: the formatID of this classImplements org. Get the formatID which corresponds to this class. |
| public void | grow(int
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. n)Grow (widen) a FormatableBitSet so that it contains at least N bits. |
| public int | Returns: the hash codeOverrides java. Produce a hash code by putting the value bytes into an int, exclusive OR'ing if there are more than 4 bytes. |
| private void | |
| public boolean | Returns: true if invariant holds, false otherwiseThis method returns true if the following conditions hold: 1. |
| public final boolean | |
| public static int | Returns: the corresponding bit countNumber of bits in given number of bytes numBytes)Statically calculates how many bits can fit into the number of bytes if this Bit object is externalized. |
| private static byte | Returns: the number of bitsbits bits)Figure out how many bits are in the last byte from the total number of bits. |
| private static int | Returns: the number of bytesbits bits)Figure out how many bytes are needed to store the input number of bits. |
| public void | or(FormatableBitSet
bitset operand otherBit)Bitwise OR this FormatableBitSet with another FormatableBitSet. |
| public void | readExternal(ObjectInput
the stream to read data from in order to restore the object in)Implements java.
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. |
| public void | |
| public void | shrink(int
The number of bits the caller wants. The
bits are always removed from the
least significant end of the bit array. n)Shrink (narrow) a FormatableBitSet to N bits. |
| public int | |
| public String | Returns: A new String containing the formatted Bit valueOverrides java. Format the string into BitSet format: {0, 2, 4, 8} if bits 0, 2, 4, 8 are set. |
| private static int | |
| private static byte | |
| private static int | |
| public void | writeExternal(ObjectOutput
the stream to write the object to out)Implements java. Format:
|
| public void | xor(FormatableBitSet
bitset operand otherBit)Bitwise XOR this FormatableBitSet with another FormatableBitSet. |
| bitsInLastByte | back to summary |
|---|---|
| private byte bitsInLastByte | |
| lengthAsBits | back to summary |
|---|---|
| private transient int lengthAsBits | |
| value | back to summary |
|---|---|
| private byte[] value Bits are stored as an array of bytes. Bits are numbered starting at 0. Bits 0..7 go in byte[0], 8..15 in byte[1] and so on. The number of bytes is tracked as part of the byte array. The number of bits being used is derived by the number of bytes being used and the number of bits being used by the last byte. The partially unused byte is always byte[byte.length] with the lowest bits being unused. Zero length bits are stored using a zero length byte array, with all bits marked as unused. | |
| FormatableBitSet | back to summary |
|---|---|
| public FormatableBitSet() Niladic Constructor | |
| FormatableBitSet | back to summary |
|---|---|
| public FormatableBitSet(int numBits) Constructs a Bit with the initial number of bits
| |
| FormatableBitSet | back to summary |
|---|---|
| public FormatableBitSet(byte[] newValue) Constructs a Bit from an array of bytes. Assume bytes are all being used.
| |
| FormatableBitSet | back to summary |
|---|---|
| public FormatableBitSet(FormatableBitSet original) Copy constructor
| |
| and | back to summary |
|---|---|
| public void and(FormatableBitSet otherBit) Bitwise AND this FormatableBitSet with another FormatableBitSet. The result is stored in this bitset. The operand is unaffected. A null operand is treated as an empty bitset (i.e. clearing this bitset). A bitset that is smaller than its operand is expanded to the same size.
| |
| anySetBit | back to summary |
|---|---|
| public int anySetBit() If any bit is set, return the zero-based bit index of the first bit that is set. If no bit is set, return -1. By using anySetBit() and anySetBit(beyondBit), one can quickly go thru the entire bit array to return all set bit.
| |
| anySetBit | back to summary |
|---|---|
| public int anySetBit(int beyondBit) Like anySetBit(), but return any set bit whose number is bigger than beyondBit. If no bit is set after beyondBit, -1 is returned. By using anySetBit() and anySetBit(beyondBit), one can quickly go thru the entire bit array to return all set bit.
| |
| calculateLength | back to summary |
|---|---|
| private int calculateLength(int realByteLength) | |
| checkPosition | back to summary |
|---|---|
| private final void checkPosition(int p) | |
| clear | back to summary |
|---|---|
| public void clear(int position) Bit clear
| |
| clear | back to summary |
|---|---|
| public void clear() Clear all the bits in this FormatableBitSet | |
| clone | back to summary |
|---|---|
| public Object clone() Overrides java. Doc from java. 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 will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
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
| |
| compare | back to summary |
|---|---|
| public int compare(FormatableBitSet other) Bit comparison. Compare this with other. Will always do a byte by byte compare. Given 2 similar bits of unequal lengths (x and y), where x.getLength() < y.getLength() but where: x[0..x.getLength()] == y[0..x.getLength()] then x < y.
| |
| copyFrom | back to summary |
|---|---|
| public void copyFrom(FormatableBitSet that) Copy the bytes from another FormatableBitSet. Assumes that this bit set is at least as large as the argument's bit set.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. Bit equivalence. Compare this with other. If the length is different, then cannot be equal so short circuit. Otherwise, rely on compare(). Note that two zero length bits are considered equal.
| |
| firstSet | back to summary |
|---|---|
| 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. Assumes that at least one bit in v is set (v!=0).
| |
| get | back to summary |
|---|---|
| public final boolean get(int position) Bit get -- alias for isSet()
| |
| getByteArray | back to summary |
|---|---|
| public byte[] getByteArray() Get the value of the byte array
| |
| getLength | back to summary |
|---|---|
| public int getLength() Get the length in bits
| |
| getLengthInBytes | back to summary |
|---|---|
| public int getLengthInBytes() Get the length in bytes of a Bit value
| |
| getNumBitsSet | back to summary |
|---|---|
| public int getNumBitsSet() Get a count of the number of bits that are set.
| |
| getTypeFormatId | back to summary |
|---|---|
| public int getTypeFormatId() Implements org. Get the formatID which corresponds to this class.
| |
| grow | back to summary |
|---|---|
| public void grow(int n) Grow (widen) a FormatableBitSet so that it contains at least N bits. If the bitset already has more than n bits, this is a noop. Negative values of n are not allowed. ASSUMPTIONS: that all extra bits in the last byte are zero.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Produce a hash code by putting the value bytes into an int, exclusive OR'ing if there are more than 4 bytes.
| |
| initializeBits | back to summary |
|---|---|
| private void initializeBits(int numBits) | |
| invariantHolds | back to summary |
|---|---|
| public boolean invariantHolds() This method returns true if the following conditions hold: 1. The number of bits in the bitset will fit into the allocated byte array. 2. 'lengthAsBits' and 'bitsInLastByte' are consistent. 3. All unused bits in the byte array are unset. This represents an invariant for the class, so this method should always return true. The method is public, but is primarily intended for testing and ASSERTS.
| |
| isSet | back to summary |
|---|---|
| public final boolean isSet(int position) Bit isSet
| |
| maxBitsForSpace | back to summary |
|---|---|
| public static int maxBitsForSpace(int numBytes) Statically calculates how many bits can fit into the number of bytes if this Bit object is externalized. Only valid for this implementation of Bit.
| |
| numBitsInLastByte | back to summary |
|---|---|
| private static byte numBitsInLastByte(int bits) Figure out how many bits are in the last byte from the total number of bits.
| |
| numBytesFromBits | back to summary |
|---|---|
| private static int numBytesFromBits(int bits) Figure out how many bytes are needed to store the input number of bits.
| |
| or | back to summary |
|---|---|
| public void or(FormatableBitSet otherBit) Bitwise OR this FormatableBitSet with another FormatableBitSet. The result is stored in this bitset. The operand is unaffected. A null operand is treated as an empty bitset (i.e. a noop). A bitset that is smaller than its operand is expanded to the same size.
| |
| readExternal | back to summary |
|---|---|
| public void readExternal(ObjectInput in) throws IOException Implements java. Note gracefully handles zero length bits -- will create a zero length array with no bits being used. Fortunately in.read() is ok with a zero length array so no special code. 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.
| |
| set | back to summary |
|---|---|
| public void set(int position) Bit set
| |
| shrink | back to summary |
|---|---|
| public void shrink(int n) Shrink (narrow) a FormatableBitSet to N bits. N may not be larger than the current bitset size, or negative.
| |
| size | back to summary |
|---|---|
| public int size() Get the length in bits -- alias for getLength()
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Format the string into BitSet format: {0, 2, 4, 8} if bits 0, 2, 4, 8 are set.
| |
| udiv8 | back to summary |
|---|---|
| private static int udiv8(int i) | |
| umod8 | back to summary |
|---|---|
| private static byte umod8(int i) | |
| umul8 | back to summary |
|---|---|
| private static int umul8(int i) | |
| writeExternal | back to summary |
|---|---|
| public void writeExternal(ObjectOutput out) throws IOException Implements java. Format:
| |
| xor | back to summary |
|---|---|
| public void xor(FormatableBitSet otherBit) Bitwise XOR this FormatableBitSet with another FormatableBitSet. The result is stored in this bitset. The operand is unaffected. A null operand is treated as an empty bitset (i.e. a noop). A bitset that is smaller than its operand is expanded to the same size.
| |