Class ObjectArraySet<K>
- All Implemented Interfaces:
ObjectCollection<K>,ObjectIterable<K>,ObjectSet<K>,Serializable,Cloneable,Iterable<K>,Collection<K>,Set<K>
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:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty array set.ObjectArraySet(int capacity) Creates a new empty array set of given initial capacity.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(Object[] a) Creates a new array set using the given backing array.ObjectArraySet(Object[] a, int size) Creates a new array set using the given backing array and the given number of elements of the array.ObjectArraySet(Collection<? extends K> c) Creates a new array set copying the contents of a given set.ObjectArraySet(Set<? extends K> c) Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidclear()clone()Returns a deep copy of this set.booleanbooleanisEmpty()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> Creates a new empty array set.static <K> ObjectArraySet<K> ofUnchecked(K... a) Creates a new array set using an array of elements.booleanintsize()Returns a type-specific spliterator on the elements of this set.Object[]toArray()<T> T[]toArray(T[] 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 interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll
-
Constructor Details
-
ObjectArraySet
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
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:
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 interfaceCollection<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin interfaceObjectCollection<K>- Specified by:
iteratorin interfaceObjectIterable<K>- Specified by:
iteratorin interfaceObjectSet<K>- Specified by:
iteratorin interfaceSet<K>- Specified by:
iteratorin classAbstractObjectSet<K>- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
-
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 interfaceCollection<K>- Specified by:
spliteratorin interfaceIterable<K>- Specified by:
spliteratorin interfaceObjectCollection<K>- Specified by:
spliteratorin interfaceObjectIterable<K>- Specified by:
spliteratorin interfaceObjectSet<K>- Specified by:
spliteratorin interfaceSet<K>- Returns:
- a type-specific spliterator on the elements of this collection.
-
contains
- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Overrides:
containsin classAbstractCollection<K>
-
size
public int size()- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein interfaceSet<K>- Specified by:
sizein classAbstractCollection<K>
-
remove
- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Overrides:
removein classAbstractCollection<K>
-
add
- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Overrides:
addin classAbstractCollection<K>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceSet<K>- Overrides:
clearin classAbstractCollection<K>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<K>- Specified by:
isEmptyin interfaceSet<K>- Overrides:
isEmptyin classAbstractCollection<K>
-
toArray
- Specified by:
toArrayin interfaceCollection<K>- Specified by:
toArrayin interfaceSet<K>- Overrides:
toArrayin classAbstractCollection<K>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<K>- Specified by:
toArrayin interfaceSet<K>- Overrides:
toArrayin classAbstractCollection<K>
-
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.
-