Package org.apache.sis.internal.util
Class SetOfUnknownSize<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.apache.sis.internal.util.SetOfUnknownSize<E>
- Type Parameters:
E
- the type of elements in the set.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
- Direct Known Subclasses:
DerivedSet
,LazySet
,OperationMethodSet
An alternative to
AbstractSet
for implementations having a costly size()
method.
This class overrides some methods in a way that avoid or reduce calls to size()
.- Since:
- 0.7
- Version:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the given object is also a set and the two sets have the same content.boolean
isEmpty()
Returnstrue
if this set is empty.protected boolean
Returnstrue
if thesize()
method is cheap.boolean
removeAll
(Collection<?> c) Removes elements of the given collection from this set.int
size()
Returns the number of elements in this set.Creates aSpliterator
without knowledge of collection size.Object[]
toArray()
Returns the elements in an array.(package private) static <T> T[]
Implementation of the publictoArray()
methods without call tosize()
.<T> T[]
toArray
(T[] array) Returns the elements in the given array, or in a new array of the same type if it was necessary to allocate more space.Methods inherited from class java.util.AbstractSet
hashCode
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, iterator, remove, retainAll, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
SetOfUnknownSize
protected SetOfUnknownSize()For subclass constructors.
-
-
Method Details
-
isSizeKnown
protected boolean isSizeKnown()Returnstrue
if thesize()
method is cheap. This is sometimes the case whensize()
has already been invoked and the subclasses cached the result.- Returns:
true
if thesize()
method is cheap.
-
isEmpty
public boolean isEmpty()Returnstrue
if this set is empty. This method avoids to invokesize()
unless it is cheap.- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
- Returns:
true
if this set is empty.
-
size
public int size()Returns the number of elements in this set. The default implementation counts the number of elements returned by the iterator. Subclasses are encouraged to cache this value if they know that the underlying storage is immutable.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
- Returns:
- the number of elements in this set.
-
removeAll
Removes elements of the given collection from this set. This method avoids to invokesize()
.- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceSet<E>
- Overrides:
removeAll
in classAbstractSet<E>
- Parameters:
c
- the collection containing elements to remove.- Returns:
true
if at least one element has been removed.
-
spliterator
Creates aSpliterator
without knowledge of collection size.- Returns:
- a
Spliterator
over the elements in this collection.
-
toArray
Returns the elements in an array.- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
- Returns:
- an array containing all set elements.
-
toArray
public <T> T[] toArray(T[] array) Returns the elements in the given array, or in a new array of the same type if it was necessary to allocate more space.- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
- Type Parameters:
T
- the type array elements.- Parameters:
array
- where to store the elements.- Returns:
- an array containing all set elements.
-
toArray
Implementation of the publictoArray()
methods without call tosize()
. -
equals
Returnstrue
if the given object is also a set and the two sets have the same content. This method avoids to invokesize()
on this instance (but it still call that method on the other instance).- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceSet<E>
- Overrides:
equals
in classAbstractSet<E>
- Parameters:
object
- the object to compare with this set.- Returns:
true
if the two set have the same content.
-