Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / Index / AbstractAllTermDocs.cs
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
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21
22 namespace Mono.Lucene.Net.Index
23 {
24     /// <summary>
25     /// Base class for enumerating all but deleted docs.
26     /// 
27     /// <p/>NOTE: this class is meant only to be used internally
28     /// by Lucene; it's only public so it can be shared across
29     /// packages.  This means the API is freely subject to
30     /// change, and, the class could be removed entirely, in any
31     /// Lucene release.  Use directly at your own risk! */
32     /// </summary>
33     public abstract class AbstractAllTermDocs : TermDocs
34     {
35         protected int maxDoc;
36         protected int doc = -1;
37
38         protected AbstractAllTermDocs(int maxDoc)
39         {
40             this.maxDoc = maxDoc;
41         }
42
43         public void Seek(Term term)
44         {
45             if (term == null)
46             {
47                 doc = -1;
48             }
49             else
50             {
51                 throw new NotSupportedException();
52             }
53         }
54
55         public void Seek(TermEnum termEnum)
56         {
57             throw new NotSupportedException();
58         }
59
60         public int Doc()
61         {
62             return doc;
63         }
64
65         public int Freq()
66         {
67             return 1;
68         }
69
70         public bool Next()
71         {
72             return SkipTo(doc + 1);
73         }
74
75         public int Read(int[] docs, int[] freqs)
76         {
77             int length = docs.Length;
78             int i = 0;
79             while (i < length && doc < maxDoc)
80             {
81                 if (!IsDeleted(doc))
82                 {
83                     docs[i] = doc;
84                     freqs[i] = 1;
85                     ++i;
86                 }
87                 doc++;
88             }
89             return i;
90         }
91
92         public bool SkipTo(int target)
93         {
94             doc = target;
95             while (doc < maxDoc)
96             {
97                 if (!IsDeleted(doc))
98                 {
99                     return true;
100                 }
101                 doc++;
102             }
103             return false;
104         }
105
106         public void Close()
107         {
108         }
109
110         public abstract bool IsDeleted(int doc);
111     }
112 }