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 diff
     1.1 --- a/Arrays.cs	Sat Aug 21 16:02:05 2010 +0000
     1.2 +++ b/Arrays.cs	Sat Aug 21 18:22:23 2010 +0000
     1.3 @@ -3,7 +3,7 @@
     1.4  // 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.
     1.5  
     1.6  using System;
     1.7 -using System.Collections;
     1.8 +using System.Collections.Generic;
     1.9  
    1.10  namespace IBBoard
    1.11  {
    1.12 @@ -12,12 +12,12 @@
    1.13  	/// </summary>
    1.14  	public class Arrays
    1.15  	{
    1.16 -		public static object[] Subtract(object[] items, object[] subtract)
    1.17 +		public static T[] Subtract<T>(T[] items, T[] subtract)
    1.18  		{
    1.19 -			ArrayList arr = new ArrayList();
    1.20 +			List<T> arr = new List<T>();
    1.21  			arr.AddRange(items);
    1.22  			
    1.23 -			foreach (object obj in subtract)
    1.24 +			foreach (T obj in subtract)
    1.25  			{
    1.26  				arr.Remove(obj);
    1.27  			}
    1.28 @@ -25,9 +25,9 @@
    1.29  			return arr.ToArray();
    1.30  		}
    1.31  
    1.32 -		public static object[] Difference(object[] items1, object[] items2)
    1.33 +		public static T[] Difference<T>(T[] items1, T[] items2)
    1.34  		{
    1.35 -			object[] diffObjs;
    1.36 +			T[] diffObjs;
    1.37  
    1.38  
    1.39  			//Difference with as few loops as possible, so see which is shortest			
    1.40 @@ -44,12 +44,12 @@
    1.41  			return diffObjs;
    1.42  		}
    1.43  
    1.44 -		private static object[] DoDifference(object[] longArray, object[] shortArray)
    1.45 +		private static T[] DoDifference<T>(T[] longArray, T[] shortArray)
    1.46  		{
    1.47 -			ArrayList arr = new ArrayList();
    1.48 +			List<T> arr = new List<T>();
    1.49  			arr.AddRange(longArray);
    1.50  
    1.51 -			foreach (object obj in shortArray)
    1.52 +			foreach (T obj in shortArray)
    1.53  			{
    1.54  				if (arr.Contains(obj))
    1.55  				{
    1.56 @@ -64,12 +64,12 @@
    1.57  			return arr.ToArray();
    1.58  		}
    1.59  		
    1.60 -		public static int IndexOf(object[] items, object item)
    1.61 +		public static int IndexOf<T>(T[] items, T item)
    1.62  		{
    1.63  			return Array.IndexOf(items, item);
    1.64  		}
    1.65  
    1.66 -		public static bool Contains(object[] items, object item)
    1.67 +		public static bool Contains<T>(T[] items, T item)
    1.68  		{
    1.69  			return IndexOf(items, item) != -1;
    1.70  		}