You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Bernhard Messer <bm...@apache.org> on 2005/03/10 17:20:15 UTC

subclasses of abstract Query class are not implementing all methods

Hi,

I would like to cache query objects in a hash map. My implementation 
failed, because not all of the Query classes are implementing the 
necessary method: "public int hashCode()". The same counts for the 
"public boolean equals (Object o)", "public String toString(String 
fieldName)" and "public String toString()". To force all subclasses of 
Query to implement this 4 methods, i would like to make them abstract 
within the base class and implement the missing ones in the subclasses. 
So in Query class itself, it would look:

public abstract String toString(String field);
public abstract String toString();
public abstract int hashCode();
public abstract boolean equals(Object o);

I think this would make the API cleaner and more usable.

Thoughts ???

Bernhard


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: subclasses of abstract Query class are not implementing all methods

Posted by Yonik Seeley <ys...@gmail.com>.
> Having a clean implementation of toString(), one would be able to
> reparse a Query with QueryParser. This is something which was discussed
> several times on the dev and user lists. I expect that it will work for
> all queries supported by QueryParser.

Only under certain restrictions.  Remember that the QueryParser uses
an Analyzer on field values, so it's impossible to guarantee that you
can go from String->Query->String and have them match...

-Yonik

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: subclasses of abstract Query class are not implementing all methods

Posted by Bernhard Messer <bm...@apache.org>.
David Spencer wrote:

> Bernhard Messer wrote:
>
>> Hi,
>>
>> I would like to cache query objects in a hash map. My implementation 
>> failed, because not all of the Query classes are implementing the 
>> necessary method: "public int hashCode()". The same counts for the 
>> "public boolean equals (Object o)", "public String toString(String 
>> fieldName)" and "public String toString()". To force all subclasses 
>> of Query to implement this 4 methods, i would like to make them 
>> abstract within the base class and implement the missing ones in the 
>> subclasses. So in Query class itself, it would look:
>>
>> public abstract String toString(String field);
>> public abstract String toString();
>
>
> What's the point of toString() w/o an argument - this doesn't really 
> matter for Query does it?

Having a clean implementation of toString(), one would be able to 
reparse a Query with QueryParser. This is something which was discussed 
several times on the dev and user lists. I expect that it will work for 
all queries supported by QueryParser.

>
>
>> public abstract int hashCode();
>> public abstract boolean equals(Object o);
>>
>> I think this would make the API cleaner and more usable.
>>
>> Thoughts ???
>>
>> Bernhard
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-dev-help@lucene.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: subclasses of abstract Query class are not implementing all methods

Posted by David Spencer <da...@tropo.com>.
Bernhard Messer wrote:

> Hi,
> 
> I would like to cache query objects in a hash map. My implementation 
> failed, because not all of the Query classes are implementing the 
> necessary method: "public int hashCode()". The same counts for the 
> "public boolean equals (Object o)", "public String toString(String 
> fieldName)" and "public String toString()". To force all subclasses of 
> Query to implement this 4 methods, i would like to make them abstract 
> within the base class and implement the missing ones in the subclasses. 
> So in Query class itself, it would look:
> 
> public abstract String toString(String field);
> public abstract String toString();

What's the point of toString() w/o an argument - this doesn't really 
matter for Query does it?

> public abstract int hashCode();
> public abstract boolean equals(Object o);
> 
> I think this would make the API cleaner and more usable.
> 
> Thoughts ???
> 
> Bernhard
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: subclasses of abstract Query class are not implementing all methods

Posted by Yonik Seeley <ys...@gmail.com>.
Great idea.  I am also planning on doing some caching based on query
objects, and I hadn't realized that these weren't implemented.

In the meantime, I guess I can cache an Object that contains a Query,
and traverse the query tree myself to implement missing .hashCode() or
.equals() functionality.

-Yonik


On Thu, 10 Mar 2005 17:20:15 +0100, Bernhard Messer <bm...@apache.org> wrote:
> Hi,
> 
> I would like to cache query objects in a hash map. My implementation
> failed, because not all of the Query classes are implementing the
> necessary method: "public int hashCode()". The same counts for the
> "public boolean equals (Object o)", "public String toString(String
> fieldName)" and "public String toString()". To force all subclasses of
> Query to implement this 4 methods, i would like to make them abstract
> within the base class and implement the missing ones in the subclasses.
> So in Query class itself, it would look:
> 
> public abstract String toString(String field);
> public abstract String toString();
> public abstract int hashCode();
> public abstract boolean equals(Object o);
> 
> I think this would make the API cleaner and more usable.
> 
> Thoughts ???
> 
> Bernhard
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org