lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrei Iliev (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LUCENENET-284) java vs .Net GetHashCode and Equals for ArrayList
Date Thu, 19 Nov 2009 16:51:39 GMT

    [ https://issues.apache.org/jira/browse/LUCENENET-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780141#action_12780141
] 

Andrei Iliev commented on LUCENENET-284:
----------------------------------------

It was (in 2.9.0) in Lucene.Net.Search.TestDisjunctionMaxQuery.TestBooleanRequiredEqualScores
test case. 
Now (in 2.9.1) it passed but (if just found why) it is due to fact that  the Clone method
now is different the code  in Java.
In java it is:
  public Object clone() {
    DisjunctionMaxQuery clone = (DisjunctionMaxQuery)super.clone();
    clone.disjuncts = (ArrayList)this.disjuncts.clone();
    return clone;
  }

In Lucene.Net 2.9.1 it is:
         public override System.Object Clone()
        {
            DisjunctionMaxQuery clone = (DisjunctionMaxQuery) base.Clone();
            return clone;
        }

But in Lucene.Net 2.9.0 it was similar to java code.
        public override System.Object Clone()
        {
            DisjunctionMaxQuery clone = (DisjunctionMaxQuery) base.Clone();
            clone.disjuncts = (System.Collections.ArrayList) this.disjuncts.Clone();
            return clone;
        }

If you change  Clone method back as it is in java, test case will fail until you apply patch.

I don't know why in Lucene.Net 2.9.1 Clone method was modified. But I think it is bad practice
to diverge from java until it is absolutely necessary ( and  in such a case it should be documented).

> java vs .Net GetHashCode and Equals for ArrayList 
> --------------------------------------------------
>
>                 Key: LUCENENET-284
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-284
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Andrei Iliev
>         Attachments: ArrayList.patch, ComparableListOfT.patch
>
>
> 1)In java the hash code of a list (and ArrayList) is defined to be the result of the
following calc:
> <code>
> hashCode = 1;
>   Iterator i = list.iterator();
>   while (i.hasNext()) {
>       Object obj = i.next();
>       hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
>   }
> </code>
> In .Net it hash code of object itself.
>  
> 2) In java two lists are defined to be equal if they contain the same elements in the
same order. 
> In .Net it compares the object references.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message