FileDocCategorySizeDatePackage
BitField.javaAPI DocApache Poi 3.0.18974Mon Jan 01 12:39:42 GMT 2007org.apache.poi.util

BitField

public class BitField extends Object
Manage operations dealing with bit-mapped fields.
author
Marc Johnson (mjohnson at apache dot org)
author
Andrew C. Oliver (acoliver at apache dot org)

Fields Summary
private final int
_mask
private final int
_shift_count
Constructors Summary
public BitField(int mask)
Create a BitField instance

param
mask the mask specifying which bits apply to this BitField. Bits that are set in this mask are the bits that this BitField operates on

        _mask = mask;
        int count       = 0;
        int bit_pattern = mask;

        if (bit_pattern != 0)
        {
            while ((bit_pattern & 1) == 0)
            {
                count++;
                bit_pattern >>= 1;
            }
        }
        _shift_count = count;
    
Methods Summary
public intclear(int holder)
Clear the bits.

param
holder the int data containing the bits we're interested in
return
the value of holder with the specified bits cleared (set to 0)

        return holder & ~_mask;
    
public byteclearByte(byte holder)
Clear the bits.

param
holder the byte data containing the bits we're interested in
return
the value of holder with the specified bits cleared (set to 0)

        return ( byte ) clear(holder);
    
public shortclearShort(short holder)
Clear the bits.

param
holder the short data containing the bits we're interested in
return
the value of holder with the specified bits cleared (set to 0)

        return ( short ) clear(holder);
    
public intgetRawValue(int holder)
Obtain the value for the specified BitField, unshifted

param
holder the int data containing the bits we're interested in
return
the selected bits

        return (holder & _mask);
    
public shortgetShortRawValue(short holder)
Obtain the value for the specified BitField, unshifted

param
holder the short data containing the bits we're interested in
return
the selected bits

        return ( short ) getRawValue(holder);
    
public shortgetShortValue(short holder)
Obtain the value for the specified BitField, appropriately shifted right, as a short. Many users of a BitField will want to treat the specified bits as an int value, and will not want to be aware that the value is stored as a BitField (and so shifted left so many bits)

param
holder the short data containing the bits we're interested in
return
the selected bits, shifted right appropriately

        return ( short ) getValue(holder);
    
public intgetValue(int holder)
Obtain the value for the specified BitField, appropriately shifted right. Many users of a BitField will want to treat the specified bits as an int value, and will not want to be aware that the value is stored as a BitField (and so shifted left so many bits)

param
holder the int data containing the bits we're interested in
return
the selected bits, shifted right appropriately

        return getRawValue(holder) >> _shift_count;
    
public booleanisAllSet(int holder)
Are all of the bits set or not? This is a stricter test than isSet, in that all of the bits in a multi-bit set must be set for this method to return true

param
holder the int data containing the bits we're interested in
return
true if all of the bits are set, else false

        return (holder & _mask) == _mask;
    
public booleanisSet(int holder)
Is the field set or not? This is most commonly used for a single-bit field, which is often used to represent a boolean value; the results of using it for a multi-bit field is to determine whether *any* of its bits are set

param
holder the int data containing the bits we're interested in
return
true if any of the bits are set, else false

        return (holder & _mask) != 0;
    
public intset(int holder)
Set the bits.

param
holder the int data containing the bits we're interested in
return
the value of holder with the specified bits set to 1

        return holder | _mask;
    
public intsetBoolean(int holder, boolean flag)
Set a boolean BitField

param
holder the int data containing the bits we're interested in
param
flag indicating whether to set or clear the bits
return
the value of holder with the specified bits set or cleared

        return flag ? set(holder)
                    : clear(holder);
    
public bytesetByte(byte holder)
Set the bits.

param
holder the byte data containing the bits we're interested in
return
the value of holder with the specified bits set to 1

        return ( byte ) set(holder);
    
public bytesetByteBoolean(byte holder, boolean flag)
Set a boolean BitField

param
holder the byte data containing the bits we're interested in
param
flag indicating whether to set or clear the bits
return
the value of holder with the specified bits set or cleared

        return flag ? setByte(holder)
                    : clearByte(holder);
    
public shortsetShort(short holder)
Set the bits.

param
holder the short data containing the bits we're interested in
return
the value of holder with the specified bits set to 1

        return ( short ) set(holder);
    
public shortsetShortBoolean(short holder, boolean flag)
Set a boolean BitField

param
holder the short data containing the bits we're interested in
param
flag indicating whether to set or clear the bits
return
the value of holder with the specified bits set or cleared

        return flag ? setShort(holder)
                    : clearShort(holder);
    
public shortsetShortValue(short holder, short value)
Replace the bits with new values.

param
holder the short data containing the bits we're interested in
param
value the new value for the specified bits
return
the value of holder with the bits from the value parameter replacing the old bits

        return ( short ) setValue(holder, value);
    
public intsetValue(int holder, int value)
Replace the bits with new values.

param
holder the int data containint the bits we're interested in
param
value the new value for the specified bits
return
the value of holder with the bits from the value parameter replacing the old bits

        return (holder & ~_mask) | ((value << _shift_count) & _mask);