示例#1
0
        /// <summary>
        /// Returns distinct items from the collection.
        /// </summary>
        /// <param name="source">
        /// The source collection to process.
        /// </param>
        /// <param name="args">
        /// 0: boolean flag specifying whether to include <c>null</c>
        /// in the results or not. Default is false, which means that
        /// <c>null</c> values will not be included in the results.
        /// </param>
        /// <returns>
        /// A collection containing distinct source collection elements.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// If there is more than one argument, or if the single optional argument
        /// is not <b>Boolean</b>.
        /// </exception>
        public object Process(ICollection source, object[] args)
        {
            if (source == null)
            {
                return(null);
            }

            bool includeNulls = false;

            if (args.Length == 1)
            {
                if (args[0] is bool)
                {
                    includeNulls = (bool)args[0];
                }
                else
                {
                    throw new ArgumentException("distinct() processor argument must be a boolean value.");
                }
            }
            else if (args.Length > 1)
            {
                throw new ArgumentException("Only a single argument can be specified for a distinct() processor.");
            }

            HybridSet set = new HybridSet(source);

            if (!includeNulls)
            {
                set.Remove(null);
            }
            return(set);
        }
        /// <summary>
        /// Returns distinct items from the collection.
        /// </summary>
        /// <param name="source">
        /// The source collection to process.
        /// </param>
        /// <param name="args">
        /// 0: boolean flag specifying whether to include <c>null</c>
        /// in the results or not. Default is false, which means that
        /// <c>null</c> values will not be included in the results.
        /// </param>
        /// <returns>
        /// A collection containing distinct source collection elements.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// If there is more than one argument, or if the single optional argument 
        /// is not <b>Boolean</b>.
        /// </exception>
        public object Execute(ICollection source, object[] args)
        {
            if (source == null)
            {
                return null;
            }

            var includeNulls = false;
            if (args.Length == 1)
            {
                if (args[0] is bool)
                {
                    includeNulls = (bool) args[0];
                }
                else
                {
                    throw new ArgumentException("distinct() processor argument must be a boolean value.");
                }
            }
            else if (args.Length > 1)
            {
                throw new ArgumentException("Only a single argument can be specified for a distinct() processor.");
            }

            var set = new HybridSet(source);
            if (!includeNulls)
            {
                set.Remove(null);
            }
            return set;
        }
示例#3
0
        public void Remove_Call_LetterSimpleSet_Remove()
        {
            bool res;
            var  PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.Remove("key");
            _LetterSimpleSetSubstitute.Received(1).Remove("key", out res);
        }
        public static HybridSet GetOperatorsForRequest(BookRequest b, NameValueCollection settings)
        {
            NameValueCollection pars                 = new NameValueCollection();
            HybridSet           filterlist           = new HybridSet();
            HybridSet           filteredaircraftlist = new HybridSet();

            pars.Add("status", "confirm");
            IList <Operator> oplist       = OperatorDAO.GetOperators(pars);
            HybridSet        aircraftlist = new HybridSet();

            foreach (Operator op in oplist)
            {
                aircraftlist.AddAll(op.Aircrafts);
            }

            String regionmatch = settings.Get("regionmatch");

            switch (regionmatch)
            {
            case "allinoperatedcountries":
            {
                ListSet countries = b.GetLegCountries();
                foreach (Operator op in oplist)
                {
                    if (op.OperatorCountries.ContainsAll(countries))
                    {
                        filteredaircraftlist.AddAll(op.Aircrafts);
                    }
                }
                break;
            }

            case "startingoperatedcountries":
            {
                String country = b.GetStartingLeg().Source.Country.Trim();
                foreach (Operator op in oplist)
                {
                    if (op.OperatorCountries.Contains(country))
                    {
                        filteredaircraftlist.AddAll(op.Aircrafts);
                    }
                }
                break;
            }

            case "aircraftpresentinstartlocation":
            {
                String location = b.GetStartingLeg().Source.City;

                if (location != null && location.Trim() != "")
                {
                    foreach (Airplane a in aircraftlist)
                    {
                        if (a.AircraftLocation.Trim().ToLower().Equals(location.ToLower()))
                        {
                            filteredaircraftlist.Add(a);
                        }
                    }
                }
                else
                {
                    location = b.GetStartingLeg().Source.AirfieldName;
                    foreach (String s in location.Split(" ".ToCharArray()))
                    {
                        if (s.Trim() != "")
                        {
                            foreach (Airplane a in aircraftlist)
                            {
                                if (a.AircraftLocation.Trim().ToLower().Equals(s.ToLower()))
                                {
                                    filteredaircraftlist.Add(a);
                                }
                            }
                        }
                    }
                }
                break;
            }

            default:
            {
                foreach (Operator op in oplist)
                {
                    filteredaircraftlist.AddAll(op.Aircrafts);
                }
                break;
            }
            }
            String    aircraftcategorymatch = settings.Get("aircraftcategorymatch");
            HybridSet categoryfilteredlist  = new HybridSet(filteredaircraftlist);

            switch (aircraftcategorymatch)
            {
            case "exactmatch":
            {
                foreach (Airplane a in filteredaircraftlist)
                {
                    if (!a.AircraftType.Equals(b.PlaneType))
                    {
                        categoryfilteredlist.Remove(a);
                    }
                }

                break;
            }

            case "parentmatch":
            {
                foreach (Airplane a in filteredaircraftlist)
                {
                    if (!a.AircraftType.ParentCategory.Equals(b.PlaneType.ParentCategory))
                    {
                        categoryfilteredlist.Remove(a);
                    }
                }
                break;
            }

            default:
            {
                break;
            }
            }
            foreach (Airplane a in categoryfilteredlist)
            {
                filterlist.Add(a.Vendor);
            }
            return(filterlist);
        }