Class CompositeDocumentSequence

  • All Implemented Interfaces:
    DocumentSequence, SafelyCloseable, Closeable, AutoCloseable

    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 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(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 AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface DocumentSequence
        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