Пример #1
0
        public Bag <T> including(T element)
        {
            var copy = new Bag <T>(this);

            copy.Add(element);
            return(copy);
        }
        public virtual Bag <T> asBag()
        {
            var set = new Bag <T>();

            foreach (T element in this)
            {
                set.Add(element);
            }
            return(set);
        }
Пример #3
0
        public Bag <T> select(Func <T, bool> lambda)
        {
            var filter = this.Where(lambda);
            var result = new Bag <T>();

            foreach (T element in filter)
            {
                result.Add(element);
            }
            return(result);
        }
Пример #4
0
        public Bag <T2> collect <T2>(Func <T, T2> lambda)
        {
            var result = new Bag <T2>();

            foreach (T element in this)
            {
                result.Add(lambda(element));
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// http://download.eclipse.org/ocl/doc/6.0.0/ocl.pdf
        /// The bag containing all elements of self and objects.
        /// </summary>
        public Bag <T> includingAll(Collection <T> collection)
        {
            var result = new Bag <T>(this);

            foreach (T item in collection)
            {
                result.Add(item);
            }

            return(result);
        }
Пример #6
0
        public Bag <T2> flatten <T2>()
        {
            var result = new Bag <T2>();

            foreach (object element in this)
            {
                if (element is Bag <T2> )
                {
                    var subcollection = (Bag <T2>)element;
                    foreach (T2 e in subcollection.flatten <T2>().asSet())
                    {
                        result.Add(e);
                    }
                }
                else if (element is T2)
                {
                    var e = (T2)element;
                    result.Add(e);
                }
            }

            return(result);
        }
Пример #7
0
        /// <summary>
        /// http://download.eclipse.org/ocl/doc/6.0.0/ocl.pdf
        /// The bag containing all elements of self apart from all occurrences of all objects.
        /// </summary>
        public Bag <T> excludingAll(Collection <T> collection)
        {
            var result = new Bag <T>();

            foreach (T item in this)
            {
                if (!collection.Contains(item))
                {
                    result.Add(item);
                }
            }

            return(result);
        }
Пример #8
0
        public Bag <T2> selectByType <T2>()
        {
            var thisCollection = this;
            var result         = new Bag <T2>();

            foreach (T item in thisCollection)
            {
                var itemType = item.GetType();

                if (itemType == typeof(T2))
                {
                    result.Add((T2)Convert.ChangeType(item, typeof(T2)));
                }
            }
            return(result);
        }
Пример #9
0
        public Bag <T2> collect <T2>(Func <T, Collection <T2> > lambda)
        {
            var result = new Bag <T2>();

            foreach (T element in this)
            {
                var e = lambda(element);


                foreach (T2 ee in e)
                {
                    result.Add(ee);
                }
            }

            return(result);
        }
Пример #10
0
        public Bag <T> reject(Func <T, bool> lambda)
        {
            var remove = this.Where(lambda);


            var result = new Bag <T>();

            foreach (T element in this)
            {
                if (!remove.Contains(element))
                {
                    result.Add(element);
                }
            }

            return(result);
        }