Example #1
0
        /// <summary>
        /// Creates a new enum set, containing only the specified element. There are
        /// six overloadings of the method. They accept from one to five elements
        /// respectively. The sixth one receives arbitrary number of elements, and
        /// runs slower than those only receive fixed number of elements.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="e"></param>
        /// <returns></returns>
        public static EnumSet <E> Of <E>(E e)
        {
            EnumSet <E> set = EnumSet <E> .NoneOf <E>(((object)e).GetType());

            set.Add(e);
            return(set);
        }
Example #2
0
        /// <summary>
        /// Creates an enum set. All the contained elements are of type Class<E>,
        /// and the contained elements are the same as those contained in s.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="s"></param>
        /// <returns></returns>
        public static EnumSet <E> CopyOf <E>(EnumSet <E> s)
        {
            EnumSet <E> set = EnumSet <E> .NoneOf <E>(s.elementClass);

            set.AddAll(s);
            return(set);
        }
Example #3
0
        /// <summary>
        /// Creates an enum set containing all the elements within the range defined
        /// by start and end (inclusive). All the elements must be in order.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static EnumSet <E> Range <E>(E start, E end)
        {
            if ((int)(object)start - (int)(object)end > 0)
            {
                throw new Exception("IllegalArgumentException");
            }
            EnumSet <E> set = EnumSet <E> .NoneOf <E>((Type)((object)start).GetType());

            set.SetRange(start, end);
            return(set);
        }
Example #4
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);
        }
Example #5
0
 public static EnumSet <Z> NoneOf <Z>(Type a)
 {
     return(EnumSet <Z> .NoneOf <Z>(a));
 }