lucenenet-dev mailing list archives

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

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

Nicholas Paldino commented on LUCENENET-284:
--------------------------------------------

Andrei (btw, it's Nicholas, not Nikolas),

This class does indeed implement IEquatable<T> and overrides the Equals and GetHashCode
methods correctly.

The IComparable<T> was an addon, and can be removed, it's not necessary, as long as
the private static CompareTo method is retained, Equals and the IEquatable<T> implementation
will still work.  Technically, equality is a subset of comparison operations, so it is a natural
fit to implement the comparison operators and IComparable.

It's also not refactored.  It's a new class in SupportClass which is used in the places it
is needed (which I got from the patch you gave).  I'm recommending your patch not be applied,
it differs too much from the Java code.

It's a better fit because it causes the least amount of diffs (compared to using an ArrayList)
between this and the Java code (which seems to be the priority over all things) when used
as opposed to the other solutions (I haven't seen what Michael has done, but I haven't seen
a separate class with the same semantics which causes the least amount of diffs between the
java code and the .NET code).

> 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