Class RangeIteratorAdapter

  • All Implemented Interfaces:
    java.util.Iterator, RangeIterator
    Direct Known Subclasses:
    FrozenNodeIteratorAdapter

    public class RangeIteratorAdapter
    extends java.lang.Object
    implements RangeIterator
    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.
    • Constructor Summary

      Constructors 
      Constructor Description
      RangeIteratorAdapter​(java.util.Collection collection)
      Creates a RangeIterator for the given collection.
      RangeIteratorAdapter​(java.util.Iterator iterator)
      Creates an adapter for the given iterator of unknown size.
      RangeIteratorAdapter​(java.util.Iterator iterator, long size)
      Creates an adapter for the given iterator of the given size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getPosition()
      Returns the current position of the iterator.
      long getSize()
      Returns the size of the iterator.
      boolean hasNext()
      Checks if this iterator has more elements.
      java.lang.Object next()
      Returns the next element in this iterator and advances the iterator position.
      void remove()
      Removes the previously retrieved element.
      void skip​(long n)
      Skips the given number of elements.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • RangeIteratorAdapter

        public RangeIteratorAdapter​(java.util.Iterator iterator,
                                    long size)
        Creates an adapter for the given iterator of the given size.
        Parameters:
        iterator - adapted iterator
        size - size of the iterator, or -1 if unknown
      • RangeIteratorAdapter

        public RangeIteratorAdapter​(java.util.Iterator iterator)
        Creates an adapter for the given iterator of unknown size.
        Parameters:
        iterator - adapted iterator
      • RangeIteratorAdapter

        public RangeIteratorAdapter​(java.util.Collection collection)
        Creates a RangeIterator for the given collection.
        Parameters:
        collection - the collection to iterate
    • Method Detail

      • getPosition

        public long getPosition()
        Returns the current position of the iterator.
        Specified by:
        getPosition in interface RangeIterator
        Returns:
        iterator position
      • getSize

        public long getSize()
        Returns the size of the iterator.
        Specified by:
        getSize in interface RangeIterator
        Returns:
        iterator size, or -1 if unknown
      • skip

        public void skip​(long n)
                  throws java.lang.IllegalArgumentException,
                         java.util.NoSuchElementException
        Skips the given number of elements.
        Specified by:
        skip in interface RangeIterator
        Parameters:
        n - number of elements to skip
        Throws:
        java.lang.IllegalArgumentException - if n is negative
        java.util.NoSuchElementException - 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.
        Specified by:
        hasNext in interface java.util.Iterator
        Returns:
        true if this iterator has more elements, false otherwise
      • next

        public java.lang.Object next()
                              throws java.util.NoSuchElementException
        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:
        next in interface java.util.Iterator
        Returns:
        next element
        Throws:
        java.util.NoSuchElementException - if there are no more elements
      • remove

        public void remove()
                    throws java.lang.UnsupportedOperationException,
                           java.lang.IllegalStateException
        Removes the previously retrieved element. Decreases the current position and size of this iterator.
        Specified by:
        remove in interface java.util.Iterator
        Throws:
        java.lang.UnsupportedOperationException - if removes are not permitted
        java.lang.IllegalStateException - if there is no previous element to remove