lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yonik Seeley <>
Subject Re: BooleanQuery.equals() change
Date Tue, 12 Apr 2005 14:59:27 GMT
> On Apr 11, 2005, at 5:57 PM, Yonik Seeley wrote:
> > Erik, why was the last change to BooleanQuery made?
> > The comment was "Correct BooleanQuery.equals such that every clause is
> > compared".
> >
> > It looks like Vector.equals() should have worked, and the new code is
> > probably slower as it creates two new arrays.
> Vector.equals() compares the Vector object instances and is only true
> if they are the same object - it does not compare the contents of the
> Vector for equality at that level.  Try it out with some test cases.

Did you try it out? (sorry, couldn't resist ;-)

The javadoc for Vector.equals() says it does the right thing.
Vector.equals() calls super.equals() which is AbstractList.equals()
which also "does the right thing".  As a sanity check, I did write a
simple test and tested it on 1.4 and 1.5 (the only JVMs I currently
have installed).  It's included at the end.

> Where in the .equals that I added are two arrays being created?

this.getClauses() and other.getClauses() both create an array.

>    public boolean equals(Object o) {
>      if (!(o instanceof BooleanQuery))
>        return false;
>      BooleanQuery other = (BooleanQuery)o;
>      return (this.getBoost() == other.getBoost())
>        &&  Arrays.equals(this.getClauses(), other.getClauses());
>    }
> It's especially risky on this list to use the word "probably" when
> talking about speed. :)  Is it really slower?

Yeah, I know... esp with todays latest HotSpot JVMs.  It was just an
educated guess.

> I'm more than happy to adjust the .equals method to something better;
> do you have a specific improvement?

Change it back to the original ;-)

I really wasn't trying to nitpick or anything... I had noticed your
comment about equals() and panicked a little since we really only want
to use an official lucene release in production (and we need to hash
on Query).


--------------------------- little test prog ---------------------------
import java.util.Vector;
public class vec {
  public static void main(String[] args) {
    Integer a = new Integer(5);
    Integer b = new Integer(5);
    Vector va = new Vector(); va.add(a);
    Vector vb = new Vector(); vb.add(b);
    System.out.println("should be false:" + (a==b) ); 
    System.out.println("should be true:" + a.equals(b) ); 
    System.out.println("should be true:" + va.equals(vb) ); 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message