Class RangeIteratorAdapter
java.lang.Object
org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter
- All Implemented Interfaces:
Iterator,RangeIterator
- Direct Known Subclasses:
FrozenNodeIteratorAdapter
Adapter for turning normal
Iterators into RangeIterators.
This helper class is used by the adapter classes in this package to
implement the JCR iterator interfaces on top of normal Java iterators.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RangeIteratorStatic instance of an emptyRangeIterator. -
Constructor Summary
ConstructorsConstructorDescriptionRangeIteratorAdapter(Collection collection) Creates aRangeIteratorfor the given collection.RangeIteratorAdapter(Iterator iterator) Creates an adapter for the given iterator of unknown size.RangeIteratorAdapter(Iterator iterator, long size) Creates an adapter for the given iterator of the given size. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the current position of the iterator.longgetSize()Returns the size of the iterator.booleanhasNext()Checks if this iterator has more elements.next()Returns the next element in this iterator and advances the iterator position.voidremove()Removes the previously retrieved element.voidskip(long n) Skips the given number of elements.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
EMPTY
Static instance of an emptyRangeIterator.
-
-
Constructor Details
-
RangeIteratorAdapter
Creates an adapter for the given iterator of the given size.- Parameters:
iterator- adapted iteratorsize- size of the iterator, or -1 if unknown
-
RangeIteratorAdapter
Creates an adapter for the given iterator of unknown size.- Parameters:
iterator- adapted iterator
-
RangeIteratorAdapter
Creates aRangeIteratorfor the given collection.- Parameters:
collection- the collection to iterate
-
-
Method Details
-
getPosition
public long getPosition()Returns the current position of the iterator.- Specified by:
getPositionin interfaceRangeIterator- Returns:
- iterator position
-
getSize
public long getSize()Returns the size of the iterator.- Specified by:
getSizein interfaceRangeIterator- Returns:
- iterator size, or -1 if unknown
-
skip
Skips the given number of elements.- Specified by:
skipin interfaceRangeIterator- Parameters:
n- number of elements to skip- Throws:
IllegalArgumentException- if n is negativeNoSuchElementException- if skipped past the last element
-
hasNext
public boolean hasNext()Checks if this iterator has more elements. If there are no more elements and the size of the iterator is unknown, then the size is set to the current position. -
next
Returns the next element in this iterator and advances the iterator position. If there are no more elements and the size of the iterator is unknown, then the size is set to the current position.- Specified by:
nextin interfaceIterator- Returns:
- next element
- Throws:
NoSuchElementException- if there are no more elements
-
remove
Removes the previously retrieved element. Decreases the current position and size of this iterator.- Specified by:
removein interfaceIterator- Throws:
UnsupportedOperationException- if removes are not permittedIllegalStateException- if there is no previous element to remove
-