Package org.apache.sis.internal.util
Class ListOfUnknownSize<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
org.apache.sis.internal.util.ListOfUnknownSize<E>
- Type Parameters:
E- the type of elements in the list.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>
- Direct Known Subclasses:
GeoTiffStore.Components,WorldFileStore.Components
An alternative to
AbstractList for implementations having a costly size() method.
This class overrides some methods in a way that avoid or reduce calls to size().
Despite extending AbstractSequentialList, this class expects implementations to override
the random access method get(int) instead of listIterator(int).
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classThe iterator returned byAbstractList.listIterator(). -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif the given object is also a list and the two lists have the same content.protected abstract booleanexists(int index) Returnstrueif an element exists at the given index.abstract Eget(int index) Returns the element at the specified index.booleanisEmpty()Returnstrueif this list is empty.listIterator(int index) Returns a list iterator over the elements in this list.booleanremoveAll(Collection<?> c) Removes elements of the given collection from this list.intsize()Returns the number of elements in this list.protected intReturnssize()if its value is already known, or a negative value if the size is still unknown.Creates aSpliteratorwithout knowledge of collection size.Object[]toArray()Returns the elements in an array.<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.AbstractList
add, clear, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, 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, streamMethods inherited from interface java.util.List
addAll, contains, containsAll, remove, replaceAll, retainAll, sort
-
Constructor Details
-
ListOfUnknownSize
protected ListOfUnknownSize()For subclass constructors.
-
-
Method Details
-
sizeIfKnown
protected int sizeIfKnown()Returnssize()if its value is already known, or a negative value if the size is still unknown. The size may become known for example if it has been cached by the subclass. In such case, someListOfUnknownSizemethods will take a more efficient path.- Returns:
size()if its value is already known, or any negative value if it still costly to compute.
-
size
public int size()Returns the number of elements in this list. The default implementation counts the number of elements for whichexists(int)returnstrue. Subclasses are encouraged to cache this value if they know that the underlying storage is immutable.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- the number of elements in this list.
-
isEmpty
public boolean isEmpty()Returnstrueif this list is empty. This method avoids to invokesize()unless it is cheap.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
trueif this list is empty.
-
exists
protected abstract boolean exists(int index) Returnstrueif an element exists at the given index. If an element at index i exists, then all elements at index 0 to i - 1 also exist. Those elements do not need to be computed immediately if their computation is deferred.- Parameters:
index- the index where to verify if an element exists.- Returns:
trueif an element exists at the given index.
-
get
Returns the element at the specified index. Invoking this method may trig computation of the element if their computation is deferred.- Specified by:
getin interfaceList<E>- Overrides:
getin classAbstractSequentialList<E>- Parameters:
index- position of the element to get in this list.- Returns:
- the element at the given index.
- Throws:
IndexOutOfBoundsException- if the given index is out of bounds.
-
removeAll
Removes elements of the given collection from this list. This method avoids to invokesize().- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<E>- Parameters:
c- the collection containing elements to remove.- Returns:
trueif at least one element has been removed.
-
listIterator
Returns a list iterator over the elements in this list. The default implementation invokesexists(int)andget(int). Write operations are not supported.- Specified by:
listIteratorin interfaceList<E>- Specified by:
listIteratorin classAbstractSequentialList<E>- Parameters:
index- index of first element to be returned from the list.- Returns:
- a list iterator over the elements in this list.
- Throws:
IndexOutOfBoundsException- if the given index is out of bounds.
-
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 interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>- Returns:
- an array containing all list 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 interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>- Type Parameters:
T- the type array elements.- Parameters:
array- where to store the elements.- Returns:
- an array containing all list elements.
-
equals
Returnstrueif the given object is also a list and the two lists have the same content. This method avoids to invokesize()on this instance.- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceList<E>- Overrides:
equalsin classAbstractList<E>- Parameters:
object- the object to compare with this list.- Returns:
trueif the two list have the same content.
-