de.caff.util

## Class BitSetBitMask

- java.lang.Object
- - de.caff.util.BitSetBitMask

- All Implemented Interfaces:
    BitMask

      public final class BitSetBitMask
      extends java.lang.Object
      implements BitMask

  A bit set based bit mask. This allows for arbitrary sized bit counts. This class is immutable.
  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static BitSetBitMask` | `ZERO` Bit set bit mask with no bits set.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BitSetBitMask(java.util.BitSet bitSet)` Constructor.
    `BitSetBitMask(int flagCount)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `BitMask` | `and(BitMask other)` Get the result of a logical and of this bit mask and another.
    `BitMask` | `andNot(BitMask other)` Get the result of a logical and of this bit mask and the inverse of another.
    `BitMask` | `clear(int pos)` Clear the flag at the given position.
    `BitMask` | `cleared()` Get a bit mask from this where all flags are cleared.
    `boolean` | `equals(java.lang.Object o)`
    `BitMask` | `flip(int pos)` Flip the flag at the given position.
    `int` | `getBitCount()` Get the number of possible bits used in this flag.
    `int` | `getCardinality()` Get the number of bits set in this flag.
    `int` | `getHighestBitSet()` Get the position of the highest bit set.
    `int` | `getLowestBitSet()` Get the position of the lowest bit set.
    `int` | `hashCode()`
    `boolean` | `isEmpty()` Is no flag set?
    `boolean` | `isSet(int pos)` Is the flag at the given position set?
    `int` | `low32()` Get the lower 32 bits of this mask.
    `long` | `low64()` Get the lower 64 bits of this mask.
    `BitMask` | `not()` Get the inverse of this bit mask.
    `BitMask` | `or(BitMask other)` Get the result of a logical or of this bit mask and another.
    `BitMask` | `set(int pos)` Set the flag at the given position.
    `java.util.BitSet` | `toBitSet()` Convert this bit mask into a bit set.
    `java.lang.String` | `toString()` Returns a string representation of the object.
    `BitMask` | `xor(BitMask other)` Get the result of a logical xor (exclusive or) of this bit mask and another.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### ZERO

          public static final BitSetBitMask ZERO

      Bit set bit mask with no bits set.

  - ### Constructor Detail

    - #### BitSetBitMask

          public BitSetBitMask(@NotNull
                               java.util.BitSet bitSet)

      Constructor.
      Parameters:
        `bitSet` - flags on which this mask is based

    - #### BitSetBitMask

          public BitSetBitMask(int flagCount)

      Constructor. This creates a bit mask with a capacity for the given number of flags.
      Parameters:
        `flagCount` - flag count

  - ### Method Detail

    - #### isSet

          public boolean isSet(int pos)

      Is the flag at the given position set?
      Specified by:
        `isSet` in interface `BitMask`
      Parameters:
        `pos` - position (non-negative)
      Returns:
        `true`: the flag is set
        `false`: the flag is not set

    - #### getBitCount

          public int getBitCount()

      Get the number of possible bits used in this flag.
      Specified by:
        `getBitCount` in interface `BitMask`
      Returns:
        bit count

    - #### getCardinality

          public int getCardinality()

      Get the number of bits set in this flag.
      Specified by:
        `getCardinality` in interface `BitMask`
      Returns:
        set bit count

    - #### isEmpty

          public boolean isEmpty()

      Is no flag set?
      Specified by:
        `isEmpty` in interface `BitMask`
      Returns:
        `true`: if no flag in this bit mask is set
        `false`: if any flag in this bit mask is set

    - #### set

          @NotNull
          public BitMask set(int pos)

      Set the flag at the given position.
      Specified by:
        `set` in interface `BitMask`
      Parameters:
        `pos` - position
      Returns:
        bit mask where the flag at the given position is set

    - #### clear

          @NotNull
          public BitMask clear(int pos)

      Clear the flag at the given position.
      Specified by:
        `clear` in interface `BitMask`
      Parameters:
        `pos` - position
      Returns:
        bit mask where the flag at the given position is cleared

    - #### flip

          @NotNull
          public BitMask flip(int pos)

      Flip the flag at the given position.
      Specified by:
        `flip` in interface `BitMask`
      Parameters:
        `pos` - position
      Returns:
        bit mask where the flag at the given position is flipped

    - #### not

          @NotNull
          public BitMask not()

      Get the inverse of this bit mask.
      Specified by:
        `not` in interface `BitMask`
      Returns:
        inverse bit mask

    - #### and

          @NotNull
          public BitMask and(@NotNull
                                      BitMask other)

      Get the result of a logical and of this bit mask and another.
      Specified by:
        `and` in interface `BitMask`
      Parameters:
        `other` - other bit mask
      Returns:
        resulting bit mask

    - #### andNot

          @NotNull
          public BitMask andNot(@NotNull
                                         BitMask other)

      Get the result of a logical and of this bit mask and the inverse of another.
      Specified by:
        `andNot` in interface `BitMask`
      Parameters:
        `other` - other bit mask
      Returns:
        resulting bit mask

    - #### or

          @NotNull
          public BitMask or(@NotNull
                                     BitMask other)

      Get the result of a logical or of this bit mask and another.
      Specified by:
        `or` in interface `BitMask`
      Parameters:
        `other` - other bit mask
      Returns:
        resulting bit mask

    - #### xor

          @NotNull
          public BitMask xor(@NotNull
                                      BitMask other)

      Get the result of a logical xor (exclusive or) of this bit mask and another.
      Specified by:
        `xor` in interface `BitMask`
      Parameters:
        `other` - other bit mask
      Returns:
        resulting bit mask

    - #### toBitSet

          @NotNull
          public java.util.BitSet toBitSet()

      Convert this bit mask into a bit set.
      Specified by:
        `toBitSet` in interface `BitMask`
      Returns:
        bit set

    - #### low32

          public int low32()

      Get the lower 32 bits of this mask.
      Specified by:
        `low32` in interface `BitMask`
      Returns:
        lower 32 bits as an int

    - #### low64

          public long low64()

      Get the lower 64 bits of this mask.
      Specified by:
        `low64` in interface `BitMask`
      Returns:
        lower 64 bits

    - #### getLowestBitSet

          public int getLowestBitSet()

      Description copied from interface: `BitMask`
      Get the position of the lowest bit set.
      Specified by:
        `getLowestBitSet` in interface `BitMask`
      Returns:
        position of the lowest bit set, or `-1` if no bit is set

    - #### getHighestBitSet

          public int getHighestBitSet()

      Description copied from interface: `BitMask`
      Get the position of the highest bit set.
      Specified by:
        `getHighestBitSet` in interface `BitMask`
      Returns:
        position of the highest bit set, or `-1` if no bit is set

    - #### cleared

          @NotNull
          public BitMask cleared()

      Description copied from interface: `BitMask`
      Get a bit mask from this where all flags are cleared.
      Specified by:
        `cleared` in interface `BitMask`
      Returns:
        a bit mask of this type where all flags are cleared

    - #### equals

          public boolean equals(java.lang.Object o)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### toString

          public java.lang.String toString()

      Returns a string representation of the object. In general, the `toString` method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

      The `toString` method for class `Object` returns a string consisting of the name of the class of which the object is an instance, the at-sign character ``@`', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

      >      getClass().getName() + '@' + Integer.toHexString(hashCode())

      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        a string representation of the object.