it.unimi.di.mg4j.document
Class CompositeDocumentSequence

java.lang.Object
  extended by it.unimi.di.mg4j.document.AbstractDocumentSequence
      extended by it.unimi.di.mg4j.document.CompositeDocumentSequence
All Implemented Interfaces:
DocumentSequence, SafelyCloseable, Closeable

public class CompositeDocumentSequence
extends AbstractDocumentSequence

A document sequence composing a list of underlying sequences.

An instance of this class exposes documents formed by juxtaposition of the content of the underlying document sequences. In particular, it instantiates a CompositeDocumentFactory using the provided optional array of field names.

For instance, by composing a document sequence whose documents have a single text field and a document sequence whose documents have a single integer field we obtain a new sequence whose documents have two fields.

The title and uri of composed documents are those of the documents returned by the first underlying sequence.


Constructor Summary
CompositeDocumentSequence(DocumentSequence... sequence)
          Creates a new composite document sequence using the provided underlying document sequences, which must possess distinct field names.
CompositeDocumentSequence(DocumentSequence[] sequence, String[] fieldName)
          Creates a new composite document sequence using the provided underlying document sequences.
 
Method Summary
 void close()
          Closes this document sequence, releasing all resources.
 DocumentFactory factory()
          Returns the factory used by this sequence.
 DocumentIterator iterator()
          Returns an iterator over the sequence of documents.
 
Methods inherited from class it.unimi.di.mg4j.document.AbstractDocumentSequence
filename, finalize, load
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeDocumentSequence

public CompositeDocumentSequence(DocumentSequence... sequence)
Creates a new composite document sequence using the provided underlying document sequences, which must possess distinct field names.

Parameters:
sequence - an array of underlying document sequences (they must return the same number of documents).

CompositeDocumentSequence

public CompositeDocumentSequence(DocumentSequence[] sequence,
                                 String[] fieldName)
Creates a new composite document sequence using the provided underlying document sequences.

Parameters:
sequence - an array of underlying document sequences (they must return the same number of documents).
fieldName - an array of field names for all fields resulting from the composition of the document factories of the underlying sequences: it will be passed to CompositeDocumentFactory.CompositeDocumentFactory(DocumentFactory[], String[]) (so in particular it may be null if all fields have distinct names).
Method Detail

close

public void close()
           throws IOException
Description copied from interface: DocumentSequence
Closes this document sequence, releasing all resources.

You should always call this method after having finished with this document sequence. Implementations are invited to call this method in a finaliser as a safety net (even better, implement SafelyCloseable), but since there is no guarantee as to when finalisers are invoked, you should not depend on this behaviour.

Specified by:
close in interface DocumentSequence
Specified by:
close in interface Closeable
Overrides:
close in class AbstractDocumentSequence
Throws:
IOException

factory

public DocumentFactory factory()
Description copied from interface: DocumentSequence
Returns the factory used by this sequence.

Every document sequence is based on a document factory that transforms raw bytes into a sequence of characters. The factory contains useful information such as the number of fields.

Returns:
the factory used by this sequence.

iterator

public DocumentIterator iterator()
                          throws IOException
Description copied from interface: DocumentSequence
Returns an iterator over the sequence of documents.

Warning: this method can be safely called just one time. For instance, implementations based on standard input will usually throw an exception if this method is called twice.

Implementations may decide to override this restriction (in particular, if they implement DocumentCollection). Usually, however, it is not possible to obtain two iterators at the same time on a collection.

Returns:
an iterator over the sequence of documents.
Throws:
IOException
See Also:
DocumentCollection