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 abooleanvalue. The bits of aImmutableBitSetare indexed by nonnegative integers. This class further implements theSetand 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
ImmutableBitSetinstances have the following characteristics:- They are unmodifiable. Elements cannot
be added or removed. Calling any mutator method on the Set
will always cause
UnsupportedOperationExceptionto be thrown. - They disallow
nullelements. Attempts to create them withnullelements 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 booleancontains(int colour)booleancontains(Object o)abstract booleancontainsAll(BitSet colours)booleancontainsAll(Collection<?> c)abstract BitSetcopyInto(BitSet target)static ImmutableBitSetcopyOf(BitSet bitSet)static ImmutableBitSetcopyOf(Collection<Integer> collection)abstract OptionalIntfirst()voidforEach(Consumer<? super Integer> action)abstract voidforEach(IntConsumer action)abstract OptionalInthigher(int e)Returns the least element in this set strictly greater than the given element.ImmutableBitSetintersection(BitSet that)ImmutableBitSetintersection(Collection<Integer> that)ImmutableBitSetintersection(ImmutableBitSet that)booleanintersects(Collection<Integer> otherSet)abstract PrimitiveIterator.OfIntintIterator()abstract IntStreamintStream()abstract booleanisEmpty()abstract OptionalIntlast()abstract OptionalIntlower(int e)Returns the greatest element in this set strictly less than the given element.static ImmutableBitSetof()static ImmutableBitSetof(int element)static ImmutableBitSetof(int... elements)static ImmutableBitSetrange(int startInclusive, int endExclusive)abstract Stream<Integer>stream()ImmutableBitSetunion(BitSet that)ImmutableBitSetunion(Collection<Integer> that)ImmutableBitSetunion(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:
isEmptyin interfaceCollection<Integer>- Specified by:
isEmptyin interfaceSet<Integer>- Overrides:
isEmptyin classAbstractCollection<Integer>
-
contains
public abstract boolean contains(int colour)
-
contains
public final boolean contains(Object o)
- Specified by:
containsin interfaceCollection<Integer>- Specified by:
containsin interfaceSet<Integer>- Overrides:
containsin classAbstractCollection<Integer>
-
containsAll
public abstract boolean containsAll(BitSet colours)
-
containsAll
public final boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<Integer>- Specified by:
containsAllin interfaceSet<Integer>- Overrides:
containsAllin classAbstractCollection<Integer>
-
stream
public abstract Stream<Integer> stream()
- Specified by:
streamin 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)
-
-