Clover coverage report -
Coverage timestamp: Fri Nov 19 2004 13:41:51 PST
file stats: LOC: 67   Methods: 5
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SearchIndex.java 87.5% 81% 100% 85.3%
coverage coverage
 1    package photospace.search;
 2   
 3    import java.io.*;
 4    import org.apache.commons.io.*;
 5    import org.apache.lucene.index.*;
 6   
 7    public class SearchIndex
 8    {
 9    File index;
 10    IndexReader reader;
 11   
 12  14 public SearchIndex(File index)
 13    throws IOException
 14    {
 15  14 this.index = index.getCanonicalFile();
 16    }
 17   
 18  63 public IndexReader getReader() throws IOException
 19    {
 20  63 synchronized(this)
 21    {
 22  1 if (!index.exists()) throw new IllegalStateException("Search index has not been created yet");
 23   
 24  62 if (reader == null)
 25    {
 26  15 try
 27    {
 28  15 reader = IndexReader.open(index);
 29    }
 30    catch (IOException e)
 31    {
 32  0 IndexWriter writer = new IndexWriter(index, new MetaAnalyzer(), true);
 33  0 writer.close();
 34  0 reader = IndexReader.open(index);
 35    }
 36    }
 37  62 return reader;
 38    }
 39    }
 40   
 41  45 public void closeReader() throws IOException
 42    {
 43  45 synchronized(this)
 44    {
 45  45 if (reader != null)
 46    {
 47  15 reader.close();
 48  15 reader = null;
 49    }
 50    }
 51    }
 52   
 53  14 public void update(File updated) throws IOException
 54    {
 55  14 synchronized(this)
 56    {
 57  14 closeReader();
 58  14 FileUtils.deleteDirectory(index);
 59  0 if (!updated.renameTo(index)) throw new IOException("Unable to move temporary index " + updated + " to " + index);
 60    }
 61    }
 62   
 63  1 public File getIndex()
 64    {
 65  1 return index;
 66    }
 67    }