public final class GeneralDomainBitSet<T> extends Object implements DomainBitSet<T>, Collection<T>
DomainBitSet
, that can be used with any type.Modifier and Type | Method and Description |
---|---|
boolean |
add(T e) |
boolean |
addAll(Collection<? extends T> c) |
static <X> GeneralDomainBitSet<X> |
allOf(LinkedHashSet<X> domain)
Creates a set with the given domain, that contains all elements.
|
static <X> GeneralDomainBitSet<X> |
allOf(List<X> domain)
Creates a set with the given domain, that contains all elements.
|
static <X> GeneralDomainBitSet<X> |
allOf(X... domain)
Creates a set with the given domain, that contains all elements.
|
void |
clear() |
GeneralDomainBitSet<T> |
clone()
Default implementation of a
cloning-method using
DomainBitSet.union(BigInteger) . |
GeneralDomainBitSet<T> |
complement()
Creates a new set with the same domain, initially containing all the elements of the domain
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.
|
boolean |
domainContains(T object)
Searches an object in the domain of this set.
|
boolean |
equals(Object o)
Compares the specified object with this domain bit set for equality.
|
void |
forEach(Consumer<? super T> action) |
boolean |
getBit(int bitIndex)
Returns the value of the bit with the specified index.
|
Domain<T> |
getDomain()
Returns a distinct list, containing all elements of the domain.
|
int |
hashCode()
Hash code of domain and elements.
|
GeneralDomainBitSet<T> |
intersect(BigInteger mask)
The intersection of this and a given mask.
|
GeneralDomainBitSet<T> |
intersect(BitSet other)
The intersection of this and a given bit set.
|
GeneralDomainBitSet<T> |
intersect(Iterable<T> other)
Intersection of this and the given set.
|
GeneralDomainBitSet<T> |
intersect(long mask)
Intersection of this and the given set.
|
GeneralDomainBitSet<T> |
intersectVarArgs(T... other)
The intersection of this set and a set represented by an array (varargs).
|
boolean |
isEmpty()
Returns true if this set contains no elements.
|
Iterator<T> |
iterator()
Returns an iterator over elements of type T.
|
GeneralDomainBitSet<T> |
minus(BigInteger mask)
The relative complement of this set and a set represented by a
BigInteger . |
GeneralDomainBitSet<T> |
minus(BitSet other)
The relative complement of this set and a set represented by a
BitSet . |
GeneralDomainBitSet<T> |
minus(Iterable<T> other)
The relative complement of this set and another set.
|
GeneralDomainBitSet<T> |
minus(long mask)
The relative complement of this set and a set represented by a bit mask.
|
GeneralDomainBitSet<T> |
minusVarArgs(T... other)
The relative complement of this set and a set represented by an array (varargs).
|
static <X> GeneralDomainBitSet<X> |
noneOf(LinkedHashSet<X> domain)
Creates an empty set with the given domain.
|
static <X> GeneralDomainBitSet<X> |
noneOf(List<X> domain)
Creates an empty set with the given domain.
|
static <X> GeneralDomainBitSet<X> |
noneOf(X... domain)
Creates an empty set with the given domain.
|
static <T> GeneralDomainBitSet<T> |
of(LinkedHashSet<T> domain,
Collection<T> initialSet)
Creates an empty set with the given domain, containing the given elements.
|
static <T> GeneralDomainBitSet<T> |
of(List<T> domain,
Collection<T> initialSet)
Creates a set with the given domain, containing the given elements.
|
boolean |
ofEqualElements(DomainBitSet<T> other)
Compares the elements, ignoring the domains.
|
Stream<T> |
parallelStream()
Returns a possibly parallel
Stream with this set as its source. |
Iterable<GeneralDomainBitSet<T>> |
powerset()
The powerset, which is the set of all subsets.
|
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
removeIf(Predicate<? super T> filter) |
boolean |
retainAll(Collection<?> c) |
int |
size()
The number of elements in this set.
|
Spliterator<T> |
spliterator()
Creates a
Spliterator over the elements in this collection. |
Stream<T> |
stream()
Returns a sequential
Stream with this collection as its source. |
Object[] |
toArray() |
<X> X[] |
toArray(X[] a) |
BigInteger |
toBigInteger()
A representation of the elements in this set as a
BigInteger . |
BitSet |
toBitSet()
A representation of the elements in this set as a
BitSet . |
LinkedHashSet<T> |
toLinkedHashSet()
Returns a new LinkedHashSet with the same elements, ordered as they appear in the domain.
|
long |
toLong()
A representation of the elements in this set as a
long . |
Set<T> |
toSet()
A regular set, with no defined domain.
|
String |
toString() |
GeneralDomainBitSet<T> |
union(BigInteger mask)
The union of this set and a set represented by a
BitSet . |
GeneralDomainBitSet<T> |
union(BitSet other)
The union of this set and a set represented by a
BitSet . |
GeneralDomainBitSet<T> |
union(Iterable<T> other)
The union of this set and a set represented by an
iterable collection. |
GeneralDomainBitSet<T> |
union(long mask)
The union of this set and a set represented by a bit mask.
|
GeneralDomainBitSet<T> |
unionVarArgs(T... other)
The union of this set and a set represented by an array (varargs).
|
allOf, allOf, createMultiEnumBitSet, cross, cross, getElement, map, map, noneOf, noneOf, ofEqualDomain, powerset, semijoin, zipWithPosition
public static <X> GeneralDomainBitSet<X> allOf(LinkedHashSet<X> domain)
X
- The type of the set and its domain.domain
- The domain.public static <X> GeneralDomainBitSet<X> allOf(List<X> domain)
X
- The type of the set and its domain.domain
- The domain.@SafeVarargs public static <X> GeneralDomainBitSet<X> allOf(X... domain)
X
- The type of the set and its domain.domain
- The domain.public static <X> GeneralDomainBitSet<X> noneOf(LinkedHashSet<X> domain)
X
- The type of the set and its domain.domain
- The domain.public static <X> GeneralDomainBitSet<X> noneOf(List<X> domain)
X
- The type of the set and its domain.domain
- The domain.@SafeVarargs public static <X> GeneralDomainBitSet<X> noneOf(X... domain)
X
- The type of the set and its domain.domain
- The domain.public static <T> GeneralDomainBitSet<T> of(LinkedHashSet<T> domain, Collection<T> initialSet)
T
- The type of the set and its domain.domain
- The domain.initialSet
- The elements to be contained.public static <T> GeneralDomainBitSet<T> of(List<T> domain, Collection<T> initialSet)
T
- The type of the set and its domain.domain
- The domain.initialSet
- The elements to be contained.public boolean add(T e)
add
in interface Collection<T>
public boolean addAll(Collection<? extends T> c)
addAll
in interface Collection<T>
IllegalArgumentException
- If any of the elements in c is not element of the given domain. In that case
the set is not altered at all.public void clear()
clear
in interface Collection<T>
public GeneralDomainBitSet<T> clone()
DomainBitSet
cloning-method
using
DomainBitSet.union(BigInteger)
.clone
in interface DomainBitSet<T>
clone
in class Object
this.union(BigInteger.ZERO)
public GeneralDomainBitSet<T> complement()
DomainBitSet
complement
in interface DomainBitSet<T>
public boolean contains(Object o)
DomainBitSet
contains
in interface DomainBitSet<T>
contains
in interface Collection<T>
o
- element whose presence in this collection is to be testedCollection.contains(Object)
public boolean containsAll(Collection<?> c)
DomainBitSet
containsAll
in interface DomainBitSet<T>
containsAll
in interface Collection<T>
c
- collection to be checked for containment in this collectionCollection.containsAll(Collection)
,
DomainBitSet.contains(Object)
public boolean domainContains(T object)
DomainBitSet
domainContains
in interface DomainBitSet<T>
object
- The object to be searched.public boolean equals(Object o)
DomainBitSet
DomainBitSet
, the two sets have the same domain, and every
member of the given set is contained in this set.
Comparison of elements only:
this.ofEqualElements(other)
Which is equivalent to:
this.toSet().equals(other.toSet())
Comparison of domain only:
this.ofEqualDomain(other)
equals
in interface DomainBitSet<T>
equals
in interface Collection<T>
equals
in class Object
DomainBitSet
, with the same domain and elements.DomainBitSet.ofEqualElements(DomainBitSet)
public boolean getBit(int bitIndex) throws IndexOutOfBoundsException
DomainBitSet
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<T>
bitIndex
- the bit indexIndexOutOfBoundsException
- if the specified index is negative or out of bounds.DomainBitSet.contains(Object)
,
BitSet.get(int)
,
BigInteger.testBit(int)
public Domain<T> getDomain()
DomainBitSet
All elements are ordered as they are defined in the domain.
Note that the returned set is immutable.
getDomain
in interface DomainBitSet<T>
Domain
of this set.public int hashCode()
DomainBitSet
hashCode
in interface DomainBitSet<T>
hashCode
in interface Collection<T>
hashCode
in class Object
public GeneralDomainBitSet<T> intersect(BigInteger mask)
DomainBitSet
intersect
in interface DomainBitSet<T>
mask
- The mask of the other set.public GeneralDomainBitSet<T> intersect(BitSet other)
DomainBitSet
intersect
in interface DomainBitSet<T>
other
- The bit set representation of the other set.public GeneralDomainBitSet<T> intersect(Iterable<T> other)
DomainBitSet
intersect
in interface DomainBitSet<T>
other
- An Iterable
collection of elements from the domain.public GeneralDomainBitSet<T> intersect(long mask) throws MoreThan64ElementsException
DomainBitSet
intersect
in interface DomainBitSet<T>
mask
- The bit mask of another set.MoreThan64ElementsException
- If the domain contains more than 64 elements, then long can't be used.public GeneralDomainBitSet<T> intersectVarArgs(T... other)
DomainBitSet
intersectVarArgs
in interface DomainBitSet<T>
other
- A set as an array. Duplicates are ignored. Must not be nor contain null
.DomainBitSet.intersect(Iterable)
public boolean isEmpty()
DomainBitSet
isEmpty
in interface DomainBitSet<T>
isEmpty
in interface Collection<T>
Collection.isEmpty()
public Iterator<T> iterator()
DomainBitSet
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<T>
iterator
in interface Iterable<T>
iterator
in interface Collection<T>
public GeneralDomainBitSet<T> minus(BigInteger mask)
DomainBitSet
BigInteger
.minus
in interface DomainBitSet<T>
mask
- The other set as a bit mask.public GeneralDomainBitSet<T> minus(BitSet other)
DomainBitSet
BitSet
.minus
in interface DomainBitSet<T>
other
- The other set.public GeneralDomainBitSet<T> minus(Iterable<T> other)
DomainBitSet
minus
in interface DomainBitSet<T>
other
- The other set.public GeneralDomainBitSet<T> minus(long mask) throws MoreThan64ElementsException
DomainBitSet
minus
in interface DomainBitSet<T>
mask
- The mask representing the other set.MoreThan64ElementsException
- If the domain contains more than 64 elements, then long can't be used.public GeneralDomainBitSet<T> minusVarArgs(T... other)
DomainBitSet
minusVarArgs
in interface DomainBitSet<T>
other
- A set as an array. Duplicates are ignored. Must not be nor contain null
.DomainBitSet.minus(Iterable)
public boolean ofEqualElements(DomainBitSet<T> other)
DomainBitSet
This is equal to, but could be a bit faster than this.toSet().equals(set.toSet())
.
ofEqualElements
in interface DomainBitSet<T>
other
- The other set.true
if both contain the same elements.Set.equals(Object)
public Stream<T> parallelStream()
DomainBitSet
Stream
with this set as its source. It is allowable for
this method to return a sequential stream.parallelStream
in interface DomainBitSet<T>
parallelStream
in interface Collection<T>
Stream
over the elements in this setCollection.parallelStream()
public Iterable<GeneralDomainBitSet<T>> 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<T>
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<T>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<T>
public boolean removeIf(Predicate<? super T> filter)
removeIf
in interface Collection<T>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<T>
public int size()
DomainBitSet
size
in interface DomainBitSet<T>
size
in interface Collection<T>
Collection.size()
public Spliterator<T> spliterator()
DomainBitSet
Spliterator
over the elements in this collection.spliterator
in interface DomainBitSet<T>
spliterator
in interface Iterable<T>
spliterator
in interface Collection<T>
Spliterator
over the elements in this collectionCollection.spliterator()
public Stream<T> stream()
DomainBitSet
Stream
with this collection as its source.stream
in interface DomainBitSet<T>
stream
in interface Collection<T>
Stream
over the elements in this collectionCollection.stream()
public Object[] toArray()
toArray
in interface Collection<T>
public <X> X[] toArray(X[] a)
toArray
in interface Collection<T>
public BigInteger toBigInteger()
DomainBitSet
BigInteger
.toBigInteger
in interface DomainBitSet<T>
BigInteger
.public BitSet toBitSet()
DomainBitSet
BitSet
.toBitSet
in interface DomainBitSet<T>
BitSet
.public LinkedHashSet<T> toLinkedHashSet()
LinkedHashSet
containing all elements of this set.public long toLong() throws MoreThan64ElementsException
DomainBitSet
long
.toLong
in interface DomainBitSet<T>
long
.MoreThan64ElementsException
- If the domain contains more than 64 elements.public Set<T> toSet()
DomainBitSet
false
for other sets without a domain.toSet
in interface DomainBitSet<T>
public GeneralDomainBitSet<T> union(BigInteger mask)
DomainBitSet
BitSet
.
Note: A fast version for BigInteger.ZERO should exist for each implementation!
union
in interface DomainBitSet<T>
mask
- A BitSet representing another set.public GeneralDomainBitSet<T> union(BitSet other)
DomainBitSet
BitSet
.union
in interface DomainBitSet<T>
other
- A BitSet representing another set.public GeneralDomainBitSet<T> union(Iterable<T> other)
DomainBitSet
iterable
collection.union
in interface DomainBitSet<T>
other
- An Iterable representing another set.public GeneralDomainBitSet<T> union(long mask) throws MoreThan64ElementsException
DomainBitSet
union
in interface DomainBitSet<T>
mask
- A bit mask representing another set.MoreThan64ElementsException
- If the domain contains more than 64 elements, then long can't be used.public GeneralDomainBitSet<T> unionVarArgs(T... other)
DomainBitSet
unionVarArgs
in interface DomainBitSet<T>
other
- A set as an array. Duplicates are ignored. Must not be nor contain null
.DomainBitSet.union(Iterable)