/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Lucene.Net.Search { /// This abstract class defines methods to iterate over a set of non-decreasing /// doc ids. Note that this class assumes it iterates on doc Ids, and therefore /// {@link #NO_MORE_DOCS} is set to {@value #NO_MORE_DOCS} in order to be used as /// a sentinel object. Implementations of this class are expected to consider /// {@link Integer#MAX_VALUE} as an invalid value. /// public abstract class DocIdSetIterator { // TODO (3.0): review the javadocs and remove any references to '3.0'. private int doc = - 1; /// When returned by {@link #NextDoc()}, {@link #Advance(int)} and /// {@link #Doc()} it means there are no more docs in the iterator. /// public static readonly int NO_MORE_DOCS = System.Int32.MaxValue; /// Unsupported anymore. Call {@link #DocID()} instead. This method throws /// {@link UnsupportedOperationException} if called. /// /// /// use {@link #DocID()} instead. /// [Obsolete("use DocID() instead.")] public virtual int Doc() { throw new System.NotSupportedException("Call docID() instead."); } /// Returns the following: /// ///

/// NOTE: in 3.0, this method will become abstract. /// ///

/// 2.9 /// public virtual int DocID() { return doc; } /// Unsupported anymore. Call {@link #NextDoc()} instead. This method throws /// {@link UnsupportedOperationException} if called. /// /// /// use {@link #NextDoc()} instead. This will be removed in 3.0 /// [Obsolete("use NextDoc() instead. This will be removed in 3.0")] public virtual bool Next() { throw new System.NotSupportedException("Call nextDoc() instead."); } /// Unsupported anymore. Call {@link #Advance(int)} instead. This method throws /// {@link UnsupportedOperationException} if called. /// /// /// use {@link #Advance(int)} instead. This will be removed in 3.0 /// [Obsolete("use Advance(int) instead. This will be removed in 3.0")] public virtual bool SkipTo(int target) { throw new System.NotSupportedException("Call advance() instead."); } /// Advances to the next document in the set and returns the doc it is /// currently on, or {@link #NO_MORE_DOCS} if there are no more docs in the /// set.
/// /// NOTE: in 3.0 this method will become abstract, following the removal /// of {@link #Next()}. For backward compatibility it is implemented as: /// ///
		/// public int nextDoc() throws IOException {
		/// return next() ? doc() : NO_MORE_DOCS;
		/// }
		/// 
/// /// NOTE: after the iterator has exhausted you should not call this /// method, as it may result in unpredicted behavior. /// ///
/// 2.9 /// public virtual int NextDoc() { return doc = Next()?Doc():NO_MORE_DOCS; } /// Advances to the first beyond the current whose document number is greater /// than or equal to target. Returns the current document number or /// {@link #NO_MORE_DOCS} if there are no more docs in the set. ///

/// Behaves as if written: /// ///

		/// int advance(int target) {
		/// int doc;
		/// while ((doc = nextDoc()) < target) {
		/// }
		/// return doc;
		/// }
		/// 
/// /// Some implementations are considerably more efficient than that. ///

/// NOTE: certain implemenations may return a different value (each /// time) if called several times in a row with the same target. ///

/// NOTE: this method may be called with {@value #NO_MORE_DOCS} for /// efficiency by some Scorers. If your implementation cannot efficiently /// determine that it should exhaust, it is recommended that you check for that /// value in each call to this method. ///

/// NOTE: after the iterator has exhausted you should not call this /// method, as it may result in unpredicted behavior. ///

/// NOTE: in 3.0 this method will become abstract, following the removal /// of {@link #SkipTo(int)}. /// ///

/// 2.9 /// public virtual int Advance(int target) { if (target == NO_MORE_DOCS) { return doc = NO_MORE_DOCS; } return doc = SkipTo(target)?Doc():NO_MORE_DOCS; } } }