Class BitSetter


  • public class BitSetter
    extends Object
    Static function to manipulate bits inside an int or long.
    Since:
    4.1
    • Constructor Summary

      Constructors 
      Constructor Description
      BitSetter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isFlagSet​(int flags, int bitIndex)
      Tests if a flag with the given index is set in a 32-bit collection of flags.
      static boolean isFlagSet​(long flags, int bitIndex)
      Tests if a flag with the given index is set in a 64-bit collection of flags.
      static int setFlag​(int flags, int bitIndex)
      Sets a flag with the given index in a 32-bit collection of flags.
      static int setFlag​(int flags, int bitIndex, boolean cond)
      Sets a flag with the given index in a 32-bit collection of flags if a given condition is true.
      static long setFlag​(long flags, int bitIndex)
      Sets a flag with the given index in a 64-bit collection of flags.
      static long setFlag​(long flags, int bitIndex, boolean cond)
      Sets a flag with the given index in a 64-bit collection of flags if a given condition is true.
    • Constructor Detail

      • BitSetter

        public BitSetter()
    • Method Detail

      • isFlagSet

        public static boolean isFlagSet​(int flags,
                                        int bitIndex)
        Tests if a flag with the given index is set in a 32-bit collection of flags.
        Parameters:
        flags - a collection of a maximum of 32 flags
        bitIndex - the zero-based index of the flag to be tested
        Returns:
        true if the flag is set
      • isFlagSet

        public static boolean isFlagSet​(long flags,
                                        int bitIndex)
        Tests if a flag with the given index is set in a 64-bit collection of flags.
        Parameters:
        flags - a collection of a maximum of 64 flags
        bitIndex - the zero-based index of the flag to be tested
        Returns:
        true if the flag is set
      • setFlag

        public static int setFlag​(int flags,
                                  int bitIndex)
        Sets a flag with the given index in a 32-bit collection of flags.
        Parameters:
        flags - a collection of a maximum of 32 flags
        bitIndex - the zero-based index of the flag to be set
        Returns:
        the collection of flags with the given flag set
      • setFlag

        public static long setFlag​(long flags,
                                   int bitIndex)
        Sets a flag with the given index in a 64-bit collection of flags.
        Parameters:
        flags - a collection of a maximum of 64 flags
        bitIndex - the zero-based index of the flag to be set
        Returns:
        the collection of flags with the given flag set
      • setFlag

        public static int setFlag​(int flags,
                                  int bitIndex,
                                  boolean cond)
        Sets a flag with the given index in a 32-bit collection of flags if a given condition is true.
        Parameters:
        flags - a collection of a maximum of 32 flags
        bitIndex - the zero-based index of the flag to be set
        cond - the condition
        Returns:
        the collection of flags with the given flag possibly set
      • setFlag

        public static long setFlag​(long flags,
                                   int bitIndex,
                                   boolean cond)
        Sets a flag with the given index in a 64-bit collection of flags if a given condition is true.
        Parameters:
        flags - a collection of a maximum of 64 flags
        bitIndex - the zero-based index of the flag to be set
        cond - the condition
        Returns:
        the collection of flags with the given flag possibly set