Ok I wasn't aware of DIS.EMPTY - calling DIS.EMPTY.iterator() is also
acceptable.

EmptyDISI does conform to the spec, as the spec says about docID(): "returns
-1 or NO_MORE_DOCS if nextDoc() or advance(int) were not called yet".
Therefore it's ok to return NO_MORE_DOCS upfront.

How do you propose we make the change? I can attach another patch which
removes EmptyDISI and changes all places to call DIS.EMPTY.iterator(), and
also change DIS.EMPTY to impl iterator() like EmptyDISI. Would that work?

Shai

On Mon, Jul 27, 2009 at 1:38 PM, Uwe Schindler <u...@thetaphi.de> wrote:

>  This was my second idea, if you really want to have this empty one.
> Instead of returing a SortedVIntList at all just create a subclass of the
> abstract one:
>
>
>
>   public static final DocIdSet EMPTY_DOCIDSET = new DocIdSet() {
>     public DocIdSetIterator iterator() {
>       return EmptyDocIdSetIterator.getInstance();
>     }
>   };
>
>  By the way, this iterator is not conformant to the spec, which says,
> before calling nextDoc() it should return -1!
>
>
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: u...@thetaphi.de
>   ------------------------------
>
> *From:* Shai Erera [mailto:ser...@gmail.com]
> *Sent:* Monday, July 27, 2009 12:32 PM
> *To:* java-dev@lucene.apache.org
> *Subject:* Re: svn commit: r798091 -
> /lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.java
>
>
>
> And BTW, now that I look at DIS.EMPTY, I think it can be improved by
> defining it like this:
>
>   public static final DocIdSet EMPTY_DOCIDSET = new SortedVIntList(new
> int[0]) {
>     public DocIdSetIterator iterator() {
>       return EmptyDocIdSetIterator.getInstance();
>     }
>   };
>
> Instead of having its iterator() always creating a new instance, it can
> return EmptyDISI's single instance.
>
> I can open an issue, but I think this can be committed quite trivially by
> one of the committers.
>
> Shai
>
> On Mon, Jul 27, 2009 at 1:26 PM, Uwe Schindler <u...@thetaphi.de> wrote:
>
> Right, and you can simply get an iterator from it.
>
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: u...@thetaphi.de
>
> > -----Original Message-----
> > From: Robert Muir [mailto:rcm...@gmail.com]
> > Sent: Monday, July 27, 2009 12:24 PM
> > To: java-dev@lucene.apache.org
> > Subject: Re: svn commit: r798091 -
> >
> /lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator
> > .java
> >
> > here it is: DocIdSet.EMPTY_DOCIDSET
> >
> > /** An empty {...@code DocIdSet} instance for easy use (this is currently
> >    * implemented using a {...@link SortedVIntList}). */
>
> >
> > On Mon, Jul 27, 2009 at 6:18 AM, Uwe Schindler<u...@thetaphi.de> wrote:
> > > Why do we need this class? There is already a static final empty
> > iterator
> > > available in DocIdSetIterator.EMPTY_DOCIDSET_ITERATOR (or something
> like
> > > that name)?
> > >
> > > -----
> > > Uwe Schindler
> > > H.-H.-Meier-Allee 63, D-28213 Bremen
> > > http://www.thetaphi.de
> > > eMail: u...@thetaphi.de
> > >
> > >> From: mikemcc...@apache.org [mailto:mikemcc...@apache.org]
> > >> Sent: Monday, July 27, 2009 12:03 PM
> > >> To: java-comm...@lucene.apache.org
> > >> Subject: svn commit: r798091 -
> > >>
> >
> /lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator
> > >> .java
> > >>
> > >> Author: mikemccand
> > >> Date: Mon Jul 27 10:02:34 2009
> > >> New Revision: 798091
> > >>
> > >> URL: http://svn.apache.org/viewvc?rev=798091&view=rev
> > >> Log:
> > >> LUCENE-1754: add EmptyDocIdSetIterator
> > >>
> > >> Added:
> > >>
> > >>
> >
> lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.
> > >> java   (with props)
> > >>
> > >> Added:
> > >>
> >
> lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.
> > >> java
> > >> URL:
> > >>
> >
> http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/
> > >> search/EmptyDocIdSetIterator.java?rev=798091&view=auto
> > >>
> >
> ==========================================================================
> > >> ====
> > >> ---
> > >>
> >
> lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.
> > >> java (added)
> > >> +++
> > >>
> >
> lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.
> > >> java Mon Jul 27 10:02:34 2009
> > >> @@ -0,0 +1,42 @@
> > >> +package org.apache.lucene.search;
> > >> +
> > >> +/**
> > >> + * 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.
> > >> + */
> > >> +
> > >> +import java.io.IOException;
> > >> +
> > >> +/**
> > >> + * An empty implementation for {...@link DocIdSetIterator}. This can be
> > used
> > >> by
> > >> + * classes which receive a null {...@link DocIdSet} from
> > >> + * {...@link Filter#getDocIdSet(org.apache.lucene.index.IndexReader)}.
> > >> + */
> > >> +public final class EmptyDocIdSetIterator extends DocIdSetIterator {
> > >> +
> > >> +  private static final DocIdSetIterator instance = new
> > >> EmptyDocIdSetIterator();
> > >> +
> > >> +  public static DocIdSetIterator getInstance() { return instance; }
> > >> +
> > >> +  // to prevent instantiation
> > >> +  private EmptyDocIdSetIterator() { }
> > >> +
> > >> +  public int advance(int target) throws IOException { return
> > >> NO_MORE_DOCS; }
> > >> +
> > >> +  public int docID() { return NO_MORE_DOCS; }
> > >> +
> > >> +  public int nextDoc() throws IOException { return NO_MORE_DOCS; }
> > >> +
> > >> +}
> > >>
> > >> Propchange:
> > >>
> >
> lucene/java/trunk/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.
> > >> java
> > >>
> -----------------------------------------------------------------------
> > ---
> > >> ----
> > >>     svn:eol-style = native
> > >>
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
> > > For additional commands, e-mail: java-dev-h...@lucene.apache.org
> > >
> > >
> >
> >
> >
> > --
> > Robert Muir
> > rcm...@gmail.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
> > For additional commands, e-mail: java-dev-h...@lucene.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-dev-h...@lucene.apache.org
>
>
>

Reply via email to