public class BooleanArraySet extends AbstractBooleanSet implements java.io.Serializable, java.lang.Cloneable
The main purpose of this implementation is that of wrapping cleanly the brute-force approach to the storage of a very small number of items: just put them into an array and scan linearly to find an item.
Constructor and Description |
---|
BooleanArraySet()
Creates a new empty array set.
|
BooleanArraySet(boolean[] a)
Creates a new array set using the given backing array.
|
BooleanArraySet(boolean[] a,
int size)
Creates a new array set using the given backing array and the given number of elements of the array.
|
BooleanArraySet(BooleanCollection c)
Creates a new array set copying the contents of a given collection.
|
BooleanArraySet(BooleanSet c)
Creates a new array set copying the contents of a given collection.
|
BooleanArraySet(java.util.Collection<? extends java.lang.Boolean> c)
Creates a new array set copying the contents of a given set.
|
BooleanArraySet(int capacity)
Creates a new empty array set of given initial capacity.
|
BooleanArraySet(java.util.Set<? extends java.lang.Boolean> c)
Creates a new array set copying the contents of a given set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(boolean k)
Ensures that this collection contains the specified element (optional operation).
|
void |
clear() |
BooleanArraySet |
clone()
Returns a deep copy of this set.
|
boolean |
contains(boolean k)
Returns
true if this collection contains the specified element. |
boolean |
isEmpty() |
BooleanIterator |
iterator()
Returns a type-specific iterator on the elements of this collection.
|
static BooleanArraySet |
of()
Creates a new empty array set.
|
static BooleanArraySet |
of(boolean... a)
Creates a new array set using an array of elements.
|
static BooleanArraySet |
of(boolean e)
Creates a new array set using the element given.
|
static BooleanArraySet |
ofUnchecked()
Creates a new empty array set.
|
static BooleanArraySet |
ofUnchecked(boolean... a)
Creates a new array set using an array of elements.
|
boolean |
remove(boolean k)
Removes an element from this set.
|
int |
size() |
BooleanSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this set.
|
boolean[] |
toArray(boolean[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
|
boolean[] |
toBooleanArray()
Returns a primitive type array containing the items of this collection.
|
equals, hashCode, rem
add, addAll, addAll, contains, containsAll, containsAll, remove, removeAll, removeAll, retainAll, retainAll, toBooleanArray, toString
add, contains, of, of, remove
addAll, containsAll, removeAll, removeIf, removeIf, retainAll, toBooleanArray
forEach, forEach
public BooleanArraySet(boolean[] a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array.public BooleanArraySet()
public BooleanArraySet(int capacity)
capacity
- the initial capacity.public BooleanArraySet(BooleanCollection c)
c
- a collection.public BooleanArraySet(java.util.Collection<? extends java.lang.Boolean> c)
c
- a collection.public BooleanArraySet(BooleanSet c)
c
- a collection.public BooleanArraySet(java.util.Set<? extends java.lang.Boolean> c)
c
- a collection.public BooleanArraySet(boolean[] a, int size)
It is the responsibility of the caller to ensure that the first size
elements of a
are distinct.
a
- the backing array.size
- the number of valid elements in a
.public static BooleanArraySet of()
of
in interface BooleanSet
public static BooleanArraySet of(boolean e)
of
in interface BooleanSet
e
- the element that the returned set will contain.e
.public static BooleanArraySet of(boolean... a)
Unlike the array accepting constructors, this method will throw if duplicate elements
are encountered. This adds a non-trivial validation burden. Use ofUnchecked()
if you
know your input has no duplicates, which will skip this validation.
of
in interface BooleanSet
a
- the backing array of the returned array set.a
.java.lang.IllegalArgumentException
- if there were duplicate entries.public static BooleanArraySet ofUnchecked()
public static BooleanArraySet ofUnchecked(boolean... a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array of the returned array set.a
.public BooleanIterator iterator()
BooleanCollection
iterator
in interface BooleanCollection
iterator
in interface BooleanIterable
iterator
in interface BooleanSet
iterator
in interface java.lang.Iterable<java.lang.Boolean>
iterator
in interface java.util.Collection<java.lang.Boolean>
iterator
in interface java.util.Set<java.lang.Boolean>
iterator
in class AbstractBooleanSet
Iterable.iterator()
public BooleanSpliterator spliterator()
Set spliterators must report at least Spliterator.DISTINCT
.
See Set.spliterator()
for more documentation on the requirements
of the returned spliterator.
In addition to the usual trait of DISTINCT
for
sets, the returned spliterator will also report
the trait ORDERED
.
The returned spliterator is late-binding; it will track structural changes
after the current item, up until the first trySplit()
,
at which point the maximum index will be fixed.
Structural changes before the current item or after the first
trySplit()
will result in unspecified behavior.
spliterator
in interface BooleanCollection
spliterator
in interface BooleanIterable
spliterator
in interface BooleanSet
spliterator
in interface java.lang.Iterable<java.lang.Boolean>
spliterator
in interface java.util.Collection<java.lang.Boolean>
spliterator
in interface java.util.Set<java.lang.Boolean>
public boolean contains(boolean k)
AbstractBooleanCollection
true
if this collection contains the specified element.contains
in interface BooleanCollection
contains
in class AbstractBooleanCollection
Collection.contains(Object)
public int size()
size
in interface java.util.Collection<java.lang.Boolean>
size
in interface java.util.Set<java.lang.Boolean>
size
in class java.util.AbstractCollection<java.lang.Boolean>
public boolean remove(boolean k)
AbstractBooleanSet
rem()
method
implemented by type-specific abstract Collection
superclass.remove
in interface BooleanSet
remove
in class AbstractBooleanSet
Collection.remove(Object)
public boolean add(boolean k)
AbstractBooleanCollection
add
in interface BooleanCollection
add
in class AbstractBooleanCollection
Collection.add(Object)
public void clear()
clear
in interface java.util.Collection<java.lang.Boolean>
clear
in interface java.util.Set<java.lang.Boolean>
clear
in class java.util.AbstractCollection<java.lang.Boolean>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Boolean>
isEmpty
in interface java.util.Set<java.lang.Boolean>
isEmpty
in class java.util.AbstractCollection<java.lang.Boolean>
public boolean[] toBooleanArray()
BooleanCollection
toBooleanArray
in interface BooleanCollection
toBooleanArray
in class AbstractBooleanCollection
Collection.toArray()
public boolean[] toArray(boolean[] a)
BooleanCollection
Note that, contrarily to Collection.toArray(Object[])
, this
methods just writes all elements of this collection: no special
value will be added after the last one.
toArray
in interface BooleanCollection
toArray
in class AbstractBooleanCollection
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public BooleanArraySet clone()
This method performs a deep copy of this array set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.
clone
in class java.lang.Object