Return-Path: Delivered-To: apmail-incubator-lucene-net-commits-archive@minotaur.apache.org Received: (qmail 41083 invoked from network); 20 Nov 2009 02:05:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Nov 2009 02:05:12 -0000 Received: (qmail 90080 invoked by uid 500); 20 Nov 2009 02:05:12 -0000 Delivered-To: apmail-incubator-lucene-net-commits-archive@incubator.apache.org Received: (qmail 90064 invoked by uid 500); 20 Nov 2009 02:05:12 -0000 Mailing-List: contact lucene-net-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@incubator.apache.org Delivered-To: mailing list lucene-net-commits@incubator.apache.org Received: (qmail 90055 invoked by uid 99); 20 Nov 2009 02:05:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Nov 2009 02:05:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Nov 2009 02:05:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BA7E32388865; Fri, 20 Nov 2009 02:04:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r882386 - in /incubator/lucene.net/trunk/C#/src/Lucene.Net: Search/DisjunctionMaxQuery.cs Search/PhraseQuery.cs Search/Sort.cs Search/Spans/SpanOrQuery.cs SupportClass.cs Date: Fri, 20 Nov 2009 02:04:41 -0000 To: lucene-net-commits@incubator.apache.org From: aroush@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091120020441.BA7E32388865@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: aroush Date: Fri Nov 20 02:04:39 2009 New Revision: 882386 URL: http://svn.apache.org/viewvc?rev=882386&view=rev Log: Patch of LUCENENET-284: java vs .Net GetHashCode and Equals for ArrayList Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/DisjunctionMaxQuery.cs incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/DisjunctionMaxQuery.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/DisjunctionMaxQuery.cs?rev=882386&r1=882385&r2=882386&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/DisjunctionMaxQuery.cs (original) +++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/DisjunctionMaxQuery.cs Fri Nov 20 02:04:39 2009 @@ -40,7 +40,7 @@ { /* The subqueries */ - private System.Collections.ArrayList disjuncts = new System.Collections.ArrayList(); + private SupportClass.EquatableList disjuncts = new SupportClass.EquatableList(); /* Multiple of the non-max disjunct scores added into our final score. Non-zero values support tie-breaking. */ private float tieBreakerMultiplier = 0.0f; Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhraseQuery.cs?rev=882386&r1=882385&r2=882386&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs (original) +++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs Fri Nov 20 02:04:39 2009 @@ -35,8 +35,8 @@ public class PhraseQuery:Query { private System.String field; - private System.Collections.ArrayList terms = new System.Collections.ArrayList(4); - private System.Collections.ArrayList positions = new System.Collections.ArrayList(4); + private SupportClass.EquatableList terms = new SupportClass.EquatableList(4); + private SupportClass.EquatableList positions = new SupportClass.EquatableList(4); private int maxPosition = 0; private int slop = 0; @@ -107,7 +107,7 @@ /// Returns the set of terms in this phrase. public virtual Term[] GetTerms() { - return (Term[]) terms.ToArray(typeof(Term)); + return (Term[])terms.ToArray(); } /// Returns the relative positions of terms in this phrase. Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Sort.cs?rev=882386&r1=882385&r2=882386&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs (original) +++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs Fri Nov 20 02:04:39 2009 @@ -294,7 +294,7 @@ // TODO in Java 1.5: switch to Arrays.hashCode(). The // Java 1.4 workaround below calculates the same hashCode // as Java 1.5's new Arrays.hashCode() - return 0x45aaf665 + new System.Collections.ArrayList(fields).GetHashCode(); + return 0x45aaf665 + SupportClass.EquatableList.GetHashCode(fields); } static Sort() { Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanOrQuery.cs?rev=882386&r1=882385&r2=882386&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs (original) +++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs Fri Nov 20 02:04:39 2009 @@ -161,7 +161,7 @@ return "spans(" + Enclosing_Instance + ")@" + ((queue == null)?"START":(queue.Size() > 0?(Doc() + ":" + Start() + "-" + End()):"END")); } } - private System.Collections.ArrayList clauses; + private SupportClass.EquatableList clauses; private System.String field; /// Construct a SpanOrQuery merging the provided clauses. @@ -169,7 +169,7 @@ { // copy clauses array into an ArrayList - this.clauses = new System.Collections.ArrayList(clauses.Length); + this.clauses = new SupportClass.EquatableList(clauses.Length); for (int i = 0; i < clauses.Length; i++) { SpanQuery clause = clauses[i]; @@ -189,7 +189,7 @@ /// Return the clauses whose spans are matched. public virtual SpanQuery[] GetClauses() { - return (SpanQuery[]) clauses.ToArray(typeof(SpanQuery[])); + return (SpanQuery[]) clauses.ToArray(); } public override System.String GetField() Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/SupportClass.cs?rev=882386&r1=882385&r2=882386&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original) +++ incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Fri Nov 20 02:04:39 2009 @@ -1788,6 +1788,244 @@ } } + /// Represents a strongly typed list of objects that can be accessed by index. + /// Provides methods to search, sort, and manipulate lists. Also provides functionality + /// to compare lists against each other through an implementations of + /// . + /// The type of elements in the list. + [Serializable] + internal class EquatableList : System.Collections.Generic.List, + IEquatable> + { + /// Initializes a new instance of the + /// class that is empty and has the + /// default initial capacity. + internal EquatableList() : base() { } + + /// Initializes a new instance of the + /// class that contains elements copied from the specified collection and has + /// sufficient capacity to accommodate the number of elements copied. + /// The collection whose elements are copied to the new list. + internal EquatableList(System.Collections.Generic.IEnumerable collection) : base(collection) { } + + /// Initializes a new instance of the + /// class that is empty and has the specified initial capacity. + /// The number of elements that the new list can initially store. + internal EquatableList(int capacity) : base(capacity) { } + + /// Adds a range of objects represented by the + /// implementation. + /// The + /// implementation to add to this list. + internal void AddRange(ICollection c) + { + // If the collection is null, throw an exception. + if (c == null) throw new ArgumentNullException("c"); + + // Pre-compute capacity. + Capacity = c.Count - (Capacity - Count); + + // Cycle through the items and add. + foreach (T item in c) + { + // Add the item. + Add(item); + } + } + + /// Compares the contents of a + /// implementation to another one to determine equality. + /// Thinking of the implementation as + /// a string with any number of characters, the algorithm checks + /// each item in each list. If any item of the list is not equal (or + /// one list contains all the elements of another list), then that list + /// element is compared to the other list element to see which + /// list is greater. + /// The implementation + /// that is considered the left hand side. + /// The implementation + /// that is considered the right hand side. + /// True if the items are equal, false otherwise. + private static bool Equals(System.Collections.Generic.IEnumerable x, + System.Collections.Generic.IEnumerable y) + { + // If x and y are null, then return true, they are the same. + if (x == null && y == null) + { + // They are the same, return 0. + return true; + } + + // If one is null, then return a value based on whether or not + // one is null or not. + if (x == null || y == null) + { + // Return false, one is null, the other is not. + return false; + } + + // The default comparer. + System.Collections.Generic.EqualityComparer defaultComparer = + System.Collections.Generic.EqualityComparer.Default; + + // Get the enumerator for other. + System.Collections.Generic.IEnumerator otherEnumerator = y.GetEnumerator(); + + // Dispose if there is an implementation. + using (otherEnumerator as IDisposable) + { + // Cycle through the items in this list. + foreach (T item in x) + { + // If there isn't an item to get, then this has more + // items than that, they are not equal. + if (!otherEnumerator.MoveNext()) + { + // Return false. + return false; + } + + // Perform a comparison. Must check this on the left hand side + // and that on the right hand side. + bool comparison = defaultComparer.Equals(item, otherEnumerator.Current); + + // If the value is false, return false. + if (!comparison) + { + // Return the value. + return comparison; + } + } + + // If there are no more items, then return true, the sequences + // are equal. + if (!otherEnumerator.MoveNext()) + { + // The sequences are equal. + return true; + } + + // The other sequence has more items than this one, return + // false, these are not equal. + return false; + } + } + +#region IEquatable> Members + /// Compares this sequence to another + /// implementation, returning true if they are equal, false otherwise. + /// The other implementation + /// to compare against. + /// True if the sequence in + /// is the same as this one. + public bool Equals(System.Collections.Generic.IEnumerable other) + { + // Compare to the other sequence. If 0, then equal. + return Equals(this, other); + } +#endregion + + /// Compares this object for equality against other. + /// The other object to compare this object against. + /// True if this object and are equal, false + /// otherwise. + public override bool Equals(object obj) + { + // Call the strongly typed version. + return Equals(obj as System.Collections.Generic.IEnumerable); + } + + /// Gets the hash code for the list. + /// The hash code value. + public override int GetHashCode() + { + // Call the static method, passing this. + return GetHashCode(this); + } + + /// Gets the hash code for the list. + /// The + /// implementation which will have all the contents hashed. + /// The hash code value. + public static int GetHashCode(System.Collections.Generic.IEnumerable source) + { + // If source is null, then return 0. + if (source == null) return 0; + + // Seed the hash code with the hash code of the type. + // This is done so that you don't have a lot of collisions of empty + // ComparableList instances when placed in dictionaries + // and things that rely on hashcodes. + int hashCode = typeof(T).GetHashCode(); + + // Iterate through the items in this implementation. + foreach (T item in source) + { + // Adjust the hash code. + hashCode = 31 * hashCode + (item == null ? 0 : item.GetHashCode()); + } + + // Return the hash code. + return hashCode; + } + + /// Overload of the == operator, it compares a + /// to an + /// implementation. + /// The to compare + /// against . + /// The to compare + /// against . + /// True if the instances are equal, false otherwise. + public static bool operator ==(EquatableList x, System.Collections.Generic.IEnumerable y) + { + // Call Equals. + return Equals(x, y); + } + + /// Overload of the == operator, it compares a + /// to an + /// implementation. + /// The to compare + /// against . + /// The to compare + /// against . + /// True if the instances are equal, false otherwise. + public static bool operator ==(System.Collections.Generic.IEnumerable x, EquatableList y) + { + // Call equals. + return Equals(x, y); + } + + /// Overload of the != operator, it compares a + /// to an + /// implementation. + /// The to compare + /// against . + /// The to compare + /// against . + /// True if the instances are not equal, false otherwise. + public static bool operator !=(EquatableList x, System.Collections.Generic.IEnumerable y) + { + // Return the negative of the equals operation. + return !(x == y); + } + + /// Overload of the != operator, it compares a + /// to an + /// implementation. + /// The to compare + /// against . + /// The to compare + /// against . + /// True if the instances are not equal, false otherwise. + public static bool operator !=(System.Collections.Generic.IEnumerable x, EquatableList y) + { + // Return the negative of the equals operation. + return !(x == y); + } + } + /// /// A simple wrapper to allow for the use of the GeneralKeyedCollection. The /// wrapper is required as there can be several keys for an object depending