Class ReferenceArraySet<K>
- All Implemented Interfaces:
ObjectIterable<K>
,ReferenceCollection<K>
,ReferenceSet<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
ConstructorDescriptionCreates a new empty array set.ReferenceArraySet
(int capacity) Creates a new empty array set of given initial capacity.Creates a new array set copying the contents of a given collection.Creates a new array set copying the contents of a given collection.ReferenceArraySet
(Object[] a) Creates a new array set using the given backing array.ReferenceArraySet
(Object[] a, int size) Creates a new array set using the given backing array and the given number of elements of the array.ReferenceArraySet
(Collection<? extends K> c) Creates a new array set copying the contents of a given set.ReferenceArraySet
(Set<? extends K> c) Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
clear()
clone()
Returns a deep copy of this set.boolean
boolean
isEmpty()
iterator()
Returns a type-specific iterator on the elements of this collection.static <K> ReferenceArraySet
<K> of()
Creates a new empty array set.static <K> ReferenceArraySet
<K> of
(K e) Creates a new array set using the element given.static <K> ReferenceArraySet
<K> of
(K... a) Creates a new array set using an array of elements.static <K> ReferenceArraySet
<K> Creates a new empty array set.static <K> ReferenceArraySet
<K> ofUnchecked
(K... a) Creates a new array set using an array of elements.boolean
int
size()
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.AbstractReferenceSet
equals, hashCode
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractReferenceCollection
toString
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll
-
Constructor Details
-
ReferenceArraySet
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
a
are distinct.- Parameters:
a
- the backing array.
-
ReferenceArraySet
public ReferenceArraySet()Creates a new empty array set. -
ReferenceArraySet
public ReferenceArraySet(int capacity) Creates a new empty array set of given initial capacity.- Parameters:
capacity
- the initial capacity.
-
ReferenceArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
ReferenceArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c
- a collection.
-
ReferenceArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
ReferenceArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c
- a collection.
-
ReferenceArraySet
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
size
elements ofa
are 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
a
are 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:ReferenceCollection
Returns a type-specific iterator on the elements of this collection.- Specified by:
iterator
in interfaceCollection<K>
- Specified by:
iterator
in interfaceIterable<K>
- Specified by:
iterator
in interfaceObjectIterable<K>
- Specified by:
iterator
in interfaceReferenceCollection<K>
- Specified by:
iterator
in interfaceReferenceSet<K>
- Specified by:
iterator
in interfaceSet<K>
- Specified by:
iterator
in classAbstractReferenceSet<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
DISTINCT
for 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:
spliterator
in interfaceCollection<K>
- Specified by:
spliterator
in interfaceIterable<K>
- Specified by:
spliterator
in interfaceObjectIterable<K>
- Specified by:
spliterator
in interfaceReferenceCollection<K>
- Specified by:
spliterator
in interfaceReferenceSet<K>
- Specified by:
spliterator
in interfaceSet<K>
- Returns:
- a type-specific spliterator on the elements of this collection.
-
contains
- Specified by:
contains
in interfaceCollection<K>
- Specified by:
contains
in interfaceSet<K>
- Overrides:
contains
in classAbstractCollection<K>
-
size
public int size()- Specified by:
size
in interfaceCollection<K>
- Specified by:
size
in interfaceSet<K>
- Specified by:
size
in classAbstractCollection<K>
-
remove
- Specified by:
remove
in interfaceCollection<K>
- Specified by:
remove
in interfaceSet<K>
- Overrides:
remove
in classAbstractCollection<K>
-
add
- Specified by:
add
in interfaceCollection<K>
- Specified by:
add
in interfaceSet<K>
- Overrides:
add
in classAbstractCollection<K>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<K>
- Specified by:
clear
in interfaceSet<K>
- Overrides:
clear
in classAbstractCollection<K>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<K>
- Specified by:
isEmpty
in interfaceSet<K>
- Overrides:
isEmpty
in classAbstractCollection<K>
-
toArray
- Specified by:
toArray
in interfaceCollection<K>
- Specified by:
toArray
in interfaceSet<K>
- Overrides:
toArray
in classAbstractCollection<K>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<K>
- Specified by:
toArray
in interfaceSet<K>
- Overrides:
toArray
in 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.
-