it.unimi.dsi.mg4j.search
Class AbstractDocumentIterator

java.lang.Object
  extended by it.unimi.dsi.fastutil.ints.AbstractIntIterator
      extended by it.unimi.dsi.mg4j.search.AbstractDocumentIterator
All Implemented Interfaces:
IntIterator, DocumentIterator, Iterable<Interval>, Iterator<Integer>
Direct Known Subclasses:
AbstractCompositeDocumentIterator, AlignDocumentIterator, DifferenceDocumentIterator, DocumentalConcatenatedClusterDocumentIterator, DocumentalMergedClusterDocumentIterator, LowPassDocumentIterator, NotDocumentIterator, PayloadPredicateDocumentIterator

public abstract class AbstractDocumentIterator
extends AbstractIntIterator
implements DocumentIterator

An abstract iterator on documents that implements hasNext() and nextInt() using nextDocument().

As explained elsewhere, since MG4J 1.2 the iteration logic has been made fully lazy, and the standard IntIterator methods are available as a commodity, but their use in performance-sensitive environments is strongly discouraged. The fully lazy implementation needs some bridging to be accessible using java.util's semi-lazy iterators, and this class provides the necessary code.

Instances of this class keep track of the next document to be returned, if it has been already peeked at by hasNext(), and of the last document returned by nextInt() or nextDocument(). Concrete subclasses must implement nextDocument() so that after it has been called last is equal to the returned document (possibly -1) and next is -1 (of course, if next has already been set nextDocument() must behave exactly like the implementation of nextInt() found in this class). Methods performing actions depending on the last document returned should throw an IllegalStateException if called when last is -1.


Nested Class Summary
protected static class AbstractDocumentIterator.AbstractIntervalIterator
           
 
Field Summary
protected  int last
          The last document returned by this iterator, or -1 if the iterator has never be advanced or if its state has been modified since the last call to nextInt() or nextDocument() because of a call to hasNext().
protected  int next
          The next document to be returned, if it has already been peeked at by hasNext(), or -1.
 
Constructor Summary
AbstractDocumentIterator()
           
 
Method Summary
 int document()
          Returns last, if it is not -1; otherwise, throws an IllegalStateException.
 boolean hasNext()
          Checks whether next has been already set; if not, peeks at the document returned by nextDocument().
 IntervalIterator iterator()
          Invokes DocumentIterator.intervalIterator()
 int nextInt()
          Deprecated. 
 
Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntIterator
next, remove, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.mg4j.search.DocumentIterator
accept, acceptOnTruePaths, dispose, indices, intervalIterator, intervalIterator, intervalIterators, nextDocument, skipTo
 
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator
skip
 
Methods inherited from interface java.util.Iterator
next, remove
 

Field Detail

last

protected int last
The last document returned by this iterator, or -1 if the iterator has never be advanced or if its state has been modified since the last call to nextInt() or nextDocument() because of a call to hasNext().


next

protected int next
The next document to be returned, if it has already been peeked at by hasNext(), or -1.

Constructor Detail

AbstractDocumentIterator

public AbstractDocumentIterator()
Method Detail

iterator

public IntervalIterator iterator()
Invokes DocumentIterator.intervalIterator()

Specified by:
iterator in interface DocumentIterator
Specified by:
iterator in interface Iterable<Interval>
Returns:
DocumentIterator.intervalIterator().

hasNext

public boolean hasNext()
Checks whether next has been already set; if not, peeks at the document returned by nextDocument().

Specified by:
hasNext in interface Iterator<Integer>
Returns:
true if next is not -1 or if nextDocument() has returned a valid document pointer.

nextInt

@Deprecated
public int nextInt()
Deprecated. 

Checks whether there is an element to be returned, sets last to next, next to -1, and returns last.

Specified by:
nextInt in interface IntIterator
Specified by:
nextInt in interface DocumentIterator
Overrides:
nextInt in class AbstractIntIterator
Returns:
the next document pointer, as cached by hasNext().
See Also:
DocumentIterator.nextDocument()

document

public int document()
Returns last, if it is not -1; otherwise, throws an IllegalStateException.

Specified by:
document in interface DocumentIterator
Returns:
last, if it is not -1.
Throws:
IllegalStateException - if last is -1.