예제 #1
0
        /// <summary>
        /// Convert a java list to a generic collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <param name="applyPerItem">Apply this delegate to all list items before adding</param>
        /// <returns>A List<typeparamref name="T"/></returns>
        public static IList <T> ConvertFromJavaList <T>(List list, ApplyPerItemReverseDelegate <T> applyPerItem)
        {
            List <T> result = new List <T>(list.size());

            for (int i = 0; i < list.size(); i++)
            {
                if (null != applyPerItem)
                {
                    result.Add(applyPerItem(list.get(i)));
                    continue;
                }
                result.Add((T)list.get(i));
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Convert a java list to a generic collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="applyPerItem">Apply this delegate to all list items before adding</param>
        /// <returns>A List<typeparamref name="T"/></returns>
        public static IList <T> ConvertFromJavaList <T>(Collection collection, ApplyPerItemReverseDelegate <T> applyPerItem)
        {
            List <T> result = new List <T>(collection.size());

            for (Iterator iterator = collection.iterator(); iterator.hasNext();)
            {
                Object next = iterator.next();
                if (null != applyPerItem)
                {
                    result.Add(applyPerItem(next));
                    continue;
                }
                result.Add((T)next);
            }
            return(result);
        }