Class BitSets

java.lang.Object
eu.bandm.tools.util.java.BitSets

public abstract class BitSets extends Object
Library of constants and operations for working with bit sets.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static BitSet
    all(int limit)
    Returns a bit set containing all bits up to a given limit (exclusive).
    static BitSet
    and(BitSet... args)
    Returns a bit set containing only those bits which are common to all given sets.
    static BitSet
    andNot(BitSet arg1, BitSet arg2)
    Returns a new bit set containing the bits which is contained in the first given bit set, but not in the second.
    static void
    Applies a consumer to each bit contained in a given bit set.
    static BitSet
    or(BitSet... args)
    Returns a bit set containing those bits which are contained in any of the given sets.
    static BitSet
    singleton(int single)
    Returns a bit set containing exactly one bit.
    static int
    the(BitSet singleton)
    Finds the unique bit contained in a bit set.
    static BitSet
    xor(BitSet a1, BitSet a2)
    Returns a new bit set containing the bits which are contained in exactly one of the given bit sets.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • and

      public static BitSet and(BitSet... args)
      Returns a bit set containing only those bits which are common to all given sets.
      Parameters:
      args - some bit sets
      Returns:
      a new bit set containing any bit if and only if it is contained in all given bit sets
      Throws:
      IllegalArgumentException - if args is empty
      NullPointerException - if args or any element of it is null
      See Also:
    • andNot

      public static BitSet andNot(BitSet arg1, BitSet arg2)
      Returns a new bit set containing the bits which is contained in the first given bit set, but not in the second.
      Parameters:
      arg1 - a bit set
      arg2 - another bit set
      Returns:
      a new bit set containing any bit if and only if it is contained in arg1, but not in arg2
      Throws:
      NullPointerException - if arg1 or arg2 is null
      See Also:
    • or

      public static BitSet or(BitSet... args)
      Returns a bit set containing those bits which are contained in any of the given sets.

      The union of zero bit sets is empty.

      Parameters:
      args - some bit sets
      Returns:
      a new bit set containing any bit if and only if it is contained in at least one of the given bit sets
      Throws:
      NullPointerException - if args or any element of it is null
      See Also:
    • xor

      public static BitSet xor(BitSet a1, BitSet a2)
      Returns a new bit set containing the bits which are contained in exactly one of the given bit sets.
      Parameters:
      a1 - a bit set
      a2 - another bit set
      Returns:
      a new bit set containing any bit if and only if it is contained in either a1 or a2, but not both
      Throws:
      NullPointerException - if a1 or a2 is null
      See Also:
    • all

      public static BitSet all(int limit)
      Returns a bit set containing all bits up to a given limit (exclusive).
      Parameters:
      limit - the number of bits
      Returns:
      a bit set with all bits up to limit (exclusive)
      Throws:
      IllegalArgumentException - if limit is negative
      See Also:
    • singleton

      public static BitSet singleton(int single)
      Returns a bit set containing exactly one bit.
      Parameters:
      single - the bit
      Returns:
      a new bit set containing the given bit but no other
      Throws:
      IndexOutOfBoundsException - if single is negative
      See Also:
    • the

      public static int the(BitSet singleton)
      Finds the unique bit contained in a bit set.
      Parameters:
      singleton - a bit set containing exactly one bit
      Returns:
      the index of the contained bit
      Throws:
      IllegalArgumentException - if singleton contains none, or more than one bit
      See Also:
    • forEach

      public static void forEach(BitSet arg, IntConsumer fun)
      Applies a consumer to each bit contained in a given bit set.
      Parameters:
      arg - the bit set
      fun - the consumer
      Throws:
      NullPointerException - if arg or fun is null