-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add LongBitField class for 64-bit operations with tests #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theodoral22
Thank you for the PR. Some minor comments to address throughout.
| * System.out.println(high8.getValue(value)); // 0x56 | ||
| * </pre> | ||
| * | ||
| * @since 3.13 (example) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong.
| } | ||
|
|
||
| /** | ||
| * Obtains the value for the specified LongBitField, unshifted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A getter "Gets..."
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LongBitFieldTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file must end in an empty line.
| public void testSetBoolean() { | ||
| LongBitField field = new LongBitField(0x1000L); // bit 12 | ||
| long holder = 0x0000L; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty lines.
| } | ||
|
|
||
| /** | ||
| * Replaces the bits with new values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A setter "Sets..."
| /** | ||
| * Tests whether any bit in the field is set. | ||
| * | ||
| * @param holder the long data containing the bits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentences should end in a period.
|
Thank you for reviewing my PR. |
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.