Class BooleanArraySet
- All Implemented Interfaces:
BooleanCollection,BooleanIterable,BooleanSet,Serializable,Cloneable,Iterable<Boolean>,Collection<Boolean>,Set<Boolean>
public class BooleanArraySet extends AbstractBooleanSet implements Serializable, 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.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor 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(int capacity)Creates a new empty array set of given initial capacity.BooleanArraySet(BooleanCollection c)Creates a new array set copying the contents of a given collection.BooleanArraySet(Collection<? extends Boolean> c)Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description booleanadd(boolean k)Ensures that this collection contains the specified element (optional operation).voidclear()BooleanArraySetclone()Returns a deep copy of this set.booleancontains(boolean k)Returnstrueif this collection contains the specified element.booleanisEmpty()BooleanIteratoriterator()Returns a type-specific iterator on the elements of this collection.booleanremove(boolean k)Removes an element from this set.intsize()Methods inherited from class it.unimi.dsi.fastutil.booleans.AbstractBooleanSet
equals, hashCode, remMethods inherited from class it.unimi.dsi.fastutil.booleans.AbstractBooleanCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toBooleanArray, toBooleanArray, toStringMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from interface it.unimi.dsi.fastutil.booleans.BooleanCollection
addAll, containsAll, removeAll, retainAll, toArray, toBooleanArray, toBooleanArrayMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
BooleanArraySet
public BooleanArraySet(boolean[] a)Creates a new array set using the given backing array. The resulting set will have as many elements as the array.It is responsibility of the caller that the elements of
aare distinct.- Parameters:
a- the backing array.
-
BooleanArraySet
public BooleanArraySet()Creates a new empty array set. -
BooleanArraySet
public BooleanArraySet(int capacity)Creates a new empty array set of given initial capacity.- Parameters:
capacity- the initial capacity.
-
BooleanArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
BooleanArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
BooleanArraySet
public BooleanArraySet(boolean[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.It is responsibility of the caller that the first
sizeelements ofaare distinct.- Parameters:
a- the backing array.size- the number of valid elements ina.
-
-
Method Details
-
iterator
Description copied from interface:BooleanCollectionReturns a type-specific iterator on the elements of this collection.Note that this specification strengthens the one given in
Iterable.iterator(), which was already strengthened in the corresponding type-specific class, but was weakened by the fact that this interface extendsCollection.- Specified by:
iteratorin interfaceBooleanCollection- Specified by:
iteratorin interfaceBooleanIterable- Specified by:
iteratorin interfaceBooleanSet- Specified by:
iteratorin interfaceCollection<Boolean>- Specified by:
iteratorin interfaceIterable<Boolean>- Specified by:
iteratorin interfaceSet<Boolean>- Specified by:
iteratorin classAbstractBooleanSet- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
public boolean contains(boolean k)Description copied from class:AbstractBooleanCollectionReturnstrueif this collection contains the specified element.This implementation iterates over the elements in the collection, looking for the specified element.
- Specified by:
containsin interfaceBooleanCollection- Overrides:
containsin classAbstractBooleanCollection- See Also:
Collection.contains(Object)
-
size
public int size()- Specified by:
sizein interfaceCollection<Boolean>- Specified by:
sizein interfaceSet<Boolean>- Specified by:
sizein classAbstractCollection<Boolean>
-
remove
public boolean remove(boolean k)Description copied from class:AbstractBooleanSetRemoves an element from this set.Note that the corresponding method of a type-specific collection is
rem(). This unfortunate situation is caused by the clash with the similarly named index-based method in theListinterface. Delegates to the type-specificrem()method implemented by type-specific abstractCollectionsuperclass.- Specified by:
removein interfaceBooleanSet- Overrides:
removein classAbstractBooleanSet- See Also:
Collection.remove(Object)
-
add
public boolean add(boolean k)Description copied from class:AbstractBooleanCollectionEnsures that this collection contains the specified element (optional operation).This implementation always throws an
UnsupportedOperationException.- Specified by:
addin interfaceBooleanCollection- Overrides:
addin classAbstractBooleanCollection- See Also:
Collection.add(Object)
-
clear
public void clear()- Specified by:
clearin interfaceCollection<Boolean>- Specified by:
clearin interfaceSet<Boolean>- Overrides:
clearin classAbstractCollection<Boolean>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Boolean>- Specified by:
isEmptyin interfaceSet<Boolean>- Overrides:
isEmptyin classAbstractCollection<Boolean>
-
clone
Returns a deep copy of this set.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.
- Returns:
- a deep copy of this set.
-