[
https://issues.apache.org/jira/browse/LUCENENET-287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12782981#action_12782981
]
Andrei Iliev commented on LUCENENET-287:
----------------------------------------
Digy, don't change "h" in GetHashCode to base.GetHashCode() - this is a bug.
If you do it, you'll get different hash code for array that are Equals.
Example:
static void Main(string[] args)
{
ArraListDest list1 = new ArraListDest();
ArraListDest list2 = new ArraListDest();
for (int i = 1; i < 10; i++)
{
list1.Add(i);
list2.Add(i);
}
Console.WriteLine("list1.Equals(list2)=" + list1.Equals(list2));
Console.WriteLine("list1.GetHashCode()=" + list1.GetHashCode());
Console.WriteLine("list2.GetHashCode()=" + list2.GetHashCode());
}
class ArraListDest : System.Collections.ArrayList
{
public override int GetHashCode()
{
int h = base.GetHashCode();
for (int i = 0; i < this.Count; i++)
{
Object si = this[i] ;
h = 31 * h + (si == null ? 0 : si.GetHashCode());
}
return h;
}
public override bool Equals(object obj)
{
if (obj == null) return false;
ArraListDest objToCompare = obj as ArraListDest;
if (objToCompare == null) return false;
if (this.Count != objToCompare.Count) return false;
for (int idx = 0; idx < this.Count; idx++)
{
if (!this[idx].Equals(objToCompare[idx])) return false;
}
return true;
}
}
> TestIndexWriterReader.TestUpdateDocument
> ------------------------------------------
>
> Key: LUCENENET-287
> URL: https://issues.apache.org/jira/browse/LUCENENET-287
> Project: Lucene.Net
> Issue Type: Bug
> Reporter: Andrei Iliev
> Attachments: SegmentInfos-DIGY.patch, SegmentInfos.patch,
> SegmentInfos2.patch, SegmentInfos3.patch, SegmentInfos4.patch
>
>
> SegmentInfos is derived from ArrayList. So Equals and GetHashCode should
> behave as java ArrayList (see LUCENENET-284).
> After that patch TestIndexWriterReader.TestUpdateDocument is passed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.