Class ImmutableBitSet

  • All Implemented Interfaces:
    Comparable<ImmutableBitSet>, Iterable<Integer>, Collection<Integer>, Set<Integer>

    public abstract class ImmutableBitSet
    extends AbstractSet<Integer>
    implements Comparable<ImmutableBitSet>
    This class implements an immutable vector of bits. Each component of the bit set has a boolean value. The bits of a ImmutableBitSet are indexed by nonnegative integers. This class further implements the Set and provide methods to access integer values without boxing.

    This is a simple implementation backed by either singleton values or a BitSet. Thus using large indices increases the allocated memory, since the backing BitSet does not have sparse representation. The ImmutableBitSet instances have the following characteristics:

    • They are unmodifiable. Elements cannot be added or removed. Calling any mutator method on the Set will always cause UnsupportedOperationException to be thrown.
    • They disallow null elements. Attempts to create them with null elements result in NullPointerException.
    • They reject duplicate elements at creation time. Duplicate elements passed to a static factory method result in IllegalArgumentException.
    • They are value-based. Callers should make no assumptions about the identity of the returned instances. Factories are free to create new instances or reuse existing ones. Therefore, identity-sensitive operations on these instances (reference equality (==), identity hash code, and synchronization) are unreliable and should be avoided.