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 TypeMethodDescriptionbooleanReturnstrueif the given object is also a set and the two sets have the same content.booleanisEmpty()Returnstrueif this set is empty.protected booleanReturnstrueif thesize()method is cheap.booleanremoveAll(Collection<?> c) Removes elements of the given collection from this set.intsize()Returns the number of elements in this set.Creates aSpliteratorwithout 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
hashCodeMethods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, iterator, remove, retainAll, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream
-
Constructor Details
-
SetOfUnknownSize
protected SetOfUnknownSize()For subclass constructors.
-
-
Method Details
-
isSizeKnown
protected boolean isSizeKnown()Returnstrueif thesize()method is cheap. This is sometimes the case whensize()has already been invoked and the subclasses cached the result.- Returns:
trueif thesize()method is cheap.
-
isEmpty
public boolean isEmpty()Returnstrueif this set is empty. This method avoids to invokesize()unless it is cheap.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
trueif 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:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein 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:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>- Parameters:
c- the collection containing elements to remove.- Returns:
trueif at least one element has been removed.
-
spliterator
Creates aSpliteratorwithout knowledge of collection size.- Returns:
- a
Spliteratorover the elements in this collection.
-
toArray
Returns the elements in an array.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin 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:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin 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
Returnstrueif 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:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceSet<E>- Overrides:
equalsin classAbstractSet<E>- Parameters:
object- the object to compare with this set.- Returns:
trueif the two set have the same content.
-