|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> services >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.iapi.services.io
Class FormatableBitSet

java.lang.Objectorg.apache.derby.iapi.services.io.FormatableBitSet
- All Implemented Interfaces:
- java.lang.Cloneable, java.io.Externalizable, Formatable, java.io.Serializable, TypedFormat
- public final class FormatableBitSet
- extends java.lang.Object
- implements Formatable, java.lang.Cloneable
- extends java.lang.Object
FormatableBitSet is implemented as a packed array of bytes.
| Field Summary | |
private short |
bitsInLastByte
|
private static char[] |
decodeArray
|
private int |
lengthAsBits
|
private byte[] |
value
Bits are stored as an array of bytes. |
| Constructor Summary | |
FormatableBitSet()
Niladic Constructor |
|
FormatableBitSet(byte[] newValue)
Constructs a Bit from an array of bytes. |
|
FormatableBitSet(byte[] newValue,
int numBits)
Constructs a Bit from an array of bytes. |
|
FormatableBitSet(FormatableBitSet original)
Copy constructor |
|
FormatableBitSet(int numBits)
Constructs a Bit with the initial number of bits |
|
| Method Summary | |
void |
and(FormatableBitSet otherBit)
Bitwise AND this Bit with another Bit. |
int |
anySetBit()
If any bit is set, return the bit number of a 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)
|
void |
clear()
Clear all the bits in this FormatableBitSet |
void |
clear(int position)
Bit clear |
java.lang.Object |
clone()
This method may be called to create a new copy of the Object. |
int |
compare(FormatableBitSet other)
Bit comparison. |
FormatableBitSet |
concatenate(FormatableBitSet other)
Bit concatenation. |
boolean |
equals(FormatableBitSet other)
Bit equivalence. |
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 to N bis |
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 static byte |
hexCharToByte(char hexChar)
Translate a hex character to a byte. |
private void |
initializeBits(int numBits)
|
boolean |
isNull()
Set the value of the byte array |
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 short |
numBitsInLastByte(int bits)
Figure out how many bits are in the last byte from the total number of bits. |
protected 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 Bit with another Bit. |
void |
readExternal(java.io.ObjectInput in)
Note: gracefully handles zero length bits -- will create a zero length array with no bits being used. |
void |
readExternalFromArray(ArrayInputStream in)
|
void |
set(int position)
Bit set |
FormatableBitSet |
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. |
void |
writeExternal(java.io.ObjectOutput out)
Format: int length in bits byte[] |
void |
xor(FormatableBitSet set)
Logically XORs this FormatableBitSet with the specified FormatableBitSet. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
value
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.
bitsInLastByte
private short bitsInLastByte
lengthAsBits
private transient int lengthAsBits
decodeArray
private static char[] decodeArray
| Constructor Detail |
FormatableBitSet
public FormatableBitSet()
- Niladic Constructor
FormatableBitSet
public FormatableBitSet(int numBits)
- Constructs a Bit with the initial number of bits
FormatableBitSet
public FormatableBitSet(byte[] newValue)
- Constructs a Bit from an array of bytes. Assume
bytes are all being used.
FormatableBitSet
public FormatableBitSet(byte[] newValue,
int numBits)
- Constructs a Bit from an array of bytes.
FormatableBitSet
public FormatableBitSet(FormatableBitSet original)
- Copy constructor
| Method Detail |
initializeBits
private void initializeBits(int numBits)
clone
public java.lang.Object clone()
- Description copied from class:
java.lang.Object - This method may be called to create a new copy of the
Object. The typical behavior is as follows:
o == o.clone()is falseo.getClass() == o.clone().getClass()is trueo.equals(o)is true
However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>
Object.equals(Object)55 .If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.
Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.
All array types implement Cloneable, and override this method as follows (it should never fail):
public Object clone() { try { super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(e.getMessage()); } }
getLengthInBytes
public int getLengthInBytes()
- Get the length in bytes of a Bit value
getLength
public int getLength()
- Get the length in bits
calculateLength
private int calculateLength(int realByteLength)
size
public int size()
- Get the length in bits -- alias for getLength()
getByteArray
public byte[] getByteArray()
- Get the value of the byte array
isNull
public boolean isNull()
- Set the value of the byte array
grow
public void grow(int n)
- Grow (widen) a FormatableBitSet to N bis
shrink
public FormatableBitSet shrink(int n)
- Shrink (narrow) a FormatableBitSet to N bits
equals
public boolean equals(FormatableBitSet other)
- 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.
compare
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.
concatenate
public FormatableBitSet concatenate(FormatableBitSet other)
- Bit concatenation.
hashCode
public int hashCode()
- Produce a hash code by putting the value bytes into an int, exclusive OR'ing
if there are more than 4 bytes.
isSet
public final boolean isSet(int position)
- Bit isSet
get
public final boolean get(int position)
- Bit get -- alias for isSet()
set
public void set(int position)
- Bit set
clear
public void clear(int position)
- Bit clear
clear
public void clear()
- Clear all the bits in this FormatableBitSet
numBytesFromBits
protected static int numBytesFromBits(int bits)
- Figure out how many bytes are needed to
store the input number of bits.
numBitsInLastByte
private static short numBitsInLastByte(int bits)
- Figure out how many bits are in the last
byte from the total number of bits.
hexCharToByte
private static byte hexCharToByte(char hexChar)
- Translate a hex character to a byte.
toString
public java.lang.String toString()
- Format the string into BitSet format: {0, 2, 4, 8} if bits 0, 2, 4, 8
are set.
maxBitsForSpace
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.
anySetBit
public int anySetBit()
- If any bit is set, return the bit number of a bit that is set.
If no bit is set, return -1;
anySetBit
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.
or
public void or(FormatableBitSet otherBit)
- Bitwise OR this Bit with another Bit.
and
public void and(FormatableBitSet otherBit)
- Bitwise AND this Bit with another Bit.
xor
public void xor(FormatableBitSet set)
- Logically XORs this FormatableBitSet with the specified FormatableBitSet.
getNumBitsSet
public int getNumBitsSet()
- Get a count of the number of bits that are set.
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Format:
- int length in bits
- byte[]
- Specified by:
writeExternalin interfacejava.io.Externalizable
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
- 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.
- Specified by:
readExternalin interfacejava.io.Externalizable
readExternalFromArray
public void readExternalFromArray(ArrayInputStream in) throws java.io.IOException
getTypeFormatId
public int getTypeFormatId()
- Get the formatID which corresponds to this class.
- Specified by:
getTypeFormatIdin interfaceTypedFormat
|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> services >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.derby.iapi.services.io.FormatableBitSet