23 using System.Collections;
24 using System.Collections.Generic;
26 namespace Lucene.Net.Support
34 public class EquatableList<T> : System.Collections.Generic.List<T>,
35 IEquatable<System.Collections.Generic.IEnumerable<T>>,
47 public EquatableList(System.Collections.Generic.IEnumerable<T> collection) : base(collection) { }
58 public void AddRange(ICollection c)
61 if (c == null)
throw new ArgumentNullException(
"c");
64 Capacity = Math.Max(c.Count + Count, Capacity);
89 private static bool? EnumerableCountsEqual(System.Collections.Generic.IEnumerable<T> x, System.Collections.Generic.IEnumerable<T> y)
92 System.Collections.Generic.ICollection<T> xOfTCollection = x as System.Collections.Generic.ICollection<T>;
93 System.Collections.Generic.ICollection<T> yOfTCollection = y as System.Collections.Generic.ICollection<T>;
94 ICollection xCollection = x as ICollection;
95 ICollection yCollection = y as ICollection;
98 int? xCount = xOfTCollection != null ? xOfTCollection.Count : xCollection != null ? xCollection.Count : (
int?)null;
99 int? yCount = yOfTCollection != null ? yOfTCollection.Count : yCollection != null ? yCollection.Count : (
int?)null;
102 if (xCount == null || yCount == null)
109 return xCount == yCount;
125 private static bool Equals(System.Collections.Generic.IEnumerable<T> x,
126 System.Collections.Generic.IEnumerable<T> y)
129 if (x == null && y == null)
137 if (x == null || y == null)
146 bool? enumerableCountsEqual = EnumerableCountsEqual(x, y);
150 if (enumerableCountsEqual != null && !enumerableCountsEqual.Value)
159 System.Collections.Generic.EqualityComparer<T> defaultComparer =
160 EqualityComparer<T>.Default;
163 System.Collections.Generic.IEnumerator<T> otherEnumerator = y.GetEnumerator();
167 using (otherEnumerator as IDisposable)
170 foreach (T item
in x)
174 if (!otherEnumerator.MoveNext())
182 bool comparison = defaultComparer.Equals(item, otherEnumerator.Current);
194 if (!otherEnumerator.MoveNext())
206 #region IEquatable<IEnumerable<T>> Members
213 public bool Equals(System.Collections.Generic.IEnumerable<T> other)
216 return Equals(
this, other);
224 public override bool Equals(
object obj)
227 return Equals(obj as System.Collections.Generic.IEnumerable<T>);
232 public override int GetHashCode()
235 return GetHashCode(
this);
239 public static int GetHashCode<T>(System.Collections.Generic.IEnumerable<T> source)
245 public static int GetHashCode(System.Collections.Generic.IEnumerable<T> source)
249 if (source == null)
return 0;
255 int hashCode = typeof(T).GetHashCode();
258 foreach (T item
in source)
261 hashCode = 31 * hashCode + (item == null ? 0 : item.GetHashCode());
325 #region ICloneable Members
331 public object Clone()