Package owl.collections
Class ImmutableBitSet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Integer>
-
- owl.collections.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 aboolean
value. The bits of aImmutableBitSet
are indexed by nonnegative integers. This class further implements theSet
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 withnull
elements result inNullPointerException
. - 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.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
contains(int colour)
boolean
contains(Object o)
abstract boolean
containsAll(BitSet colours)
boolean
containsAll(Collection<?> c)
abstract BitSet
copyInto(BitSet target)
static ImmutableBitSet
copyOf(BitSet bitSet)
static ImmutableBitSet
copyOf(Collection<Integer> collection)
abstract OptionalInt
first()
void
forEach(Consumer<? super Integer> action)
abstract void
forEach(IntConsumer action)
abstract OptionalInt
higher(int e)
Returns the least element in this set strictly greater than the given element.ImmutableBitSet
intersection(BitSet that)
ImmutableBitSet
intersection(Collection<Integer> that)
ImmutableBitSet
intersection(ImmutableBitSet that)
boolean
intersects(Collection<Integer> otherSet)
abstract PrimitiveIterator.OfInt
intIterator()
abstract IntStream
intStream()
abstract boolean
isEmpty()
abstract OptionalInt
last()
abstract OptionalInt
lower(int e)
Returns the greatest element in this set strictly less than the given element.static ImmutableBitSet
of()
static ImmutableBitSet
of(int element)
static ImmutableBitSet
of(int... elements)
static ImmutableBitSet
range(int startInclusive, int endExclusive)
abstract Stream<Integer>
stream()
ImmutableBitSet
union(BitSet that)
ImmutableBitSet
union(Collection<Integer> that)
ImmutableBitSet
union(ImmutableBitSet that)
-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, iterator, remove, retainAll, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, toArray
-
Methods inherited from interface java.lang.Comparable
compareTo
-
-
-
-
Method Detail
-
of
public static ImmutableBitSet of()
-
of
public static ImmutableBitSet of(int element)
-
of
public static ImmutableBitSet of(int... elements)
-
range
public static ImmutableBitSet range(int startInclusive, int endExclusive)
-
copyOf
public static ImmutableBitSet copyOf(BitSet bitSet)
-
copyOf
public static ImmutableBitSet copyOf(Collection<Integer> collection)
-
first
public abstract OptionalInt first()
-
last
public abstract OptionalInt last()
-
higher
public abstract OptionalInt higher(int e)
Returns the least element in this set strictly greater than the given element.- Parameters:
e
- the value to match- Returns:
- the least element greater than
e
. - Throws:
NoSuchElementException
- if there is no such element.
-
lower
public abstract OptionalInt lower(int e)
Returns the greatest element in this set strictly less than the given element.- Parameters:
e
- the value to match- Returns:
- the greatest element less than
e
. - Throws:
NoSuchElementException
- if there is no such element.
-
isEmpty
public abstract boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<Integer>
- Specified by:
isEmpty
in interfaceSet<Integer>
- Overrides:
isEmpty
in classAbstractCollection<Integer>
-
contains
public abstract boolean contains(int colour)
-
contains
public final boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<Integer>
- Specified by:
contains
in interfaceSet<Integer>
- Overrides:
contains
in classAbstractCollection<Integer>
-
containsAll
public abstract boolean containsAll(BitSet colours)
-
containsAll
public final boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<Integer>
- Specified by:
containsAll
in interfaceSet<Integer>
- Overrides:
containsAll
in classAbstractCollection<Integer>
-
stream
public abstract Stream<Integer> stream()
- Specified by:
stream
in interfaceCollection<Integer>
-
intStream
public abstract IntStream intStream()
-
intIterator
public abstract PrimitiveIterator.OfInt intIterator()
-
forEach
public abstract void forEach(IntConsumer action)
-
union
public final ImmutableBitSet union(Collection<Integer> that)
-
union
public final ImmutableBitSet union(BitSet that)
-
union
public final ImmutableBitSet union(ImmutableBitSet that)
-
intersection
public final ImmutableBitSet intersection(Collection<Integer> that)
-
intersection
public final ImmutableBitSet intersection(BitSet that)
-
intersection
public final ImmutableBitSet intersection(ImmutableBitSet that)
-
intersects
public boolean intersects(Collection<Integer> otherSet)
-
-