# HG changeset patch # User IBBoard # Date 1282414943 0 # Node ID cd96f6078edbd51c1dbf42a6b876292dfe4ba4c9 # Parent 3200ed24d29ed2f37ed670533371eee0bf67f870 Re #2: Refactor API * Make Arrays use generics for better return types diff -r 3200ed24d29e -r cd96f6078edb Arrays.cs --- a/Arrays.cs Sat Aug 21 16:02:05 2010 +0000 +++ b/Arrays.cs Sat Aug 21 18:22:23 2010 +0000 @@ -3,7 +3,7 @@ // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. using System; -using System.Collections; +using System.Collections.Generic; namespace IBBoard { @@ -12,12 +12,12 @@ /// public class Arrays { - public static object[] Subtract(object[] items, object[] subtract) + public static T[] Subtract(T[] items, T[] subtract) { - ArrayList arr = new ArrayList(); + List arr = new List(); arr.AddRange(items); - foreach (object obj in subtract) + foreach (T obj in subtract) { arr.Remove(obj); } @@ -25,9 +25,9 @@ return arr.ToArray(); } - public static object[] Difference(object[] items1, object[] items2) + public static T[] Difference(T[] items1, T[] items2) { - object[] diffObjs; + T[] diffObjs; //Difference with as few loops as possible, so see which is shortest @@ -44,12 +44,12 @@ return diffObjs; } - private static object[] DoDifference(object[] longArray, object[] shortArray) + private static T[] DoDifference(T[] longArray, T[] shortArray) { - ArrayList arr = new ArrayList(); + List arr = new List(); arr.AddRange(longArray); - foreach (object obj in shortArray) + foreach (T obj in shortArray) { if (arr.Contains(obj)) { @@ -64,12 +64,12 @@ return arr.ToArray(); } - public static int IndexOf(object[] items, object item) + public static int IndexOf(T[] items, T item) { return Array.IndexOf(items, item); } - public static bool Contains(object[] items, object item) + public static bool Contains(T[] items, T item) { return IndexOf(items, item) != -1; }