Class BitSetHelper


  • @Immutable
    public final class BitSetHelper
    extends Object
    Helper class to work with bit sets.
    Author:
    Philip Helger
    • Method Detail

      • createBitSet

        @Nonnull
        public static BitSet createBitSet​(byte nValue)
        Convert the passed byte value to an bit set of size 8.
        Parameters:
        nValue - The value to be converted to a bit set.
        Returns:
        The non-null bit set.
      • createBitSet

        @Nonnull
        public static BitSet createBitSet​(short nValue)
        Convert the passed short value to an bit set of size 16.
        Parameters:
        nValue - The value to be converted to a bit set.
        Returns:
        The non-null bit set.
      • createBitSet

        @Nonnull
        public static BitSet createBitSet​(int nValue)
        Convert the passed int value to an bit set of size 32.
        Parameters:
        nValue - The value to be converted to a bit set.
        Returns:
        The non-null bit set.
      • createBitSet

        @Nonnull
        public static BitSet createBitSet​(long nValue)
        Convert the passed long value to an bit set of size 64.
        Parameters:
        nValue - The value to be converted to a bit set.
        Returns:
        The non-null bit set.
      • getExtractedIntValue

        public static int getExtractedIntValue​(@Nonnull
                                               BitSet aBS)
        Extract the int representation of the passed bit set. To avoid loss of data, the bit set may not have more than 32 bits.
        Parameters:
        aBS - The bit set to extract the value from. May not be null.
        Returns:
        The extracted value. May be negative if the bit set has 32 elements, the highest order bit is set.
      • getExtractedLongValue

        public static long getExtractedLongValue​(@Nonnull
                                                 BitSet aBS)
        Extract the long representation of the passed bit set. To avoid loss of data, the bit set may not have more than 64 bits.
        Parameters:
        aBS - The bit set to extract the value from. May not be null.
        Returns:
        The extracted value. May be negative if the bit set has 64 elements, the highest order bit is set.