Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8E1F4200BDE for ; Thu, 10 Nov 2016 12:47:23 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 8CB5B160B14; Thu, 10 Nov 2016 11:47:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AC466160B22 for ; Thu, 10 Nov 2016 12:47:21 +0100 (CET) Received: (qmail 33810 invoked by uid 500); 10 Nov 2016 11:47:20 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 30145 invoked by uid 99); 10 Nov 2016 11:47:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2016 11:47:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 593F4EF79A; Thu, 10 Nov 2016 11:47:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nightowl888@apache.org To: commits@lucenenet.apache.org Date: Thu, 10 Nov 2016 11:47:28 -0000 Message-Id: <456b96ad18294274a231ae90298f6e5e@git.apache.org> In-Reply-To: <75d0a803894f49d5a0c77d723f975556@git.apache.org> References: <75d0a803894f49d5a0c77d723f975556@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/58] [abbrv] lucenenet git commit: Added object overrides to Core.Support.HashMap so it can be used as a dictionary key based on values within the dictionary rather than by reference equality. archived-at: Thu, 10 Nov 2016 11:47:23 -0000 Added object overrides to Core.Support.HashMap so it can be used as a dictionary key based on values within the dictionary rather than by reference equality. Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/63fa4caf Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/63fa4caf Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/63fa4caf Branch: refs/heads/master Commit: 63fa4caff3c10f2e9ad9c63c6b24043534f8a2a6 Parents: dc8a4b8 Author: Shad Storhaug Authored: Sat Nov 5 16:51:13 2016 +0700 Committer: Shad Storhaug Committed: Mon Nov 7 18:44:13 2016 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Support/HashMap.cs | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/63fa4caf/src/Lucene.Net.Core/Support/HashMap.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Support/HashMap.cs b/src/Lucene.Net.Core/Support/HashMap.cs index addd506..0fcf29a 100644 --- a/src/Lucene.Net.Core/Support/HashMap.cs +++ b/src/Lucene.Net.Core/Support/HashMap.cs @@ -125,6 +125,84 @@ namespace Lucene.Net.Support return this[key]; } + #region Object overrides + + public override bool Equals(object obj) + { + if (obj == this) + return true; + + if (!(obj is IDictionary)) + return false; + IDictionary m = (IDictionary)obj; + if (m.Count != Count) + return false; + + try + { + var i = GetEnumerator(); + while (i.MoveNext()) + { + KeyValuePair e = i.Current; + TKey key = e.Key; + TValue value = e.Value; + if (value == null) + { + if (!(m[key] == null && m.ContainsKey(key))) + return false; + } + else + { + if (!value.Equals(m[key])) + return false; + } + } + } + catch (InvalidCastException) + { + return false; + } + catch (NullReferenceException) + { + return false; + } + + return true; + } + + public override int GetHashCode() + { + int h = 0; + var i = GetEnumerator(); + while (i.MoveNext()) + h += i.Current.GetHashCode(); + return h; + } + + public override string ToString() + { + var i = GetEnumerator(); + if (!i.MoveNext()) + return "{}"; + + StringBuilder sb = new StringBuilder(); + sb.Append('{'); + for (;;) + { + var e = i.Current; + TKey key = e.Key; + TValue value = e.Value; + sb.Append(key); + sb.Append('='); + sb.Append(value); + if (!i.MoveNext()) + return sb.Append('}').ToString(); + sb.Append(',').Append(' '); + } + } + + #endregion + #region Implementation of IEnumerable public IEnumerator> GetEnumerator()