Пример #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> 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);
        }
Пример #9
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);
        }