public abstract class AbstractIterationSet<E> extends AbstractSet<E>
Set
implementations for which calculating size()
requires
an iteration through all of the set's elements to count them.
Superclass methods in AbstractSet
that rely on size()
are overridden with alternate
implementations that avoid the use of size()
when possible.
For a read-only implementation, subclasses should implement contains()
and iterator()
.
For a mutable implementation, subclasses should also implement add()
, remove()
,
and clear()
, and make the iterator()
mutable.
Modifier | Constructor and Description |
---|---|
protected |
AbstractIterationSet() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Overridden in
AbstractIterationSet to minimize the use of size() . |
int |
hashCode() |
boolean |
isEmpty()
Overridden in
AbstractIterationSet to minimize the use of size() . |
int |
size()
Calculate size.
|
Spliterator<E> |
spliterator()
Overridden in
AbstractIterationSet to avoid the use of size() . |
Object[] |
toArray()
Overridden in
AbstractIterationSet to minimize the use of size() . |
<T> T[] |
toArray(T[] array)
Overridden in
AbstractIterationSet to minimize the use of size() . |
removeAll
add, addAll, clear, contains, containsAll, iterator, remove, retainAll, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, clear, contains, containsAll, iterator, remove, retainAll
parallelStream, removeIf, stream
public int size()
The implementation in AbstractIterationSet
iterates through all of the elements.
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public boolean equals(Object obj)
AbstractIterationSet
to minimize the use of size()
.equals
in interface Collection<E>
equals
in interface Set<E>
equals
in class AbstractSet<E>
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in interface Set<E>
hashCode
in class AbstractSet<E>
public boolean isEmpty()
AbstractIterationSet
to minimize the use of size()
.isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
public Object[] toArray()
AbstractIterationSet
to minimize the use of size()
.toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] array)
AbstractIterationSet
to minimize the use of size()
.toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public Spliterator<E> spliterator()
AbstractIterationSet
to avoid the use of size()
.Copyright © 2022. All rights reserved.