コード例 #1
0
        private readonly IList <IndexReader> subReadersList; // LUCENENET: Changed from IList<R> to IList<IndexReader> to eliminate casting

        /// <summary>
        /// Constructs a <see cref="BaseCompositeReader{R}"/> on the given <paramref name="subReaders"/>. </summary>
        /// <param name="subReaders"> the wrapped sub-readers. This array is returned by
        /// <see cref="GetSequentialSubReaders()"/> and used to resolve the correct
        /// subreader for docID-based methods. <b>Please note:</b> this array is <b>not</b>
        /// cloned and not protected for modification, the subclass is responsible
        /// to do this. </param>
        protected BaseCompositeReader(R[] subReaders)
        {
            this.subReaders = subReaders;

            // LUCENENET: To eliminate casting, we create the list explicitly
            var subReadersList = new JCG.List <IndexReader>(subReaders.Length);

            for (int i = 0; i < subReaders.Length; i++)
            {
                subReadersList.Add(subReaders[i]);
            }
            this.subReadersList = subReadersList.AsReadOnly();

            starts = new int[subReaders.Length + 1]; // build starts array
            int maxDoc = 0, numDocs = 0;

            for (int i = 0; i < subReaders.Length; i++)
            {
                starts[i] = maxDoc;
                IndexReader r = subReaders[i];
                maxDoc += r.MaxDoc; // compute maxDocs
                if (maxDoc < 0)     // overflow
                {
                    throw new ArgumentException("Too many documents, composite IndexReaders cannot exceed " + int.MaxValue);
                }
                numDocs += r.NumDocs; // compute numDocs
                r.RegisterParentReader(this);
            }
            starts[subReaders.Length] = maxDoc;
            this.maxDoc  = maxDoc;
            this.numDocs = numDocs;
        }