Add LongBitField class for 64-bit operations with tests#1552
Add LongBitField class for 64-bit operations with tests#1552theodoral22 wants to merge 2 commits intoapache:masterfrom
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
@theodoral22
Thank you for the PR. Some minor comments to address throughout.
| * System.out.println(high8.getValue(value)); // 0x56 | ||
| * </pre> | ||
| * | ||
| * @since 3.13 (example) |
| } | ||
|
|
||
| /** | ||
| * Obtains the value for the specified LongBitField, unshifted. |
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LongBitFieldTest { |
There was a problem hiding this comment.
The class and test methods should not be public to follow JUnit 5 guidelines.
| public long setValue(final long holder, final long value) { | ||
| return holder & ~mask | (value << shiftCount) & mask; | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
The file must end in an empty line.
| public void testSetBoolean() { | ||
| LongBitField field = new LongBitField(0x1000L); // bit 12 | ||
| long holder = 0x0000L; | ||
|
|
| } | ||
|
|
||
| /** | ||
| * Replaces the bits with new values. |
| /** | ||
| * Tests whether any bit in the field is set. | ||
| * | ||
| * @param holder the long data containing the bits |
There was a problem hiding this comment.
Sentences should end in a period.
|
Thank you for reviewing my PR. |
|
Adding another class seems heavy. What do you think about updating |
|
Yeah sure. That's perfect. Are you going to use the #1561? |
|
@theodoral22 |
|
Ok. Thank you for your cooperation. |
|
Just to make sure, do you want me to make other changes or everything’s ok? |
|
Hello @theodoral22 |
|
Hello @theodoral22 I merged #1561 and credited you in Thank you! |
|
Hello @garydgregory |
Summary
This PR introduces a new class
LongBitFieldthat extends the concept ofBitFieldto support 64-bit values (long).The existing
BitFieldonly supportsint,shortandbyte, which is insufficient for modern use cases involving large flags or 64-bit bitsets.Features
set,clear,setBoolean,getValue,getRawValue,isSet,isAllSet.longvalues to allow 64-bit flags.LongBitFieldTest.java, covering:-> Single-bit and multi-bit masks
-> Edge cases (lowest and highest bits)
-> Boolean set/clear operations
-> Setting and getting values
BitFieldAPI for easy adoption.Motivation
int). Many modern applications require 64-bit flags or large bitsets.longvalues.Testing
LongBitFieldTest.java.