public interface ReferenceSet<K> extends ReferenceCollection<K>, java.util.Set<K>
Set
; provides some additional methods that use polymorphism to avoid (un)boxing.
Additionally, this interface strengthens (again) iterator()
.
This interface specifies reference equality semantics (members will be compared equal with
==
instead of equals
), which may result in breaks in contract
if attempted to be used with non reference-equality semantics based Set
s. For example, a
aReferenceSet.equals(aObjectSet)
may return different a different result then
aObjectSet.equals(aReferenceSet)
, in violation of equals
's contract
requiring it being symmetric.
Set
Modifier and Type | Method and Description |
---|---|
ObjectIterator<K> |
iterator()
Returns a type-specific iterator on the elements of this set.
|
static <K> ReferenceSet<K> |
of()
Returns an immutable empty set.
|
static <K> ReferenceSet<K> |
of(K... a)
Returns an immutable list with the elements given.
|
static <K> ReferenceSet<K> |
of(K e)
Returns an immutable set with the element given.
|
static <K> ReferenceSet<K> |
of(K e0,
K e1)
Returns an immutable set with the elements given.
|
static <K> ReferenceSet<K> |
of(K e0,
K e1,
K e2)
Returns an immutable set with the elements given.
|
default ObjectSpliterator<K> |
spliterator()
Returns a type-specific spliterator on the elements of this set.
|
ObjectIterator<K> iterator()
iterator
in interface java.util.Collection<K>
iterator
in interface java.lang.Iterable<K>
iterator
in interface ObjectIterable<K>
iterator
in interface ReferenceCollection<K>
iterator
in interface java.util.Set<K>
Iterable.iterator()
Iterable.iterator()
,
which was already strengthened in the corresponding type-specific class,
but was weakened by the fact that this interface extends Set
.
Also, this is generally the only iterator
method subclasses should override.
default ObjectSpliterator<K> spliterator()
Set spliterators must report at least Spliterator.DISTINCT
.
See Set.spliterator()
for more documentation on the requirements
of the returned spliterator.
spliterator
in interface java.util.Collection<K>
spliterator
in interface java.lang.Iterable<K>
spliterator
in interface ObjectIterable<K>
spliterator
in interface ReferenceCollection<K>
spliterator
in interface java.util.Set<K>
Collection.spliterator()
, which was already
strengthened in the corresponding type-specific class,
but was weakened by the fact that this interface extends Set
.
Also, this is generally the only spliterator
method subclasses should override.
Spliterator
for documentation on what binding policies mean)
that wraps this instance's type specific iterator()
.
Additionally, it reports Spliterator.SIZED
and Spliterator.DISTINCT
.
Iterator
is an inherently linear API, the returned spliterator will yield limited performance gains
when run in parallel contexts, as the returned spliterator's
trySplit()
will have linear runtime.static <K> ReferenceSet<K> of()
static <K> ReferenceSet<K> of(K e)
e
- an element.e
.static <K> ReferenceSet<K> of(K e0, K e1)
e0
- the first element.e1
- the second element.e0
and e1
.java.lang.IllegalArgumentException
- if there were duplicate entries.static <K> ReferenceSet<K> of(K e0, K e1, K e2)
e0
- the first element.e1
- the second element.e2
- the third element.e0
, e1
, and e2
.java.lang.IllegalArgumentException
- if there were duplicate entries.@SafeVarargs static <K> ReferenceSet<K> of(K... a)
a
- the list of elements that will be in the final set.a
.java.lang.IllegalArgumentException
- if there are any duplicate entries.