Class ObjectArraySet<K>
- All Implemented Interfaces:
ObjectCollection<K>,ObjectIterable<K>,ObjectSet<K>,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<K>,java.util.Collection<K>,java.util.Set<K>
public class ObjectArraySet<K> extends AbstractObjectSet<K> 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.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ObjectArraySet()Creates a new empty array set.ObjectArraySet(int capacity)Creates a new empty array set of given initial capacity.ObjectArraySet(ObjectCollection<K> c)Creates a new array set copying the contents of a given collection.ObjectArraySet(ObjectSet<K> c)Creates a new array set copying the contents of a given collection.ObjectArraySet(java.lang.Object[] a)Creates a new array set using the given backing array.ObjectArraySet(java.lang.Object[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.ObjectArraySet(java.util.Collection<? extends K> c)Creates a new array set copying the contents of a given set.ObjectArraySet(java.util.Set<? extends K> c)Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description booleanadd(K k)voidclear()ObjectArraySet<K>clone()Returns a deep copy of this set.booleancontains(java.lang.Object k)booleanisEmpty()ObjectIterator<K>iterator()Returns a type-specific iterator on the elements of this collection.static <K> ObjectArraySet<K>of()Creates a new empty array set.static <K> ObjectArraySet<K>of(K e)Creates a new array set using the element given.static <K> ObjectArraySet<K>of(K... a)Creates a new array set using an array of elements.static <K> ObjectArraySet<K>ofUnchecked()Creates a new empty array set.static <K> ObjectArraySet<K>ofUnchecked(K... a)Creates a new array set using an array of elements.booleanremove(java.lang.Object k)intsize()ObjectSpliterator<K>spliterator()Returns a type-specific spliterator on the elements of this set.java.lang.Object[]toArray()<K> K[]toArray(K[] a)Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectSet
equals, hashCodeMethods inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectCollection
toStringMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAllMethods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.lang.Iterable
forEachMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll
-
Constructor Details
-
ObjectArraySet
public ObjectArraySet(java.lang.Object[] a)Creates a new array set using the given backing array. The resulting set will have as many elements as the array.It is the responsibility of the caller to ensure that the elements of
aare distinct.- Parameters:
a- the backing array.
-
ObjectArraySet
public ObjectArraySet()Creates a new empty array set. -
ObjectArraySet
public ObjectArraySet(int capacity)Creates a new empty array set of given initial capacity.- Parameters:
capacity- the initial capacity.
-
ObjectArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
ObjectArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
ObjectArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
ObjectArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
ObjectArraySet
public ObjectArraySet(java.lang.Object[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.It is the responsibility of the caller to ensure that the first
sizeelements ofaare distinct.- Parameters:
a- the backing array.size- the number of valid elements ina.
-
-
Method Details
-
of
Creates a new empty array set.- Returns:
- a new empty array set.
-
of
Creates a new array set using the element given.- Parameters:
e- the element that the returned set will contain.- Returns:
- a new array set containing
e.
-
of
Creates a new array set using an array of elements.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.- Parameters:
a- the backing array of the returned array set.- Returns:
- a new array set containing the elements in
a. - Throws:
java.lang.IllegalArgumentException- if there were duplicate entries.
-
ofUnchecked
Creates a new empty array set.- Returns:
- a new empty array set.
-
ofUnchecked
Creates a new array set using an array of elements.It is the responsibility of the caller to ensure that the elements of
aare distinct.- Parameters:
a- the backing array of the returned array set.- Returns:
- a new array set containing the elements in
a.
-
iterator
Description copied from interface:ObjectCollectionReturns a type-specific iterator on the elements of this collection.- Specified by:
iteratorin interfacejava.util.Collection<K>- Specified by:
iteratorin interfacejava.lang.Iterable<K>- Specified by:
iteratorin interfaceObjectCollection<K>- Specified by:
iteratorin interfaceObjectIterable<K>- Specified by:
iteratorin interfaceObjectSet<K>- Specified by:
iteratorin interfacejava.util.Set<K>- Specified by:
iteratorin classAbstractObjectSet<K>- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
spliterator
Returns a type-specific spliterator on the elements of this set.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
DISTINCTfor sets, the returned spliterator will also report the traitORDERED.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 firsttrySplit()will result in unspecified behavior.- Specified by:
spliteratorin interfacejava.util.Collection<K>- Specified by:
spliteratorin interfacejava.lang.Iterable<K>- Specified by:
spliteratorin interfaceObjectCollection<K>- Specified by:
spliteratorin interfaceObjectIterable<K>- Specified by:
spliteratorin interfaceObjectSet<K>- Specified by:
spliteratorin interfacejava.util.Set<K>- Returns:
- a type-specific spliterator on the elements of this collection.
-
contains
public boolean contains(java.lang.Object k) -
size
public int size() -
remove
public boolean remove(java.lang.Object k) -
add
-
clear
public void clear() -
isEmpty
public boolean isEmpty() -
toArray
public java.lang.Object[] toArray() -
toArray
public <K> K[] toArray(K[] a) -
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.
-