23 using System.Collections;
25 namespace Lucene.Net.Support
33 public static void Add(System.Collections.Hashtable hashtable, System.Object item)
35 hashtable.
Add(item, item);
38 public static void AddIfNotContains(System.Collections.Hashtable hashtable, System.Object item)
48 if (hashtable.Contains(item) ==
false)
50 hashtable.Add(item, item);
55 public static void AddIfNotContains(System.Collections.ArrayList hashtable, System.Object item)
60 if (hashtable.Contains(item) ==
false)
67 public static void AddAll(System.Collections.Hashtable hashtable, System.Collections.ICollection items)
69 System.Collections.IEnumerator iter = items.GetEnumerator();
71 while (iter.MoveNext())
74 hashtable.Add(item, item);
78 public static void AddAllIfNotContains(System.Collections.Hashtable hashtable, System.Collections.IList items)
81 for (
int i = 0; i < items.Count; i++)
84 if (hashtable.Contains(item) ==
false)
86 hashtable.Add(item, item);
91 public static void AddAllIfNotContains(System.Collections.Hashtable hashtable, System.Collections.ICollection items)
93 System.Collections.IEnumerator iter = items.GetEnumerator();
95 while (iter.MoveNext())
98 if (hashtable.Contains(item) ==
false)
100 hashtable.Add(item, item);
105 public static void AddAllIfNotContains(System.Collections.Generic.IDictionary<
string,
string> hashtable, System.Collections.Generic.ICollection<
string> items)
107 foreach (
string s
in items)
109 if (hashtable.ContainsKey(s) ==
false)
116 public static void AddAll(System.Collections.Generic.IDictionary<
string,
string> hashtable, System.Collections.Generic.ICollection<
string> items)
118 foreach (
string s
in items)
124 public static bool Contains(System.Collections.Generic.ICollection<
string> col,
string item)
126 foreach (
string s
in col)
if (s == item)
return true;
130 public static bool Contains(System.Collections.ICollection col, System.Object item)
132 System.Collections.IEnumerator iter = col.GetEnumerator();
133 while (iter.MoveNext())
135 if (iter.Current.Equals(item))
142 public static System.String CollectionToString(System.Collections.Generic.IDictionary<
string,
string> c)
144 Hashtable t =
new Hashtable();
145 foreach (
string key
in c.Keys)
149 return CollectionToString(t);
157 public static System.String CollectionToString(System.Collections.ICollection c)
159 System.Text.StringBuilder s =
new System.Text.StringBuilder();
164 System.Collections.ArrayList l =
new System.Collections.ArrayList(c);
166 bool isDictionary = (c is System.Collections.BitArray || c is System.Collections.Hashtable || c is System.Collections.IDictionary || c is System.Collections.Specialized.NameValueCollection || (l.Count > 0 && l[0] is System.Collections.DictionaryEntry));
167 for (
int index = 0; index < l.Count; index++)
169 if (l[index] == null)
171 else if (!isDictionary)
176 if (c is System.Collections.Specialized.NameValueCollection)
177 s.Append(((System.Collections.Specialized.NameValueCollection)c).GetKey(index));
179 s.Append(((System.Collections.DictionaryEntry)l[index]).Key);
181 if (c is System.Collections.Specialized.NameValueCollection)
182 s.Append(((System.Collections.Specialized.NameValueCollection)c).GetValues(index)[0]);
184 s.Append(((System.Collections.DictionaryEntry)l[index]).Value);
187 if (index < l.Count - 1)
193 if (c is System.Collections.ArrayList)
194 isDictionary =
false;
218 public static bool CompareStringArrays(System.String[] l1, System.String[] l2)
220 if (l1.Length != l2.Length)
222 for (
int i = 0; i < l1.Length; i++)
235 public static void Sort(System.Collections.IList list, System.Collections.IComparer Comparator)
237 if (((System.Collections.ArrayList)list).IsReadOnly)
238 throw new System.NotSupportedException();
240 if ((Comparator == null) || (Comparator is System.Collections.Comparer))
244 ((System.Collections.ArrayList)list).Sort();
246 catch (System.InvalidOperationException e)
248 throw new System.InvalidCastException(e.Message);
255 ((System.Collections.ArrayList)list).Sort(Comparator);
257 catch (System.InvalidOperationException e)
259 throw new System.InvalidCastException(e.Message);
271 public static void Fill(System.Array array, System.Int32 fromindex, System.Int32 toindex, System.Object val)
273 System.Object Temp_Object = val;
274 System.Type elementtype = array.GetType().GetElementType();
275 if (elementtype != val.GetType())
276 Temp_Object = Convert.ChangeType(val, elementtype);
277 if (array.Length == 0)
278 throw (
new System.NullReferenceException());
279 if (fromindex > toindex)
280 throw (
new System.ArgumentException());
281 if ((fromindex < 0) || ((System.Array)array).Length < toindex)
282 throw (
new System.IndexOutOfRangeException());
283 for (
int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++)
284 array.SetValue(Temp_Object, index);
293 public static void Fill(System.Array array, System.Object val)
295 Fill(array, 0, array.Length, val);
311 public static bool Equals(System.Array array1, System.Array array2)
314 if ((array1 == null) && (array2 == null))
316 else if ((array1 != null) && (array2 != null))
318 if (array1.Length == array2.Length)
320 int length = array1.Length;
322 for (
int index = 0; index < length; index++)
324 System.Object o1 = array1.GetValue(index);
325 System.Object o2 = array2.GetValue(index);
326 if (o1 == null && o2 == null)
328 else if (o1 == null || !o1.Equals(o2))