Package net.orbyfied.coldlib.util.logic
Interface BitFlag
public interface BitFlag
Represents a flag object, which can
be stored in a bit set (integer as well).
-
Method Summary
Modifier and TypeMethodDescriptionstatic BitFlagall()Create a new bit flag which will produce a full bit mask to cover all bits.static BitFlagat(int offset) Create a new basic bit flag with a specific bit offset set.default longGet the bit mask by shifting onegetBitOffset()times to the right.intGet the offset of the bit this flag uses in a bit set.default intset(int i, boolean value) Set the flag bit to the given value in the provided integer.default longset(long i, boolean value) Set the flag bit to the given value in the provided integer.default BitSetSet the flag bit to the given value in the provided bit set.
-
Method Details
-
at
Create a new basic bit flag with a specific bit offset set.- Parameters:
offset- The bit offset.- Returns:
- The flag instance.
-
all
Create a new bit flag which will produce a full bit mask to cover all bits. Bit offset is set to-1.- Returns:
- The flag instance.
-
getBitOffset
int getBitOffset()Get the offset of the bit this flag uses in a bit set. A value of-1will enable everything.- Returns:
- The offset.
-
getBitMask
default long getBitMask()Get the bit mask by shifting onegetBitOffset()times to the right. Will overflow and produce incorrect results if the bit offset is over 64 (maxlongcapacity). Then you will have to use aBitSetwithset(BitSet, boolean)instead of primitives.- Returns:
- The bit mask.
-
set
Set the flag bit to the given value in the provided bit set. Modifies the input bit set instance.- Parameters:
set- The bit set.value- True/false.- Returns:
- The same bit set instance.
-
set
default int set(int i, boolean value) Set the flag bit to the given value in the provided integer. Returns a new result value.- Parameters:
i- The input integer.value- True/false.- Returns:
- The output integer.
-
set
default long set(long i, boolean value) Set the flag bit to the given value in the provided integer. Returns a new result value.- Parameters:
i- The input integer.value- True/false.- Returns:
- The output integer.
-