Interface BitFlag


public interface BitFlag
Represents a flag object, which can be stored in a bit set (integer as well).
  • Method Summary

    Modifier and Type
    Method
    Description
    static BitFlag
    all()
    Create a new bit flag which will produce a full bit mask to cover all bits.
    static BitFlag
    at(int offset)
    Create a new basic bit flag with a specific bit offset set.
    default long
    Get the bit mask by shifting one getBitOffset() times to the right.
    int
    Get the offset of the bit this flag uses in a bit set.
    default int
    set(int i, boolean value)
    Set the flag bit to the given value in the provided integer.
    default long
    set(long i, boolean value)
    Set the flag bit to the given value in the provided integer.
    default BitSet
    set(BitSet set, boolean value)
    Set the flag bit to the given value in the provided bit set.
  • Method Details

    • at

      static BitFlag at(int offset)
      Create a new basic bit flag with a specific bit offset set.
      Parameters:
      offset - The bit offset.
      Returns:
      The flag instance.
    • all

      static BitFlag 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 -1 will enable everything.
      Returns:
      The offset.
    • getBitMask

      default long getBitMask()
      Get the bit mask by shifting one getBitOffset() times to the right. Will overflow and produce incorrect results if the bit offset is over 64 (max long capacity). Then you will have to use a BitSet with set(BitSet, boolean) instead of primitives.
      Returns:
      The bit mask.
    • set

      default BitSet set(BitSet set, boolean value)
      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.