Skip to content

Conversation

@theodoral22
Copy link

Summary

This PR introduces a new class LongBitField that extends the concept of BitField to support 64-bit values (long).
The existing BitField only supports int, short and byte, which is insufficient for modern use cases involving large flags or 64-bit bitsets.

Features

  • Supports all basic bit operations: set, clear, setBoolean, getValue, getRawValue, isSet, isAllSet.
  • Operates on long values to allow 64-bit flags.
  • Fully unit-tested in LongBitFieldTest.java, covering:
    -> Single-bit and multi-bit masks
    -> Edge cases (lowest and highest bits)
    -> Boolean set/clear operations
    -> Setting and getting values
  • Designed to be consistent with BitField API for easy adoption.

Motivation

  • 'BitField' is limited to 32-bit integers (int). Many modern applications require 64-bit flags or large bitsets.
  • This class provides a direct, intuitive solution for such cases without needing to manually manipulate long values.

Testing

  • All methods are covered by JUnit tests in LongBitFieldTest.java.
  • Tests validate correctness of all bit operations, including edge cases.
  • Tests can be run using standard Maven/Gradle build for Apache Commons Lang.

Copy link
Member

@garydgregory garydgregory left a 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)
Copy link
Member

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.
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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;

Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.

@theodoral22
Copy link
Author

Thank you for reviewing my PR.
I have made some changes based on your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants