Coverage Report - org.galagosearch.core.store.DocumentIndexStore
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentIndexStore
86%
12/14
67%
4/6
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 
 3  
 package org.galagosearch.core.store;
 4  
 
 5  
 import java.io.IOException;
 6  
 import java.util.Collections;
 7  
 import java.util.List;
 8  
 import org.galagosearch.core.parse.Document;
 9  
 import org.galagosearch.core.parse.DocumentIndexReader;
 10  
 
 11  
 /**
 12  
  * <p>A DocumentStore that reads document data from corpus files.</p>
 13  
  * A DocumentIndexStore checks the corpus files sequentially until
 14  
  * it finds a matching document.</p>
 15  
  * @author trevor
 16  
  */
 17  
 public class DocumentIndexStore implements DocumentStore {
 18  
     List<DocumentIndexReader> readers;
 19  
 
 20  
     public DocumentIndexStore(DocumentIndexReader reader) {
 21  4
         this(Collections.singletonList(reader));
 22  4
     }
 23  
 
 24  4
     public DocumentIndexStore(List<DocumentIndexReader> readers) {
 25  4
         this.readers = readers;
 26  4
     }
 27  
 
 28  
     public Document get(String identifier) throws IOException {
 29  4
         for (DocumentIndexReader reader : readers) {
 30  4
             Document document = reader.getDocument(identifier);
 31  4
             if (document != null) {
 32  4
                 return document;
 33  
             }
 34  0
         }
 35  0
         return null;
 36  
     }
 37  
 
 38  
     public void close() throws IOException {
 39  4
         for (DocumentIndexReader reader : readers) {
 40  4
             reader.close();
 41  
         }
 42  4
     }
 43  
 }