E
- Enum type that implements EnumBitSetHelper
<E>
.public final class EnumBitSet<E extends Enum<E> & EnumBitSetHelper<E>> extends Object implements DomainBitSet<E>, Collection<E>
All information is hidden. But this class offers many more methods compared to EnumSet
.
Those extra methods are inspired by set theory so that set operations are much simpler to perform
with the given methods. These methods are defined in the interface DomainBitSet
.
Methods such as union(EnumBitSet)
, toEnumSet()
, and complement()
return a new and independent set. This allows a functional style of programming.
However, this set is mutable. It can be altered using the interface of Collection
(
add(Enum)
, remove(Object)
etc.). This allows the classic imperative style of
programming.
Sadly both BitSet and EnumSet are not implementations of some interface. Therefore this class can not share the interface of these other classes. Most methods are implemented here so this is in fact compatible in most cases.
This set is a DomainBitSet
with a domain made of all enum elements of a given enum type.
This set is not thread-safe. You can use Collections.unmodifiableSet(Set)
, but will lose
all methods not declared in Set
.
See the package-info for naming conventions.
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
boolean |
addAll(Collection<? extends E> c) |
static <X extends Enum<X> & EnumBitSetHelper<X>> |
allOf(Class<X> type)
Creates an EnumBitSet containing all of the elements in the specified element type.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asBigInteger(EnumSet<X> set)
Convert EnumSet to BitInteger.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asBigInteger(X... set)
Convert VarArg/Array of enums to BitInteger.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asBitSet(EnumSet<X> set)
Creates a BitSet of a given set of enums.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asBitSet(X... set)
Creates a BitSet of a given set of enums.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumBitSet(BigInteger mask,
Class<X> type)
Creates set of enums from a bit set.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumBitSet(BitSet set,
Class<X> type)
Creates set of enums from a bit set.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumBitSet(Collection<X> collection,
Class<X> type)
Creates a new EnumBitSet from a given Collection.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumBitSet(EnumSet<X> set,
Class<X> type)
Creates a new EnumBitSet from a given BitSet.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumBitSet(long mask,
Class<X> type)
Creates set of enums from a long.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumSet(BigInteger mask,
Class<X> type)
Creates set of enums from a bit set.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumSet(BitSet bitset,
Class<X> type)
Creates set of enums from a BitSet.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumSet(long mask,
Class<X> type)
Creates set of enums from a 64 bit bit set.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asEnumSet(X first,
X... rest)
Creates set of enums from at least one element.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asLong(EnumSet<X> set)
Creates a 64 bit bitmask of a given set of enums.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
asLong(X... set)
Creates a 64 bit bit set of a given set of enums.
|
void |
clear() |
EnumBitSet<E> |
clone()
Returns a copy of this set.
|
EnumBitSet<E> |
complement()
Creates a new EnumBitSet with the same element type as this, initially containing all the
elements of this type that are not contained in this set.
|
boolean |
contains(Object o)
Returns true if this set contains the specified element.
|
boolean |
containsAll(Collection<?> c)
Returns true if this set contains all of the elements in the specified collection.
|
<Y extends Enum<Y> & EnumBitSetHelper<Y>> |
cross(EnumBitSet<Y> set)
The Cartesian product with another EnumBitSet.
|
boolean |
domainContains(E object)
Is the given enum constant an element of this set's domain?
|
boolean |
equals(Object other)
Compares the specified object with this domain bit set for equality.
|
void |
forEach(Consumer<? super E> action) |
boolean |
getBit(int bitIndex)
Returns the value of the bit with the specified index.
|
Domain<E> |
getDomain()
The Domain containing all elements of the enum type.
|
Class<E> |
getEnumType()
The enum type class that defines the available enum elements.
|
int |
getEnumTypeSize()
Amount of enum elements.
|
int |
hashCode()
Hash code of domain and elements.
|
EnumBitSet<E> |
intersect(BigInteger mask)
Returns a new EnumBitSet containing all elements that are in
this and the given
mask . |
EnumBitSet<E> |
intersect(BitSet set)
Returns a new EnumBitSet containing all elements that are in
this and the given
set . |
EnumBitSet<E> |
intersect(EnumBitSet<E> set)
Returns a new EnumBitSet containing all elements that are in
this and the given
set . |
EnumBitSet<E> |
intersect(EnumSet<E> set)
Returns a new EnumBitSet containing all elements that are in
this and the given
set . |
EnumBitSet<E> |
intersect(Iterable<E> set)
Returns a new EnumBitSet containing all elements that are in
this and the given
set . |
EnumBitSet<E> |
intersect(long mask)
Returns a new EnumBitSet containing all elements that are in
this and the given
mask . |
EnumBitSet<E> |
intersectVarArgs(E... set)
Returns a new EnumBitSet containing all elements that are in
this and the given
set . |
boolean |
isEmpty()
Returns true if this set contains no elements.
|
Iterator<E> |
iterator()
Returns an iterator over elements of type T.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
just(X value)
Returns a new EnumBitSet containing just one enum value.
|
<S extends Enum<S> & EnumBitSetHelper<S>> |
map(Class<S> newEnumType)
Returns a new set with elements of a given enum type, containing all elements of the other enum
type.
|
<S extends Enum<S> & EnumBitSetHelper<S>> |
map(Class<S> newEnumType,
Function<E,S> mapper)
Returns a new set with elements of a given enum type, containing all mapped elements.
|
<S> DomainBitSet<S> |
map(Domain<S> newDomain,
Function<E,S> mapper)
Returns a new set with elements of a given domain, containing all mapped elements.
|
EnumBitSet<E> |
minus(BigInteger mask)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given mask . |
EnumBitSet<E> |
minus(BitSet set)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given bit set . |
EnumBitSet<E> |
minus(EnumBitSet<E> set)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given set . |
EnumBitSet<E> |
minus(EnumSet<E> set)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given set . |
EnumBitSet<E> |
minus(Iterable<E> set)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given set . |
EnumBitSet<E> |
minus(long mask)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given mask . |
EnumBitSet<E> |
minusVarArgs(E... set)
Returns a new EnumBitSet containing all elements that are in
this , but not in the
given set . |
static <X extends Enum<X> & EnumBitSetHelper<X>> |
noneOf(Class<X> type)
Creates an EnumBitSet containing none of the elements in the specified element type.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
of(X first,
X... more)
Creates a new EnumBitSet containing at least one value.
|
boolean |
ofEqualDomain(DomainBitSet<E> set)
Compares the domains.
|
Stream<E> |
parallelStream()
Returns a possibly parallel
Stream with this set as its source. |
Iterable<EnumBitSet<E>> |
powerset()
The powerset, which is the set of all subsets.
|
static <X extends Enum<X> & EnumBitSetHelper<X>> |
range(X from,
X to)
Creates an enum set initially containing all of the elements in the range defined by the two
specified endpoints.
|
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size()
The number of elements in this set.
|
Spliterator<E> |
spliterator()
Creates a
Spliterator over the elements in this collection. |
Stream<E> |
stream()
Returns a sequential
Stream with this collection as its source. |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
BigInteger |
toBigInteger()
Returns a BigInteger that represents this set.
|
String |
toBinaryString()
Binary string representation of this set.
|
String |
toBinaryString(int width)
Binary string representation of this set.
|
BitSet |
toBitSet()
Returns a new BitSet that represents this set.
|
EnumSet<E> |
toEnumSet()
Copy of the underlying EnumSet.
|
long |
toLong()
Returns a long value that represents this set.
|
Set<E> |
toSet()
Copy of the underlying EnumSet.
|
String |
toString()
Returns a string representation of this set.
|
EnumBitSet<E> |
union(BigInteger mask)
Returns a new EnumBitSet containing all elements that are in
this or the given
mask . |
EnumBitSet<E> |
union(BitSet set)
Returns a new EnumBitSet containing all elements that are in
this or the given
set . |
EnumBitSet<E> |
union(EnumBitSet<E> set)
Returns a new EnumBitSet containing all elements that are in
this or the given
set . |
EnumBitSet<E> |
union(EnumSet<E> set)
Returns a new EnumBitSet containing all elements that are in
this or the given
set . |
EnumBitSet<E> |
union(Iterable<E> set)
The union of this set and a set represented by an
iterable collection. |
EnumBitSet<E> |
union(long mask)
Returns a new EnumBitSet containing all elements that are in
this or the given
mask . |
EnumBitSet<E> |
unionVarArgs(E... set)
Returns a new EnumBitSet containing all elements that are in
this or the given
set . |
Stream<Pair<Object,Integer,E>> |
zipWithPosition()
Returns a sequential stream with pairs of all elements of this set and their position in the
domain.
|
allOf, allOf, createMultiEnumBitSet, cross, cross, getElement, map, noneOf, noneOf, ofEqualElements, powerset, semijoin
removeIf
public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> allOf(Class<X> type)
X
- The enum type.type
- Enum type.of(Enum, Enum...)
,
noneOf(Class)
public static <X extends Enum<X> & EnumBitSetHelper<X>> BigInteger asBigInteger(EnumSet<X> set)
X
- Enum type of the elements.set
- A set of enum constants.@SafeVarargs public static <X extends Enum<X> & EnumBitSetHelper<X>> BigInteger asBigInteger(X... set)
X
- Enum type of the elements.set
- A set of enum constants.public static <X extends Enum<X> & EnumBitSetHelper<X>> BitSet asBitSet(EnumSet<X> set)
X
- Enum type of the elements.set
- A set of enum constants.@SafeVarargs public static <X extends Enum<X> & EnumBitSetHelper<X>> BitSet asBitSet(X... set)
X
- Enum type of the elements.set
- A set of enum constants.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> asEnumBitSet(BigInteger mask, Class<X> type)
X
- The class of the parameter elements and of the setmask
- A bit mask, must be positive.type
- The class of the parameter elements and of the set.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> asEnumBitSet(BitSet set, Class<X> type)
X
- The class of the parameter elements and of the setset
- A BitSet.type
- The class of the parameter elements and of the set.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> asEnumBitSet(Collection<X> collection, Class<X> type)
null
.X
- The class of the parameter elements and of the setcollection
- A Collection of enum elements, not null and not containing null.type
- The class of the parameter elements and of the set.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> asEnumBitSet(EnumSet<X> set, Class<X> type)
X
- The class of the parameter elements and of the setset
- An EnumSet.type
- The class of the parameter elements and of the set.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> asEnumBitSet(long mask, Class<X> type) throws MoreThan64ElementsException
X
- The class of the parameter elements and of the setmask
- A bit mask.type
- The class of the parameter elements and of the set.MoreThan64ElementsException
public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumSet<X> asEnumSet(BigInteger mask, Class<X> type)
X
- The class of the parameter elements and of the setmask
- A bit mask, must be positive.type
- The class of the parameter elements and of the setpublic static <X extends Enum<X> & EnumBitSetHelper<X>> EnumSet<X> asEnumSet(BitSet bitset, Class<X> type)
X
- The class of the parameter elements and of the setbitset
- A BitSet.type
- The class of the parameter elements and of the set.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumSet<X> asEnumSet(long mask, Class<X> type) throws MoreThan64ElementsException
X
- The enum type of the set.mask
- The bit mask.type
- The enum type of the set.MoreThan64ElementsException
- This fails if the enum type contains more than 64 elements.@SafeVarargs public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumSet<X> asEnumSet(X first, X... rest)
EnumSet.of(Enum, Enum...)
directly!X
- The class of the parameter elements and of the setfirst
- an element that the set is to contain initiallyrest
- the remaining elements the set is to contain initiallyEnumSet.of(first, rest)
.NullPointerException
- if any of the specified elements are null, or if rest is nullpublic static <X extends Enum<X> & EnumBitSetHelper<X>> long asLong(EnumSet<X> set) throws MoreThan64ElementsException
X
- Enum type of the elements.set
- An EnumSet af an enum type with up to 64 constants.MoreThan64ElementsException
- This fails if any element in the set has a higher index than 63.@SafeVarargs public static <X extends Enum<X> & EnumBitSetHelper<X>> long asLong(X... set) throws MoreThan64ElementsException
X
- Enum type of the elements.set
- An EnumSet af an enum type with up to 64 constants.MoreThan64ElementsException
- This fails if any element in the set has a higher index than 63.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> just(X value)
EnumBitSet.just(X)
is equal to X.asEnumBitSet()
X
- The enum type of the value.value
- The single value that will be contained in the result.value
.public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> noneOf(Class<X> type)
X
- The enum type.type
- Enum type.of(Enum, Enum...)
,
allOf(Class)
@SafeVarargs public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> of(X first, X... more)
X
- The enum type of all elements.first
- The first element (must not be null).more
- More elements to add.noneOf(Class)
public static <X extends Enum<X> & EnumBitSetHelper<X>> EnumBitSet<X> range(X from, X to)
X
- The class of the parameter elements and of the setfrom
- the first element in the rangeto
- the last element in the rangeNullPointerException
- if from
or to
are nullIllegalArgumentException
- if from.compareTo(to) > 0
public boolean add(E e)
add
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public void clear()
clear
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public EnumBitSet<E> clone()
clone
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
clone
in class Object
this.union(BigInteger.ZERO)
public EnumBitSet<E> complement()
complement
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
public boolean contains(Object o)
contains
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
contains
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
o
- element whose presence in this collection is to be testedCollection.contains(Object)
public boolean containsAll(Collection<?> c)
containsAll
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
containsAll
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
c
- collection to be checked for containment in this collectionCollection.containsAll(Collection)
,
DomainBitSet.contains(Object)
public <Y extends Enum<Y> & EnumBitSetHelper<Y>> Set<Pair<EnumBitSetHelper<?>,E,Y>> cross(EnumBitSet<Y> set)
Enum
and EnumBitSetHelper
instead of Object.Y
- The type of the elements in the given set.set
- Another set.Set
containing all pairs
.DomainBitSet.cross(DomainBitSet)
,
DomainBitSet.cross(DomainBitSet, BiConsumer)
,
BitSetUtilities.cross(DomainBitSet, DomainBitSet, Class)
public boolean domainContains(E object)
domainContains
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
object
- The object to be searched.object.getDeclaringClass() == this.enumType
public boolean equals(Object other)
DomainBitSet
, the two sets have the same domain, and every
member of the given set is contained in this set.equals
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
equals
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
equals
in class Object
DomainBitSet
, with the same domain and elements.DomainBitSet.equals(Object)
,
DomainBitSet.ofEqualElements(DomainBitSet)
public boolean getBit(int bitIndex) throws IndexOutOfBoundsException
true
if the bit
with the index bitIndex
is currently set in this BitSet
; otherwise, the result
is false
.
Note that not all DomainBitSets are implemented as a bit set. In that case this method emulates the behavior of an actual bit set.
getBit
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
bitIndex
- the bit indexIndexOutOfBoundsException
- if the specified index is negative or out of bounds.DomainBitSet.getElement(int)
public Domain<E> getDomain()
getDomain
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
Domain
with all enum elements.getEnumTypeSize()
public Class<E> getEnumType()
Enum.getDeclaringClass()
.public int getEnumTypeSize()
This is equal to
, but possibly faster.getDomain()
.size()
public int hashCode()
hashCode
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
hashCode
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
hashCode
in class Object
public EnumBitSet<E> intersect(BigInteger mask)
this
and the given
mask
.intersect
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
mask
- Another set, represented by a bit mask, must be positive. this ∩ set
complement()
public EnumBitSet<E> intersect(BitSet set)
this
and the given
set
.intersect
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set. this ∩ set
complement()
public EnumBitSet<E> intersect(EnumBitSet<E> set)
this
and the given
set
.set
- Another set. this ∩ set
complement()
public EnumBitSet<E> intersect(EnumSet<E> set)
this
and the given
set
.set
- Another set. this ∩ set
complement()
public EnumBitSet<E> intersect(Iterable<E> set)
this
and the given
set
.intersect
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set. this ∩ set
complement()
public EnumBitSet<E> intersect(long mask) throws MoreThan64ElementsException
this
and the given
mask
.intersect
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
mask
- Another set, represented by a bit mask. this ∩ set
MoreThan64ElementsException
- This fails if any element in the set has a higher index than 63.complement()
public EnumBitSet<E> intersectVarArgs(E... set)
this
and the given
set
.intersectVarArgs
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set. this ∩ set
complement()
public boolean isEmpty()
isEmpty
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
isEmpty
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
Collection.isEmpty()
public Iterator<E> iterator()
The order is not defined as this could be backed by a set. Iteration in the same order as the
domain can be done like this:
domainBitSet.getDomain().stream().filter(domainBitSet::contains).forEach(...)
iterator
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
iterator
in interface Iterable<E extends Enum<E> & EnumBitSetHelper<E>>
iterator
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public <S extends Enum<S> & EnumBitSetHelper<S>> EnumBitSet<S> map(Class<S> newEnumType)
Mapping is done by the ordinal of each enum constant. Therefore the given enum type must not contain less constants than the enum type of this set.
S
- Type of given enum domain.newEnumType
- The new enum type.IllegalArgumentException
- if the given enum type contains less constants.map(Domain, Function)
,
map(Class, Function)
,
Stream.map(Function)
public <S extends Enum<S> & EnumBitSetHelper<S>> EnumBitSet<S> map(Class<S> newEnumType, Function<E,S> mapper)
This is a convenience method. The same can be done with: this.stream().map(mapper)
S
- Type of given enum domain.newEnumType
- The new enum type.mapper
- function to map from E to S.map(Domain, Function)
,
map(Domain, Function)
,
Stream.map(Function)
public <S> DomainBitSet<S> map(Domain<S> newDomain, Function<E,S> mapper)
This is a convenience method. The same can be done with: this.stream().map(mapper)
This returns an EnumBitSet if the given Domain originates from an EnumBitSet.
map
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
S
- Type of given domain.newDomain
- The new domainmapper
- function to map from T to S.map(Class, Function)
public EnumBitSet<E> minus(BigInteger mask)
this
, but not in the
given mask
.minus
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
mask
- Another set, represented by a bit mask, must be positive.this ∖ mask
removeAll(Collection)
public EnumBitSet<E> minus(BitSet set)
this
, but not in the
given bit set
.minus
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set.this ∖ set
removeAll(Collection)
public EnumBitSet<E> minus(EnumBitSet<E> set)
this
, but not in the
given set
.set
- Another set.this ∖ set
removeAll(Collection)
public EnumBitSet<E> minus(EnumSet<E> set)
this
, but not in the
given set
.set
- Another set.this ∖ set
removeAll(Collection)
public EnumBitSet<E> minus(Iterable<E> set)
this
, but not in the
given set
.minus
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set.this ∖ mask
removeAll(Collection)
public EnumBitSet<E> minus(long mask) throws MoreThan64ElementsException
this
, but not in the
given mask
.minus
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
mask
- Another set, represented by a bit mask.this ∖ mask
MoreThan64ElementsException
- This fails if any element in this set has a higher index than 63.removeAll(Collection)
public EnumBitSet<E> minusVarArgs(E... set)
this
, but not in the
given set
.minusVarArgs
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set.this ∖ set
removeAll(Collection)
public boolean ofEqualDomain(DomainBitSet<E> set)
DomainBitSet
This is equal to, but could be a bit faster than
this.getDomain().equals(set.getDomain())
.
ofEqualDomain
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- The other set.true
if both are of equal domains.public Stream<E> parallelStream()
DomainBitSet
Stream
with this set as its source. It is allowable for
this method to return a sequential stream.parallelStream
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
parallelStream
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
Stream
over the elements in this setCollection.parallelStream()
public Iterable<EnumBitSet<E>> powerset() throws MoreThan64ElementsException
DomainBitSet
Note: Complexity is O(2n)
. For sets with more than 64 elements this
would be insanely large. Therefore this is limited to sets with up to 64 elements. However, the
size of the domain does not matter.
This is not thread safe and has to be processed sequentially.
powerset
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
MoreThan64ElementsException
- if this set contains more than 64 elements. This would result in more than 18E18
subsets.DomainBitSet.powerset(Consumer, boolean)
public boolean remove(Object o)
remove
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
minusVarArgs(Enum...)
,
minus(EnumBitSet)
,
minus(EnumSet)
,
minus(BigInteger)
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
intersect(BigInteger)
,
intersect(BitSet)
,
intersectVarArgs(Enum...)
,
intersect(EnumBitSet)
,
intersect(EnumSet)
,
intersect(long)
public int size()
Not to be confused with getEnumTypeSize()
.
size
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
size
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
Collection.size()
public Spliterator<E> spliterator()
Spliterator
over the elements in this collection.spliterator
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
spliterator
in interface Iterable<E extends Enum<E> & EnumBitSetHelper<E>>
spliterator
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
Spliterator
over the elements in this collectionCollection.spliterator()
public Stream<E> stream()
DomainBitSet
Stream
with this collection as its source.stream
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
stream
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
Stream
over the elements in this collectionCollection.stream()
public Object[] toArray()
toArray
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E extends Enum<E> & EnumBitSetHelper<E>>
public BigInteger toBigInteger()
toBigInteger
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
EnumBitSet
as a BigInteger
.toBinaryString()
public String toBinaryString()
The length of the returned string is the same as the amount of enum elements in the enum type.
EnumBitSet
as a String of 0s and 1s.public String toBinaryString(int width)
The length of the returned string is as least as long as width.
Example: Use this if you have an enum type with less than 64 elements but you want to use a bit
field with 64 bits. this.toBinaryString(64)
will already have the appropriate
length.
width
- The minimal width of the returned String.EnumBitSet
as a String of 0s and 1s. The length is at
least width.public BitSet toBitSet()
toBitSet
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
EnumBitSet
as a BitSet
;public long toLong() throws MoreThan64ElementsException
toLong
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
EnumBitSet
as a long
.MoreThan64ElementsException
- This fails if any element in this set has a higher index than 63.public Set<E> toSet()
toSet
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
bitset.clone()
public String toString()
toString
in class Object
AbstractCollection.toString()
public EnumBitSet<E> union(BigInteger mask)
this
or the given
mask
.union
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
mask
- Bit mask of another set, must be positive. this ∪ set
IllegalArgumentException
- The bit mask must not have any bits set that are not mapped to an enum constant.public EnumBitSet<E> union(BitSet set)
this
or the given
set
.union
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set. this ∪ set
IllegalArgumentException
- The bit set must not have any bits set that are not mapped to an enum constant.public EnumBitSet<E> union(EnumBitSet<E> set)
this
or the given
set
.set
- Another set. this ∪ set
public EnumBitSet<E> union(EnumSet<E> set)
this
or the given
set
.set
- Another set. this ∪ set
public EnumBitSet<E> union(Iterable<E> set)
DomainBitSet
iterable
collection.union
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- An Iterable representing another set.public EnumBitSet<E> union(long mask) throws MoreThan64ElementsException
this
or the given
mask
.union
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
mask
- Bit mask of another set. this ∪ set
MoreThan64ElementsException
- This fails if any element in this set has a higher index than 63.public EnumBitSet<E> unionVarArgs(E... set)
this
or the given
set
.unionVarArgs
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
set
- Another set. this ∪ set
DomainBitSet.union(Iterable)
public Stream<Pair<Object,Integer,E>> zipWithPosition()
This can be collected to a Map
using toTreeMap
.
As this uses enum types the position is always the ordinal
of the
constant.
zipWithPosition
in interface DomainBitSet<E extends Enum<E> & EnumBitSetHelper<E>>
BitSetUtilities.toTreeMap()
,
DomainBitSet.getElement(int)