it.unimi.di.mg4j.search
Class AbstractIntervalDocumentIterator

java.lang.Object
  extended by it.unimi.di.mg4j.search.AbstractDocumentIterator
      extended by it.unimi.di.mg4j.search.AbstractIntervalDocumentIterator
All Implemented Interfaces:
DocumentIterator
Direct Known Subclasses:
AbstractCompositeDocumentIterator, AlignDocumentIterator, DifferenceDocumentIterator, LowPassDocumentIterator

public abstract class AbstractIntervalDocumentIterator
extends AbstractDocumentIterator

An abstract iterator on documents that provides basic support for handling interval iterators.

Implementing subclasses must override getIntervalIterator(Index, int, boolean, Object) so that it returns the correct interval iterator. Note that because of delays in class initialization, the constructor of this class takes a number of apparently disparate parameters: they are necessary to initialize various kinds of interval iterators. This class provides static methods that help in building the correct value for the parameters of the constructor.


Field Summary
protected  Index2IntervalIteratorMap currentIterators
          A map from indices to the iterators returned for the current document.
protected  ReferenceSet<Index> indices
          The set of indices involved in this iterator.
protected  Index2IntervalIteratorMap intervalIterators
          A map from indices to interval iterators.
protected  Index soleIndex
          If not null, the sole index involved in this document iterator.
protected  IntervalIterator soleIntervalIterator
          If not null, the sole interval iterator involved in this document iterator.
protected  Reference2ReferenceMap<Index,IntervalIterator> unmodifiableCurrentIterators
          An unmodifiable wrapper around currentIterators.
 
Fields inherited from class it.unimi.di.mg4j.search.AbstractDocumentIterator
curr, weight
 
Fields inherited from interface it.unimi.di.mg4j.search.DocumentIterator
END_OF_LIST
 
Constructor Summary
protected AbstractIntervalDocumentIterator(int n, ReferenceSet<Index> indices, boolean allIndexIterators, Object arg)
          Creates a new instance.
 
Method Summary
protected static boolean allIndexIterators(DocumentIterator... documentIterator)
          A commodity static methods that checks whether all specified document iterators are actually index iterators.
protected abstract  IntervalIterator getIntervalIterator(Index index, int n, boolean allIndexIterators, Object arg)
          Creates an interval iterator suitable for this AbstractIntervalDocumentIterator.
 ReferenceSet<Index> indices()
          Returns the set of indices over which this iterator is built.
protected static ReferenceArraySet<Index> indices(Index index, DocumentIterator... documentIterator)
          A commodity static methods that computes the union of the indices of the given document iterators.
 
Methods inherited from class it.unimi.di.mg4j.search.AbstractDocumentIterator
document, ensureOnADocument, mayHaveNext, weight, weight
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.unimi.di.mg4j.search.DocumentIterator
accept, acceptOnTruePaths, dispose, intervalIterator, intervalIterator, intervalIterators, nextDocument, skipTo
 

Field Detail

indices

protected final ReferenceSet<Index> indices
The set of indices involved in this iterator.


soleIndex

protected final Index soleIndex
If not null, the sole index involved in this document iterator.


soleIntervalIterator

protected final IntervalIterator soleIntervalIterator
If not null, the sole interval iterator involved in this document iterator.


intervalIterators

protected final Index2IntervalIteratorMap intervalIterators
A map from indices to interval iterators.


currentIterators

protected final Index2IntervalIteratorMap currentIterators
A map from indices to the iterators returned for the current document. The key set may not contain an index because the related iterator has never been requested. Note that implementing subclasses might use this map just to store the result of DocumentIterator.intervalIterators(), leaving the tracking of current iterators to some other mechanism.


unmodifiableCurrentIterators

protected final Reference2ReferenceMap<Index,IntervalIterator> unmodifiableCurrentIterators
An unmodifiable wrapper around currentIterators.

Constructor Detail

AbstractIntervalDocumentIterator

protected AbstractIntervalDocumentIterator(int n,
                                           ReferenceSet<Index> indices,
                                           boolean allIndexIterators,
                                           Object arg)
Creates a new instance.

Parameters:
n - the number of underlying iterators.
indices - the set of indices appearing in the underlying iterators.
allIndexIterators - whether all underlying iterators are index iterators.
arg - an argument that will be passed to getIntervalIterator(Index, int, boolean, Object).
Method Detail

getIntervalIterator

protected abstract IntervalIterator getIntervalIterator(Index index,
                                                        int n,
                                                        boolean allIndexIterators,
                                                        Object arg)
Creates an interval iterator suitable for this AbstractIntervalDocumentIterator.

Parameters:
index - the reference index for the iterator, or null.
n - the number of underlying or component iterators.
allIndexIterators - whether all underlying or component iterators are index iterators.
arg - an optional argument.
Returns:
an interval iterator suitable for this AbstractIntervalDocumentIterator.

indices

public ReferenceSet<Index> indices()
Description copied from interface: DocumentIterator
Returns the set of indices over which this iterator is built.

Returns:
the set of indices over which this iterator is built.

indices

protected static ReferenceArraySet<Index> indices(Index index,
                                                  DocumentIterator... documentIterator)
A commodity static methods that computes the union of the indices of the given document iterators.

Parameters:
index - an index that will be passed to AbstractCompositeDocumentIterator.AbstractCompositeDocumentIterator(Index, Object, DocumentIterator...).
documentIterator - a list of document iterators.
Returns:
a set containing the union of the indices of the given document iterators.

allIndexIterators

protected static boolean allIndexIterators(DocumentIterator... documentIterator)
A commodity static methods that checks whether all specified document iterators are actually index iterators.

Parameters:
documentIterator - a list of document iterators.
Returns:
true if all elements of documentIterator are actually index iterators.