示例#1
0
        /// <summary>
        /// Determines whether the collection contains all the elements in the specified collection.
        /// </summary>
        /// <param name="target">The collection to check.</param>
        /// <param name="c">Collection whose elements would be checked for containment.</param>
        /// <returns>true id the target collection contains all the elements of the specified collection.</returns>
        public static bool ContainsAll(System.Collections.ICollection target, System.Collections.ICollection c)
        {
            System.Collections.IEnumerator e = c.GetEnumerator();

            bool contains = false;

            //Reflection. Invoke "containsAll" method for proprietary classes or "Contains" method for each element in the collection
            System.Reflection.MethodInfo method;
            try
            {
                method = target.GetType().GetMethod("containsAll");

                if (method != null)
                {
                    contains = (bool)method.Invoke(target, new Object[] { c });
                }
                else
                {
                    method = target.GetType().GetMethod("Contains");
                    while (e.MoveNext() == true)
                    {
                        if ((contains = (bool)method.Invoke(target, new Object[] { e.Current })) == false)
                        {
                            break;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(contains);
        }
 public static void AddAll(System.Collections.Hashtable hashtable, System.Collections.ICollection items)
 {
     System.Collections.IEnumerator iter = items.GetEnumerator();
     System.Object item;
     while (iter.MoveNext())
     {
         item = iter.Current;
         hashtable.Add(item, item);
     }
 }
 /// <summary>
 /// Converts an ICollection instance to an ArrayList instance.
 /// </summary>
 /// <param name="c">The ICollection instance to be converted.</param>
 /// <returns>An ArrayList instance in which its elements are the elements of the ICollection instance.</returns>
 public static System.Collections.ArrayList ToArrayList(System.Collections.ICollection c)
 {
     System.Collections.ArrayList   tempArrayList  = new System.Collections.ArrayList();
     System.Collections.IEnumerator tempEnumerator = c.GetEnumerator();
     while (tempEnumerator.MoveNext())
     {
         tempArrayList.Add(tempEnumerator.Current);
     }
     return(tempArrayList);
 }
 public static bool Contains(System.Collections.ICollection col, System.Object item)
 {
     System.Collections.IEnumerator iter = col.GetEnumerator();
     while (iter.MoveNext())
     {
         if (iter.Current.Equals(item))
         {
             return(true);
         }
     }
     return(false);
 }
 public static void AddAllIfNotContains(System.Collections.Hashtable hashtable, System.Collections.ICollection items)
 {
     System.Collections.IEnumerator iter = items.GetEnumerator();
     System.Object item;
     while (iter.MoveNext())
     {
         item = iter.Current;
         if (hashtable.Contains(item) == false)
         {
             hashtable.Add(item, item);
         }
     }
 }
示例#6
0
        /// <summary>
        /// Gets the list items.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <returns></returns>
        internal static IList <IMessageMember> GetListItems(System.Collections.ICollection collection)
        {
            List <IMessageMember> result = new List <IMessageMember>();
            IEnumerator           enumer = collection.GetEnumerator();

            while (enumer.MoveNext())
            {
                MessageItem oItem = new MessageItem(enumer.Current);
                result.Add(oItem);
            }

            return(result);
        }
        /// <summary>
        /// Returns an array containing all the elements of the collection.
        /// </summary>
        /// <returns>The array containing all the elements of the collection.</returns>
        public static System.Object[] ToArray(System.Collections.ICollection c)
        {
            int index = 0;

            System.Object[] objects          = new System.Object[c.Count];
            System.Collections.IEnumerator e = c.GetEnumerator();

            while (e.MoveNext())
            {
                objects[index++] = e.Current;
            }

            return(objects);
        }
        public void getValues(ref int[] indexes, ref double[] values)
        {
            System.Collections.ICollection keys = hash.Keys;
            int count = keys.Count;

            indexes = new int[count];
            values  = new double[count];
            int i = 0;

            for (IEnumerator it = keys.GetEnumerator(); it.MoveNext();)
            {
                indexes[i]  = (int)it.Current;
                values[i++] = (double)hash[it.Current];
            }
        }
示例#9
0
        public void AddRangeInList(System.Collections.ICollection keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys cannot be null.");
            }
            IEnumerator          _enum = keys.GetEnumerator();
            object               obj;
            NCLinkedListNode <T> node;

            while (_enum.MoveNext())
            {
                node = new NCLinkedListNode <T>((T)_enum.Current);
                this.AddLast(node);
            }
        }
示例#10
0
        public void UnitRmk_ocCurrent_HotUpdate()
        {
            var rm = new RankedMap <char, int> {
                { 'c', 3 }
            };

            System.Collections.ICollection oc   = rm.Keys;
            System.Collections.IEnumerator etor = oc.GetEnumerator();

            bool ok = etor.MoveNext();

            Assert.AreEqual('c', etor.Current);

            rm.Clear();
            Assert.AreEqual('c', etor.Current);
        }
示例#11
0
        public void UnitRm_ocCurrent_HotUpdate()
        {
            var rm = new RankedMap <int, int>();
            var kv = new KeyValuePair <int, int> (1, -1);

            rm.Add(kv.Key, kv.Value);

            System.Collections.ICollection oc   = rm;
            System.Collections.IEnumerator etor = oc.GetEnumerator();

            bool ok = etor.MoveNext();

            Assert.AreEqual(new DictionaryEntry(kv.Key, kv.Value), etor.Current);

            rm.Clear();
            Assert.AreEqual(new DictionaryEntry(kv.Key, kv.Value), etor.Current);
        }
        /// <summary>
        /// Obtains an array containing all the elements of the collection.
        /// </summary>
        /// <param name="objects">The array into which the elements of the collection will be stored.</param>
        /// <returns>The array containing all the elements of the collection.</returns>
        public static System.Object[] ToArray(System.Collections.ICollection c, System.Object[] objects)
        {
            int index = 0;

            System.Type     type = objects.GetType().GetElementType();
            System.Object[] objs = (System.Object[])Array.CreateInstance(type, c.Count);

            System.Collections.IEnumerator e = c.GetEnumerator();

            while (e.MoveNext())
            {
                objs[index++] = e.Current;
            }

            //If objects is smaller than c then do not return the new array in the parameter
            if (objects.Length >= c.Count)
            {
                objs.CopyTo(objects, 0);
            }

            return(objs);
        }
示例#13
0
        /// <summary>
        /// Creates an enum set. The contained elements are the same as those
        /// contained in collection c. If c is an enum set, invoking this method is
        /// the same as invoking {@link #copyOf(EnumSet)}.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="c"></param>
        /// <returns></returns>
        public static EnumSet <E> CopyOf <E>(ICollection <E> c)
        {
            if (c is EnumSet <E> )
            {
                return(CopyOf((EnumSet <E>)c));
            }
            if (0 == c.Count)
            {
                throw new Exception("IllegalArgumentException");
            }
            IEnumerator <E> iterator = c.GetEnumerator();

            iterator.MoveNext();
            E           element = iterator.Current;
            EnumSet <E> set     = EnumSet <E> .NoneOf <E>((Type)((object)element).GetType());

            set.Add(element);
            while (iterator.MoveNext())
            {
                set.Add(iterator.Current);
            }
            return(set);
        }
示例#14
0
        private static bool CollectionsEqual(ICollection o1, ICollection o2)
        {
            IEnumerator e1 = o1.GetEnumerator();
            IEnumerator e2 = o2.GetEnumerator();

            int count;
            for (count = 0; e1.MoveNext() && e2.MoveNext(); count++)
            {
                if (!AreEqual(e1.Current, e2.Current))
                    break;
            }

            if (count == o1.Count && count == o2.Count)
                return true;

            return false;
        }