[ 
https://issues.apache.org/jira/browse/LUCENE-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13712434#comment-13712434
 ] 

David Smiley commented on LUCENE-460:
-------------------------------------

I am not an expert on hashCode generation, yet as any java developer I have to 
generate hash codes.  I typically leave this to my IDE, IntelliJ.  As I find 
the need to update a hashCode, *do you think it's bad form for me to outright 
replace an existing hashCode implementation you wrote that looks complicated to 
me with what IntelliJ generates?*:  Here's a specific example:

SpanNotQuery formerly:
{code:java}
    int h = include.hashCode();
    h = (h<<1) | (h >>> 31);  // rotate left
    h ^= exclude.hashCode();
    h = (h<<1) | (h >>> 31);  // rotate left
    h ^= Float.floatToRawIntBits(getBoost());
    return h;
{code}

IntelliJ will generate a hashCode for this + a new pre & post pair of integer 
fields I'm adding via LUCENE-5091:
{code:java}
    int result = super.hashCode();
    result = 31 * result + include.hashCode();
    result = 31 * result + exclude.hashCode();
    result = 31 * result + pre;
    result = 31 * result + post;
    return result;
{code}

Now that's a hashCode implementation I can understand, and I don't question 
it's validity because IntelliJ always generates them in a consistent fashion 
that I am used to seeing.  Your hashCode might be better, but I simply don't 
understand and thus can't maintain it.  Do you want me to consult you (or an 
applicable author of a confusing hashCode in general) every time?  Granted this 
doesn't happen often.

                
> hashCode improvements
> ---------------------
>
>                 Key: LUCENE-460
>                 URL: https://issues.apache.org/jira/browse/LUCENE-460
>             Project: Lucene - Core
>          Issue Type: Improvement
>          Components: core/search
>            Reporter: Yonik Seeley
>            Assignee: Yonik Seeley
>            Priority: Minor
>
> It would be nice for all Query classes to implement hashCode and equals to 
> enable them to be used as keys when caching.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to