Class Flags

java.lang.Object
com.pnfsoftware.jeb.util.base.Flags

@Ser public class Flags extends Object
Bit flags object, int based (allow 32 bit flags).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create flags with the initial value 0.
    Flags(int initial)
    Create flags.
    Flags(int initialFlags, int allowedFlags, Map<Integer,String> names)
    Create flags and specify which bits (0..31) are legal parts of the flags.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addTo(int f)
    Add (set) bits to the current flags.
    int
    get()
    Get the current flags.
    static boolean
    has(int flags, int bits)
    Flags utility: determine if the provided bit(s) is/are set
    boolean
    hasAll(int f)
    Determine if all of the provided bits are currently set.
    boolean
    hasNone(int f)
    Determine if none of the provided bits are currently set.
    boolean
    hasSome(int f)
    Determine if some of the provided bits are currently set.
    boolean
    isValidBit(int bit)
    Determine whether a bit index is legal for this flag set.
    boolean
    removeFrom(int f)
    Remove (reset) bits from the current flags.
    boolean
    set(int flags)
    Set the flags.
    static int
    set(int flags, int bits, boolean enabled)
    Flags utility: set or reset bits.
    boolean
    testBit(int bit)
    Determine whether a bit is currently set.
     
    boolean
    update(int f, boolean add)
    Add or remove bits to the current flags.
    void
    verify(int f)
    Verify that the provided flags only contain allowed bits.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Flags

      public Flags()
      Create flags with the initial value 0.
    • Flags

      public Flags(int initial)
      Create flags.
      Parameters:
      initial - initial flags value
    • Flags

      public Flags(int initialFlags, int allowedFlags, Map<Integer,String> names)
      Create flags and specify which bits (0..31) are legal parts of the flags.
      Parameters:
      initialFlags - initial flags value
      allowedFlags - legal bit flags; 0xFFFFFFFF (-1) means all bits are legal and can be accessed
      names - optional bit names
  • Method Details

    • verify

      public void verify(int f)
      Verify that the provided flags only contain allowed bits.
      Parameters:
      f - flags to verify
      Throws:
      IllegalArgumentException - if an illegal bit is set
    • get

      public int get()
      Get the current flags.
      Returns:
      current flags
    • set

      public boolean set(int flags)
      Set the flags.
      Parameters:
      flags - new flags value
      Returns:
      true if the flags have changed, false otherwise
    • isValidBit

      public boolean isValidBit(int bit)
      Determine whether a bit index is legal for this flag set.
      Parameters:
      bit - bit index, from 0 to 31
      Returns:
      true if the bit is in range and allowed
    • testBit

      public boolean testBit(int bit)
      Determine whether a bit is currently set.
      Parameters:
      bit - bit index, from 0 to 31
      Returns:
      true if the bit is set
      Throws:
      IllegalArgumentException - if the bit index is out of range
    • hasAll

      public boolean hasAll(int f)
      Determine if all of the provided bits are currently set.
      Parameters:
      f - bits to test
      Returns:
      true if all bits are set
    • hasSome

      public boolean hasSome(int f)
      Determine if some of the provided bits are currently set.
      Parameters:
      f - bits to test
      Returns:
      true if at least one bit is set
    • hasNone

      public boolean hasNone(int f)
      Determine if none of the provided bits are currently set.
      Parameters:
      f - bits to test
      Returns:
      true if none of the bits are set
    • addTo

      public boolean addTo(int f)
      Add (set) bits to the current flags.
      Parameters:
      f - flags to be added
      Returns:
      true if the overall flags have changed, false otherwise
    • removeFrom

      public boolean removeFrom(int f)
      Remove (reset) bits from the current flags.
      Parameters:
      f - flags to be removed
      Returns:
      true if the overall flags have changed, false otherwise
    • update

      public boolean update(int f, boolean add)
      Add or remove bits to the current flags.
      Parameters:
      f - flags to be added or remove
      add - true to add flags, false to remove flags
      Returns:
      true if the overall flags have changed, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • set

      public static int set(int flags, int bits, boolean enabled)
      Flags utility: set or reset bits.
      Parameters:
      flags - current flags
      bits - bit(s) to set or reset
      enabled - true to set, false to reset
      Returns:
      updated flags
    • has

      public static boolean has(int flags, int bits)
      Flags utility: determine if the provided bit(s) is/are set
      Parameters:
      flags - current flags
      bits - bits to check
      Returns:
      true if the provided bits are all set, false otherwise