com.thinkaurelius.titan.graphdb.query

## Class LimitAdjustingIterator<R>

- java.lang.Object
- - com.thinkaurelius.titan.graphdb.query.LimitAdjustingIterator<R>

- All Implemented Interfaces:
    Iterator<R>

      public abstract class LimitAdjustingIterator<R>
      extends Object
      implements Iterator<R>

  An iterator implementation that wraps around another iterator to iterate it up to a given limit. The idea is that the wrapped iterator is based on data that is fairly expensive to retrieve (e.g. from a database). As such, we don't want to retrieve all of it but "just enough". However, if more data is requested, then we want the wrapped iterator to be updated (i.e. additional data be retrieved). The limit for the wrapped iterator is updated by a factor of 2. When the iterator is updated, the iterator must be iterated through to the point of the last returned element. While this may seem expensive, it is less expensive than retrieving more than needed elements in the first place. However, this still means the initial currentLimit in the constructor should be chosen wisely.
  Author:
    Matthias Broecheler (me@matthiasb.com)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LimitAdjustingIterator(int maxLimit, int currentLimit)` Initializes this iterator with the current limit and the maximum number of elements that may be retrieved from the wrapped iterator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract Iterator<R>` | `getNewIterator(int newLimit)` This returns the wrapped iterator with up to the specified number of elements.
    `boolean` | `hasNext()`
    `R` | `next()`
    `void` | `remove()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LimitAdjustingIterator

          public LimitAdjustingIterator(int maxLimit,
                                int currentLimit)

      Initializes this iterator with the current limit and the maximum number of elements that may be retrieved from the wrapped iterator.
      Parameters:
        `maxLimit` -
        `currentLimit` -

  - ### Method Detail

    - #### getNewIterator

          public abstract Iterator<R> getNewIterator(int newLimit)

      This returns the wrapped iterator with up to the specified number of elements.
      Parameters:
        `newLimit` -
      Returns:

    - #### hasNext

          public boolean hasNext()

      Specified by:
        `hasNext` in interface `Iterator<R>`

    - #### next

          public R next()

      Specified by:
        `next` in interface `Iterator<R>`

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `Iterator<R>`

Copyright © 2012–2014. All rights reserved.