Supports operations on bit-mapped fields. Instances of this class can be used to store a flag or data within an int, short or byte. Each BitField is constructed with a mask value, which indicates the bits that will be used to store and retrieve the data for
| 71 | * @since 2.0 |
| 72 | */ |
| 73 | public class BitField { |
| 74 | |
| 75 | private final int _mask; |
| 76 | private final int _shift_count; |
| 77 | |
| 78 | /** |
| 79 | * <p>Creates a BitField instance.</p> |
| 80 | * |
| 81 | * @param mask the mask specifying which bits apply to this |
| 82 | * BitField. Bits that are set in this mask are the bits |
| 83 | * that this BitField operates on |
| 84 | */ |
| 85 | public BitField(final int mask) { |
| 86 | _mask = mask; |
| 87 | _shift_count = mask == 0 ? 0 : Integer.numberOfTrailingZeros(mask); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * <p>Obtains the value for the specified BitField, appropriately |
| 92 | * shifted right.</p> |
| 93 | * |
| 94 | * <p>Many users of a BitField will want to treat the specified |
| 95 | * bits as an int value, and will not want to be aware that the |
| 96 | * value is stored as a BitField (and so shifted left so many |
| 97 | * bits).</p> |
| 98 | * |
| 99 | * @see #setValue(int,int) |
| 100 | * @param holder the int data containing the bits we're interested |
| 101 | * in |
| 102 | * @return the selected bits, shifted right appropriately |
| 103 | */ |
| 104 | public int getValue(final int holder) { |
| 105 | return getRawValue(holder) >> _shift_count; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * <p>Obtains the value for the specified BitField, appropriately |
| 110 | * shifted right, as a short.</p> |
| 111 | * |
| 112 | * <p>Many users of a BitField will want to treat the specified |
| 113 | * bits as an int value, and will not want to be aware that the |
| 114 | * value is stored as a BitField (and so shifted left so many |
| 115 | * bits).</p> |
| 116 | * |
| 117 | * @see #setShortValue(short,short) |
| 118 | * @param holder the short data containing the bits we're |
| 119 | * interested in |
| 120 | * @return the selected bits, shifted right appropriately |
| 121 | */ |
| 122 | public short getShortValue(final short holder) { |
| 123 | return (short) getValue(holder); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * <p>Obtains the value for the specified BitField, unshifted.</p> |
| 128 | * |
| 129 | * @param holder the int data containing the bits we're |
| 130 | * interested in |
nothing calls this directly
no outgoing calls
no test coverage detected