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 that f
| 71 | * @since 2.0 |
| 72 | */ |
| 73 | public class BitField { |
| 74 | |
| 75 | private final long mask; |
| 76 | |
| 77 | private final int shiftCount; |
| 78 | |
| 79 | /** |
| 80 | * Creates a BitField instance. |
| 81 | * |
| 82 | * @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. |
| 83 | */ |
| 84 | public BitField(final int mask) { |
| 85 | this.mask = Integer.toUnsignedLong(mask); |
| 86 | this.shiftCount = this.mask == 0 ? 0 : Long.numberOfTrailingZeros(this.mask); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Creates a BitField instance. |
| 91 | * |
| 92 | * @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. |
| 93 | * @since 3.21.0 |
| 94 | */ |
| 95 | public BitField(final long mask) { |
| 96 | this.mask = mask; |
| 97 | this.shiftCount = mask == 0 ? 0 : Long.numberOfTrailingZeros(mask); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Clears the bits. |
| 102 | * |
| 103 | * @param holder the int data containing the bits we're interested in. |
| 104 | * @return the value of holder with the specified bits cleared (set to {@code 0}). |
| 105 | */ |
| 106 | public int clear(final int holder) { |
| 107 | return (int) (holder & ~mask); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Clears the bits. |
| 112 | * |
| 113 | * @param holder the long data containing the bits we're interested in. |
| 114 | * @return the value of holder with the specified bits cleared (set to {@code 0}). |
| 115 | * @since 3.21.0 |
| 116 | */ |
| 117 | public long clear(final long holder) { |
| 118 | return holder & ~mask; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Clears the bits. |
| 123 | * |
| 124 | * @param holder the byte data containing the bits we're interested in. |
| 125 | * @return the value of holder with the specified bits cleared (set to {@code 0}). |
| 126 | */ |
| 127 | public byte clearByte(final byte holder) { |
| 128 | return (byte) clear(holder); |
| 129 | } |
| 130 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…