changeset 89:cd96f6078edb

Re #2: Refactor API * Make Arrays use generics for better return types
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Aug 2010 18:22:23 +0000
parents 3200ed24d29e
children 1575d57a8423
files Arrays.cs
diffstat 1 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 	/// </summary>
 	public class Arrays
 	{
-		public static object[] Subtract(object[] items, object[] subtract)
+		public static T[] Subtract<T>(T[] items, T[] subtract)
 		{
-			ArrayList arr = new ArrayList();
+			List<T> arr = new List<T>();
 			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>(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>(T[] longArray, T[] shortArray)
 		{
-			ArrayList arr = new ArrayList();
+			List<T> arr = new List<T>();
 			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>(T[] items, T item)
 		{
 			return Array.IndexOf(items, item);
 		}
 
-		public static bool Contains(object[] items, object item)
+		public static bool Contains<T>(T[] items, T item)
 		{
 			return IndexOf(items, item) != -1;
 		}