Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 112   Methods: 9
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeTermDocs.java 100% 96.4% 88.9% 95.9%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: NodeTermDocs.java 821662 2009-10-05 02:09:28Z natalia $
 18    */
 19   
 20    package org.apache.xindice.core.query.ftsearch;
 21   
 22    import org.apache.lucene.index.TermDocs;
 23    import org.apache.lucene.index.Term;
 24    import org.apache.lucene.index.TermEnum;
 25   
 26    import java.util.ArrayList;
 27    import java.util.Iterator;
 28    import java.util.Map;
 29    import java.util.List;
 30   
 31    /**
 32    * TermDocs for searching over DOM nodes in memory
 33    *
 34    * @version $Revision: 821662 $, $Date: 2009-10-05 02:09:28 +0000 (Mon, 05 Oct 2009) $
 35    */
 36    public class NodeTermDocs implements TermDocs {
 37    protected int num;
 38    protected ArrayList[] nodes;
 39    protected Map termMap;
 40    protected int[] freqs;
 41    private boolean init;
 42   
 43  59 public NodeTermDocs(NodeReader reader) {
 44  59 nodes = reader.getNodes();
 45  59 termMap = reader.getTermMap();
 46   
 47  59 freqs = new int[nodes.length];
 48    }
 49   
 50  63 public void seek(Term term) {
 51  63 List docs = (List) termMap.get(term.text());
 52  63 if (docs != null) {
 53  41 for (Iterator i = docs.iterator(); i.hasNext(); ) {
 54  60 int idx = ((Integer) i.next()).intValue();
 55  60 freqs[idx]++;
 56    }
 57    }
 58   
 59  63 num = 0;
 60    }
 61   
 62  0 public void seek(TermEnum termEnum) {
 63  0 seek(termEnum.term());
 64    }
 65   
 66  8 public int doc() {
 67  8 return num;
 68    }
 69   
 70  8 public int freq() {
 71  8 return freqs[num];
 72    }
 73   
 74  8 public boolean next() {
 75  8 if (!init) {
 76  4 init = true;
 77  4 num = 0;
 78    } else {
 79  4 num++;
 80    }
 81   
 82  8 while(num < nodes.length && freqs[num] == 0) {
 83  3 num++;
 84    }
 85   
 86  8 return num < nodes.length;
 87    }
 88   
 89  95 public int read(int[] docs, int[] freqs) {
 90  95 int count = 0;
 91  95 for (int i = 0; i < docs.length && num < nodes.length; i++, num++) {
 92  89 if (this.freqs[num] > 0) {
 93  50 freqs[count] = this.freqs[num];
 94  50 docs[count] = num;
 95  50 count++;
 96    }
 97    }
 98   
 99  95 return count;
 100    }
 101   
 102  3 public boolean skipTo(int target) {
 103  3 num = target;
 104  3 return num < nodes.length;
 105    }
 106   
 107    /**
 108    * Not applicable
 109    */
 110  56 public void close() {
 111    }
 112    }