Пример #1
0
        /// <summary>
        /// Gets the set of NHibernate <see cref="Table"/> objects known to the specified configuration.
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="namespaceFilter"></param>
        /// <returns></returns>
        private static List <Table> GetTables(Configuration cfg, RelationalSchemaOptions.NamespaceFilterOption namespaceFilter)
        {
            // build set of all tables
            var tables = new HybridSet();
            var filteredClassMappings = CollectionUtils.Select(
                cfg.ClassMappings,
                classMapping => namespaceFilter.Matches(classMapping.MappedClass.Namespace));

            foreach (var pc in filteredClassMappings)
            {
                foreach (var table in pc.TableClosureIterator)
                {
                    tables.Add(table);
                }
            }

            var filteredCollectionMappings = CollectionUtils.Select(
                cfg.CollectionMappings,
                collectionMapping => namespaceFilter.Matches(collectionMapping.Owner.MappedClass.Namespace));

            foreach (var collection in filteredCollectionMappings)
            {
                tables.Add(collection.CollectionTable);
            }

            return(CollectionUtils.Sort(tables, (Table x, Table y) => x.Name.CompareTo(y.Name)));
        }
Пример #2
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 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 Contains_Call_LetterSimpleSet_Contains()
        {
            var PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.Contains("key");
            _LetterSimpleSetSubstitute.Received(1).Contains("key");
        }
Пример #4
0
        public void GetEnumerator_Call_LetterSimpleSet_GetEnumerator()
        {
            var PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.GetEnumerator();
            _LetterSimpleSetSubstitute.Received(1).GetEnumerator();
        }
Пример #5
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);
        }
Пример #6
0
        public void Clear_Call_LetterSimpleSetFactory_GetDefault()
        {
            var PolyMorphSet = new HybridSet <string>();

            _LetterSimpleSetFactory.ClearReceivedCalls();
            PolyMorphSet.Clear();
            _LetterSimpleSetFactory.Received(1).GetDefault <string>();
        }
Пример #7
0
        public void Remove_Call_LetterSimpleSet_Remove()
        {
            bool res;
            var  PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.Remove("key");
            _LetterSimpleSetSubstitute.Received(1).Remove("key", out res);
        }
Пример #8
0
        public void Add_ICollection_Call_LetterSimpleSet_Add()
        {
            bool res;
            ICollection <string> PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.Add("key");
            _LetterSimpleSetSubstitute.Received(1).Add("key", out res);
        }
Пример #9
0
        /// <summary>
        /// Returns a value for the arithmetic addition operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue(context, evalContext);
            var rhs = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(lhs) && NumberUtils.IsNumber(rhs))
            {
                return(NumberUtils.Add(lhs, rhs));
            }
            if (lhs is DateTime && (rhs is TimeSpan || rhs is string || NumberUtils.IsNumber(rhs)))
            {
                if (NumberUtils.IsNumber(rhs))
                {
                    rhs = TimeSpan.FromDays(Convert.ToDouble(rhs));
                }
                else if (rhs is string)
                {
                    rhs = TimeSpan.Parse((string)rhs);
                }

                return((DateTime)lhs + (TimeSpan)rhs);
            }
            if (lhs is String || rhs is String)
            {
                return(string.Concat(lhs, rhs));
            }
            if ((lhs is IList || lhs is ISet) && (rhs is IList || rhs is ISet))
            {
                ISet leftset  = new HybridSet(lhs as ICollection);
                ISet rightset = new HybridSet(rhs as ICollection);
                return(leftset.Union(rightset));
            }
            if (lhs is IDictionary && rhs is IDictionary)
            {
                ISet leftset  = new HybridSet(((IDictionary)lhs).Keys);
                ISet rightset = new HybridSet(((IDictionary)rhs).Keys);
                var  unionset = leftset.Union(rightset);

                IDictionary result = new Hashtable(unionset.Count);
                foreach (var key in unionset)
                {
                    if (leftset.Contains(key))
                    {
                        result.Add(key, ((IDictionary)lhs)[key]);
                    }
                    else
                    {
                        result.Add(key, ((IDictionary)rhs)[key]);
                    }
                }
                return(result);
            }
            throw new ArgumentException("Cannot add instances of '"
                                        + lhs.GetType().FullName
                                        + "' and '"
                                        + rhs.GetType().FullName
                                        + "'.");
        }
Пример #10
0
        public void UnionWith_Add_ElementsToCollection(string[] strings)
        {
            var PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.UnionWith(strings);
            bool res;

            Received.InOrder(() =>
                             strings.ForEach(s => _LetterSimpleSetSubstitute.Add(s, out res))
                             );
        }
		/// <summary>
		/// Adds all the elements in the specified collection to the set if they are not already present.
		/// </summary>
		/// <param name="c">A collection of objects to add to the set.</param>
		/// <returns><see langword="true" /> is the set changed as a result of this operation, <see langword="false" /> if not.</returns>
		public override sealed bool AddAll(ICollection c)
		{
			Set temp;
			lock (c.SyncRoot)
			{
				temp = new HybridSet(c);
			}

			lock (mSyncRoot)
			{
				return mBasisSet.AddAll(temp);
			}
		}
Пример #12
0
        /// <summary>
        /// Retains only the elements in this set that are contained in the
        /// specified collection.
        /// </summary>
        /// <param name="c">
        /// The collection that defines the set of elements to be retained.
        /// </param>
        /// <returns>
        /// <see langword="true"/> if this set changed as a result of this
        /// operation.
        /// </returns>
        public override sealed bool RetainAll(ICollection c)
        {
            Set temp;

            lock (c.SyncRoot)
            {
                temp = new HybridSet(c);
            }
            lock (_mSyncRoot)
            {
                return(_mBasisSet.RetainAll(temp));
            }
        }
        private static Property BuilPropertyFromArrays <T>(Func <ISet <int>, int[], T> perform, Func <T, T, bool> compare, Func <int[], int[], T, bool> categoryExtractor = null, string category = null)
        {
            LetterSimpleSetFactoryBuilder.Factory = new LetterSimpleSetFactory(10);
            return(Prop.ForAll <int[], int[]>((arr1, arr2) =>
            {
                var set = new HashSet <int>(arr1);
                var hybridSet = new HybridSet <int>(arr1);

                var computedSet = perform(set, arr2);
                var computedHybrid = perform(hybridSet, arr2);

                var prop = compare(computedSet, computedHybrid);
                return (categoryExtractor == null) ? prop.ToProperty() : prop.Classify(categoryExtractor(arr1, arr2, computedSet), category);
            }));
        }
Пример #14
0
 public static void OperatorResolve(BookRequest b)
 {
     if (AdminBO.GetCountry().SendRequestToOperator)
     {
         HybridSet olist = OperatorBO.GetOperatorsForRequest(b);
         foreach (Operator o in olist)
         {
             OperatorRequest or = new OperatorRequest();
             or.Operator      = o;
             or.Request       = b;
             or.TimeOfRequest = DateTime.Now;
             BookRequestDAO.MakePersistent(or);
         }
     }
 }
        public Property Constructor_ReturnsCorrectValue()
        {
            const int transition = 10;

            LetterSimpleSetFactoryBuilder.Factory = new LetterSimpleSetFactory(10);
            return(Prop.ForAll <int[]>((arr) =>
            {
                var set = new HashSet <int>(arr);
                var hybridSet = new HybridSet <int>(arr);
                return set.SetEquals(hybridSet).Classify(set.Count <= 1, "Single")
                .Classify(set.Count > 1 && set.Count <= transition, "List")
                .Classify(set.Count > transition, "Hash")
                .Classify(set.Count != arr.Length, "None trivial")
                .Classify(set.Count == arr.Length, "trivial");
            }));
        }
Пример #16
0
        /// <summary>
        /// Adds all the elements in the specified collection to the set if
        /// they are not already present.
        /// </summary>
        /// <param name="collection">A collection of objects to add to the set.</param>
        /// <returns>
        /// <see langword="true"/> is the set changed as a result of this
        /// operation.
        /// </returns>
        public override sealed bool AddAll(ICollection collection)
        {
            if (collection == null)
            {
                return(false);
            }
            Set temp;

            lock (collection.SyncRoot)
            {
                temp = new HybridSet(collection);
            }
            lock (_mSyncRoot)
            {
                return(_mBasisSet.AddAll(temp));
            }
        }
        private void CreateIndexes(Configuration config, Collection collection)
        {
            if (collection.Element is ManyToOne)
            {
                // many-to-many collection

                // collect all columns that participate in foreign keys
                HybridSet columns = new HybridSet();
                foreach (ForeignKey fk in collection.CollectionTable.ForeignKeyIterator)
                {
                    CollectionUtils.ForEach(fk.ColumnIterator,
                                            delegate(Column col)
                    {
                        columns.Add(col);
                    });
                }

                // there should always be exactly 2 "foreign key' columns in a many-many join table, AFAIK
                if (columns.Count != 2)
                {
                    throw new Exception("SNAFU");
                }

                List <Column> indexColumns = new List <Column>(new TypeSafeEnumerableWrapper <Column>(columns));

                // create two indexes, each containing both columns, going in both directions
                CreateIndex(collection.CollectionTable, indexColumns);

                indexColumns.Reverse();
                CreateIndex(collection.CollectionTable, indexColumns);
            }
            else
            {
                // this is a value collection, or a one-to-many collection

                // find the foreign-key that refers back to the owner table (assume there is only one of these - is this always true??)
                ForeignKey foreignKey = CollectionUtils.SelectFirst <ForeignKey>(collection.CollectionTable.ForeignKeyIterator,
                                                                                 delegate(ForeignKey fk) { return(Equals(fk.ReferencedTable, collection.Table)); });

                // create an index on all columns in this foreign key
                if (foreignKey != null)
                {
                    CreateIndex(collection.CollectionTable, new TypeSafeEnumerableWrapper <Column>(foreignKey.ColumnIterator));
                }
            }
        }
Пример #18
0
		private void CreateIndexes(Configuration config, Collection collection)
        {
            if(collection.Element is ManyToOne)
            {
                // many-to-many collection

                // collect all columns that participate in foreign keys
                HybridSet columns = new HybridSet();
                foreach (ForeignKey fk in collection.CollectionTable.ForeignKeyIterator)
                {
                    CollectionUtils.ForEach(fk.ColumnIterator, 
                        delegate(Column col)
                            {
                                columns.Add(col);
                            });
                }

                // there should always be exactly 2 "foreign key' columns in a many-many join table, AFAIK
                if (columns.Count != 2)
                {
                    throw new Exception("SNAFU");
                }

                List<Column> indexColumns = new List<Column>(new TypeSafeEnumerableWrapper<Column>(columns));

                // create two indexes, each containing both columns, going in both directions
                CreateIndex(collection.CollectionTable, indexColumns);

                indexColumns.Reverse();
                CreateIndex(collection.CollectionTable, indexColumns);
            }
            else
            {
                // this is a value collection, or a one-to-many collection

                // find the foreign-key that refers back to the owner table (assume there is only one of these - is this always true??)
                ForeignKey foreignKey = CollectionUtils.SelectFirst<ForeignKey>(collection.CollectionTable.ForeignKeyIterator,
                    delegate (ForeignKey fk) { return Equals(fk.ReferencedTable, collection.Table); });

                // create an index on all columns in this foreign key
                if(foreignKey != null)
                {
                    CreateIndex(collection.CollectionTable, new TypeSafeEnumerableWrapper<Column>(foreignKey.ColumnIterator));
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
        {
            ISet set = new HybridSet();

            Type elementType = null;

            if (StringUtils.HasText(this.elementTypeName))
            {
                elementType = TypeResolutionUtils.ResolveType(this.elementTypeName);
            }

            string elementName = propertyName + "[(set-element)]";

            foreach (object element in this)
            {
                object resolvedElement = resolver(objectName, definition, elementName, element);

                if (elementType != null)
                {
                    try
                    {
                        resolvedElement = TypeConversionUtils.ConvertValueIfNecessary(elementType, resolvedElement, propertyName);
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                                  String.Format(
                                      "Unable to convert managed set element '{0}' from [{1}] into [{2}] during initialization"
                                      + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?",
                                      resolvedElement, resolvedElement.GetType(), elementType, propertyName, objectName));
                    }
                }

                set.Add(resolvedElement);
            }

            return(set);
        }
Пример #20
0
        /// <summary>
        /// Gets all of the interfaces that the
        /// supplied <see cref="System.Type"/> implements.
        /// </summary>
        /// <remarks>
        /// This includes interfaces implemented by any superclasses.
        /// </remarks>
        /// <param name="type">
        /// The type to analyse for interfaces.
        /// </param>
        /// <returns>
        /// All of the interfaces that the supplied <see cref="System.Type"/> implements.
        /// </returns>
        public static Type[] GetAllInterfacesFromType(Type type)
        {
            AssertUtils.ArgumentNotNull(type, "type");
            ISet interfaces = new HybridSet();

            do
            {
                Type[] ifcs = type.GetInterfaces();
                foreach (Type ifc in ifcs)
                {
                    interfaces.Add(ifc);
                }
                type = type.BaseType;
            } while (type != null);

            if (interfaces.Count > 0)
            {
                Type[] types = new Type[interfaces.Count];
                interfaces.CopyTo(types, 0);
                return(types);
            }
            return(Type.EmptyTypes);
        }
Пример #21
0
 public void Collections_GetEnumerator_Call_LetterSimpleSet_GetEnumerator()
 {
     System.Collections.IEnumerable PolyMorphSet = new HybridSet <string>();
     PolyMorphSet.GetEnumerator();
     _LetterSimpleSetSubstitute.Received(1).GetEnumerator();
 }
Пример #22
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
        {
            ISet set = new HybridSet();
            
            Type elementType = null;
            if (StringUtils.HasText(this.elementTypeName))
            {
                elementType = TypeResolutionUtils.ResolveType(this.elementTypeName);
            }

            string elementName = propertyName + "[(set-element)]";
            foreach (object element in this)
            {
                object resolvedElement = resolver(objectName, definition, elementName, element);

                if (elementType != null)
                {
                    try
                    {
                        resolvedElement = TypeConversionUtils.ConvertValueIfNecessary(elementType, resolvedElement, propertyName);
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                            String.Format(
                                    "Unable to convert managed set element '{0}' from [{1}] into [{2}] during initialization"
                                    + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?", 
                                    resolvedElement, resolvedElement.GetType(), elementType, propertyName, objectName));
                    }
                }

                set.Add(resolvedElement);
            }

            return set;
        }
Пример #23
0
        /// <summary>
        /// Returns a value for the arithmetic addition operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue(context, evalContext);
            var rhs = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(lhs) && NumberUtils.IsNumber(rhs))
            {
                return NumberUtils.Add(lhs, rhs);
            }
            if (lhs is DateTime && (rhs is TimeSpan || rhs is string || NumberUtils.IsNumber(rhs)))
            {
                if (NumberUtils.IsNumber(rhs))
                {
                    rhs = TimeSpan.FromDays(Convert.ToDouble(rhs));
                }
                else if (rhs is string)
                {
                    rhs = TimeSpan.Parse((string) rhs);
                }

                return (DateTime) lhs + (TimeSpan) rhs;
            }
            if (lhs is String || rhs is String)
            {
                return string.Concat(lhs, rhs);
            }
            if ((lhs is IList || lhs is ISet) && (rhs is IList || rhs is ISet))
            {
                ISet leftset = new HybridSet(lhs as ICollection);
                ISet rightset = new HybridSet(rhs as ICollection);
                return leftset.Union(rightset);
            }
            if (lhs is IDictionary && rhs is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary) lhs).Keys);
                ISet rightset = new HybridSet(((IDictionary) rhs).Keys);
                var unionset = leftset.Union(rightset);

                IDictionary result = new Hashtable(unionset.Count);
                foreach(var key in unionset)
                {
                    if(leftset.Contains(key))
                    {
                        result.Add(key, ((IDictionary)lhs)[key]);
                    }
                    else
                    {
                        result.Add(key, ((IDictionary)rhs)[key]);
                    }
                }
                return result;
            }
            throw new ArgumentException("Cannot add instances of '"
                                        + lhs.GetType().FullName
                                        + "' and '"
                                        + rhs.GetType().FullName
                                        + "'.");
        }
        /// <summary>
        /// Create an array of arguments to invoke a constructor or static factory method,
        /// given the resolved constructor arguments values.
        /// </summary>
        /// <remarks>When return value is null the out parameter UnsatisfiedDependencyExceptionData will contain
        /// information for use in throwing a UnsatisfiedDependencyException by the caller.  This avoids using
        /// exceptions for flow control as in the original implementation.</remarks>
        private ArgumentsHolder CreateArgumentArray(string objectName, RootObjectDefinition rod, ConstructorArgumentValues resolvedValues, ObjectWrapper wrapper, Type[] paramTypes, MethodBase methodOrCtorInfo, bool autowiring, out UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData)
        {
            string methodType = (methodOrCtorInfo is ConstructorInfo) ? "constructor" : "factory method";
            unsatisfiedDependencyExceptionData = null;

            ArgumentsHolder args = new ArgumentsHolder(paramTypes.Length);
            ISet usedValueHolders = new HybridSet();
            IList autowiredObjectNames = new LinkedList();
            bool resolveNecessary = false;

            ParameterInfo[] argTypes = methodOrCtorInfo.GetParameters();

            for (int paramIndex = 0; paramIndex < paramTypes.Length; paramIndex++)
            {
                Type paramType = paramTypes[paramIndex];

                string parameterName = argTypes[paramIndex].Name;
                // If we couldn't find a direct match and are not supposed to autowire,
                // let's try the next generic, untyped argument value as fallback:
                // it could match after type conversion (for example, String -> int).               
                ConstructorArgumentValues.ValueHolder valueHolder = null;
                if (resolvedValues.GetNamedArgumentValue(parameterName) != null)
                {
                    valueHolder = resolvedValues.GetArgumentValue(parameterName, paramType, usedValueHolders);
                }
                else
                {
                    valueHolder = resolvedValues.GetArgumentValue(paramIndex, paramType, usedValueHolders);
                }


                if (valueHolder == null && !autowiring)
                {
                    valueHolder = resolvedValues.GetGenericArgumentValue(null, usedValueHolders);
                }
                if (valueHolder != null)
                {
                    // We found a potential match - let's give it a try.
                    // Do not consider the same value definition multiple times!
                    usedValueHolders.Add(valueHolder);
                    args.rawArguments[paramIndex] = valueHolder.Value;
                    try
                    {
                        object originalValue = valueHolder.Value;
                        object convertedValue = TypeConversionUtils.ConvertValueIfNecessary(paramType, originalValue, null);
                        args.arguments[paramIndex] = convertedValue;

                        //?
                        args.preparedArguments[paramIndex] = convertedValue;
                    }
                    catch (TypeMismatchException ex)
                    {
                        //To avoid using exceptions for flow control, this is not a cost in Java as stack trace is lazily created.
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                   "Could not convert {0} argument value [{1}] to required type [{2}] : {3}",
                                   methodType, valueHolder.Value,
                                   paramType, ex.Message);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);
                        return null;
                    }
                }
                else
                {
                    // No explicit match found: we're either supposed to autowire or
                    // have to fail creating an argument array for the given constructor.
                    if (!autowiring)
                    {
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                  "Ambiguous {0} argument types - " +
                                  "Did you specify the correct object references as {0} arguments?",
                                  methodType);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);

                        return null;
                    }
                    try
                    {
                        MethodParameter param = MethodParameter.ForMethodOrConstructor(methodOrCtorInfo, paramIndex);
                        object autowiredArgument = ResolveAutoWiredArgument(param, objectName, autowiredObjectNames);
                        args.rawArguments[paramIndex] = autowiredArgument;
                        args.arguments[paramIndex] = autowiredArgument;
                        args.preparedArguments[paramIndex] = new AutowiredArgumentMarker();
                        resolveNecessary = true;
                    }
                    catch (ObjectsException ex)
                    {
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, ex.Message);

                        return null;
                    }

                }
            }
            foreach (string autowiredObjectName in autowiredObjectNames)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Autowiring by type from object name '" + objectName +
                         "' via " + methodType + " to object named '" + autowiredObjectName + "'");
                }
            }


            return args;

        }
Пример #25
0
        /// <summary>
        /// Returns a value for the arithmetic multiplication operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue( context, evalContext );
            var rhs = GetRightValue( context, evalContext );

            if (NumberUtils.IsNumber(lhs) && NumberUtils.IsNumber(rhs))
            {
                return NumberUtils.Multiply(lhs, rhs);
            }

            if (lhs is IList ||
                lhs is ISet)
            {
                ISet leftset = new HybridSet(lhs as ICollection);
                ISet rightset;
                if (rhs is IList ||
                    rhs is ISet)
                {
                    rightset = new HybridSet(rhs as ICollection);
                }
                else if (rhs is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)rhs).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + lhs.GetType().FullName
                                                + "' and '"
                                                + rhs.GetType().FullName
                                                + "'.");
                }
                return leftset.Intersect(rightset);
            }
            if (lhs is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary)lhs).Keys);
                ISet rightset;
                if (rhs is IList || rhs is ISet)
                {
                    rightset = new HybridSet(rhs as ICollection);
                }
                else if (rhs is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)rhs).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + lhs.GetType().FullName
                                                + "' and '"
                                                + rhs.GetType().FullName
                                                + "'.");
                }
                IDictionary result = new Hashtable(rightset.Count);
                foreach (var key in leftset.Intersect(rightset))
                {
                    result.Add(key, ((IDictionary)lhs)[key]);
                }
                return result;
            }
            throw new ArgumentException("Cannot multiply instances of '"
                                        + lhs.GetType().FullName
                                        + "' and '"
                                        + rhs.GetType().FullName
                                        + "'.");
        }
Пример #26
0
        /// <summary>
        /// Returns a value for the arithmetic subtraction operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object left  = GetLeftValue(context, evalContext);
            object right = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(left) && NumberUtils.IsNumber(right))
            {
                return(NumberUtils.Subtract(left, right));
            }
            else if (NumberUtils.IsNumber(left) && NumberUtils.TryConvertTo(ref right, ref left))
            {
                return(NumberUtils.Subtract(left, right));
            }
            else if (NumberUtils.IsNumber(right) && NumberUtils.TryConvertTo(ref left, ref right))
            {
                return(NumberUtils.Subtract(left, right));
            }
            else if (left is DateTime && (right is TimeSpan || right is string || NumberUtils.IsNumber(right)))
            {
                if (NumberUtils.IsNumber(right))
                {
                    right = TimeSpan.FromDays(Convert.ToDouble(right));
                }
                else if (right is string)
                {
                    right = TimeSpan.Parse((string)right);
                }
                return((DateTime)left - (TimeSpan)right);
            }
            else if (left is DateTime && right is DateTime)
            {
                return((DateTime)left - (DateTime)right);
            }
            else if (left is IList || left is ISet)
            {
                ISet leftset = new HybridSet(left as ICollection);
                ISet rightset;
                if (right is IList || right is ISet)
                {
                    rightset = new HybridSet(right as ICollection);
                }
                else if (right is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)right).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + left.GetType().FullName
                                                + "' and '"
                                                + right.GetType().FullName
                                                + "'.");
                }
                return(leftset.Minus(rightset));
            }
            else if (left is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary)left).Keys);
                ISet rightset;
                if (right is IList || right is ISet)
                {
                    rightset = new HybridSet(right as ICollection);
                }
                else if (right is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)right).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + left.GetType().FullName
                                                + "' and '"
                                                + right.GetType().FullName
                                                + "'.");
                }
                IDictionary result = new Hashtable(rightset.Count);
                foreach (object key in leftset.Minus(rightset))
                {
                    result.Add(key, ((IDictionary)left)[key]);
                }
                return(result);
            }
            else
            {
                throw new ArgumentException("Cannot subtract instances of '"
                                            + left.GetType().FullName
                                            + "' and '"
                                            + right.GetType().FullName
                                            + "'.");
            }
        }
Пример #27
0
 public void Count_Call_LetterSimpleSet_Count()
 {
     var PolyMorphSet = new HybridSet <string>();
     var count        = PolyMorphSet.Count;
     var res          = _LetterSimpleSetSubstitute.Received(1).Count;
 }
Пример #28
0
		/// <summary>
		/// Returns <c>true</c> if the set contains all the elements in the specified collection.
		/// </summary>
		/// <param name="c">A collection of objects.</param>
		/// <returns><c>true</c> if the set contains all the elements in the specified collection, <c>false</c> otherwise.</returns>
		public sealed override bool ContainsAll(ICollection c)
		{
			Set temp;
			lock(c.SyncRoot)
			{
				temp = new HybridSet(c);
			}
			lock(mSyncRoot)
			{
				return mBasisSet.ContainsAll(temp);
			}
		}
Пример #29
0
		/// <summary>
		/// Adds all the elements in the specified collection to the set if
		/// they are not already present.
		/// </summary>
		/// <param name="collection">A collection of objects to add to the set.</param>
		/// <returns>
		/// <see langword="true"/> is the set changed as a result of this
		/// operation.
		/// </returns>
		public override sealed bool AddAll(ICollection collection)
		{
			if(collection == null) 
			{
				return false;
			}
			Set temp;
			lock (collection.SyncRoot)
			{
				temp = new HybridSet(collection);
			}
			lock (_mSyncRoot)
			{
				return _mBasisSet.AddAll(temp);
			}
		}
Пример #30
0
        public void IsReadOnly_IsFalse()
        {
            var PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.IsReadOnly.Should().BeFalse();
        }
Пример #31
0
        public void Constructor_WithoutParameters_Call_LetterSimpleSetFactory_GetDefault_WithoutParameters()
        {
            var PolyMorphSet = new HybridSet <string>();

            _LetterSimpleSetFactory.Received(1).GetDefault <string>();
        }
Пример #32
0
        public void Constructor_WithoneElement_Call_LetterSimpleSetFactory_GetDefault_WithoutoneElement()
        {
            var PolyMorphSet = new HybridSet <string>("abcd");

            _LetterSimpleSetFactory.Received(1).GetDefault("abcd");
        }
        /// <summary>
        /// Determines the <see cref="System.Type"/> of the object defined
        /// by the supplied object <paramref name="definition"/>. 
        /// </summary>
        /// <param name="objectName">
        /// The name associated with the supplied object <paramref name="definition"/>.
        /// </param>
        /// <param name="definition">
        /// The <see cref="Spring.Objects.Factory.Support.RootObjectDefinition"/>
        /// that the <see cref="System.Type"/> is to be determined for. 
        /// </param>
        /// <returns>
        /// The <see cref="System.Type"/> of the object defined by the supplied
        /// object <paramref name="definition"/>; or <see lang="null"/> if the
        /// <see cref="System.Type"/> cannot be determined.
        /// </returns>
        protected override Type GetTypeForFactoryMethod(string objectName, RootObjectDefinition definition)
        {
            Type factoryType = null;
            bool isStatic = true;

            if (StringUtils.HasText(definition.FactoryObjectName))
            {
                // check declared factory method return type on factory type...
                factoryType = GetType(definition.FactoryObjectName);
                isStatic = false;
            }
            else
            {
                factoryType = ResolveObjectType(definition, objectName);
            }
            if (factoryType == null)
            {
                return null;
            }

            // If all factory methods have the same return type, return that type.
            // Can't clearly figure out exact method due to type converting / autowiring!
            int minNrOfArgs = definition.ConstructorArgumentValues.GenericArgumentValues.Count;
            MethodInfo[] candidates = factoryType.GetMethods();
            ISet returnTypes = new HybridSet();
            foreach (MethodInfo factoryMethod in candidates)
            {
#if NET_2_0
                GenericArgumentsHolder genericArgsInfo = new GenericArgumentsHolder(definition.FactoryMethodName);
                if (factoryMethod.IsStatic == isStatic && factoryMethod.Name.Equals(genericArgsInfo.GenericMethodName)
                    && ReflectionUtils.GetParameterTypes(factoryMethod).Length >= minNrOfArgs
                    && factoryMethod.GetGenericArguments().Length == genericArgsInfo.GetGenericArguments().Length)
                {
                    if (genericArgsInfo.ContainsGenericArguments)
                    {
                        string[] unresolvedGenericArgs = genericArgsInfo.GetGenericArguments();
                        Type[] genericArgs = new Type[unresolvedGenericArgs.Length];
                        for (int j = 0; j < unresolvedGenericArgs.Length; j++)
                        {
                            genericArgs[j] = TypeResolutionUtils.ResolveType(unresolvedGenericArgs[j]);
                        }
                        returnTypes.Add(factoryMethod.MakeGenericMethod(genericArgs).ReturnType);
                    }
                    else
                    {
                        returnTypes.Add(factoryMethod.ReturnType);
                    }
                }
#else
                if (factoryMethod.IsStatic == isStatic && factoryMethod.Name.Equals(definition.FactoryMethodName)
                    && ReflectionUtils.GetParameterTypes(factoryMethod).Length >= minNrOfArgs)
                {
                    returnTypes.Add(factoryMethod.ReturnType);
                }
#endif
            }
            if (returnTypes.Count == 1)
            {
                // clear return type found: all factory methods return same type...
                return (Type)ObjectUtils.EnumerateFirstElement(returnTypes);
            }

            // ambiguous return types found: return null to indicate "not determinable"...
            return null;
        }
Пример #34
0
 public void Setup()
 {
     hashSet   = new HashSet <MethodOverrides>();
     hybridSet = new HybridSet();
     hashedSet = new HashedSet();
 }
Пример #35
0
 public override void SetUp()
 {
     Set          = new HybridSet();
     SetForSetOps = new HybridSet();
 }
        /// <summary>
        /// Create an array of arguments to invoke a constructor or static factory method,
        /// given the resolved constructor arguments values.
        /// </summary>
        /// <remarks>When return value is null the out parameter UnsatisfiedDependencyExceptionData will contain
        /// information for use in throwing a UnsatisfiedDependencyException by the caller.  This avoids using
        /// exceptions for flow control as in the original implementation.</remarks>
        private ArgumentsHolder CreateArgumentArray(string objectName, RootObjectDefinition rod, ConstructorArgumentValues resolvedValues, ObjectWrapper wrapper, Type[] paramTypes, MethodBase methodOrCtorInfo, bool autowiring, out UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData)
        {
            string methodType = (methodOrCtorInfo is ConstructorInfo) ? "constructor" : "factory method";

            unsatisfiedDependencyExceptionData = null;

            ArgumentsHolder args                 = new ArgumentsHolder(paramTypes.Length);
            ISet            usedValueHolders     = new HybridSet();
            IList           autowiredObjectNames = new LinkedList();
            bool            resolveNecessary     = false;

            ParameterInfo[] argTypes = methodOrCtorInfo.GetParameters();

            for (int paramIndex = 0; paramIndex < paramTypes.Length; paramIndex++)
            {
                Type paramType = paramTypes[paramIndex];

                string parameterName = argTypes[paramIndex].Name;
                // If we couldn't find a direct match and are not supposed to autowire,
                // let's try the next generic, untyped argument value as fallback:
                // it could match after type conversion (for example, String -> int).
                ConstructorArgumentValues.ValueHolder valueHolder = null;
                if (resolvedValues.GetNamedArgumentValue(parameterName) != null)
                {
                    valueHolder = resolvedValues.GetArgumentValue(parameterName, paramType, usedValueHolders);
                }
                else
                {
                    valueHolder = resolvedValues.GetArgumentValue(paramIndex, paramType, usedValueHolders);
                }


                if (valueHolder == null && !autowiring)
                {
                    valueHolder = resolvedValues.GetGenericArgumentValue(null, usedValueHolders);
                }
                if (valueHolder != null)
                {
                    // We found a potential match - let's give it a try.
                    // Do not consider the same value definition multiple times!
                    usedValueHolders.Add(valueHolder);
                    args.rawArguments[paramIndex] = valueHolder.Value;
                    try
                    {
                        object originalValue  = valueHolder.Value;
                        object convertedValue = TypeConversionUtils.ConvertValueIfNecessary(paramType, originalValue, null);
                        args.arguments[paramIndex] = convertedValue;

                        //?
                        args.preparedArguments[paramIndex] = convertedValue;
                    }
                    catch (TypeMismatchException ex)
                    {
                        //To avoid using exceptions for flow control, this is not a cost in Java as stack trace is lazily created.
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                                            "Could not convert {0} argument value [{1}] to required type [{2}] : {3}",
                                                            methodType, valueHolder.Value,
                                                            paramType, ex.Message);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);
                        return(null);
                    }
                }
                else
                {
                    // No explicit match found: we're either supposed to autowire or
                    // have to fail creating an argument array for the given constructor.
                    if (!autowiring)
                    {
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                                            "Ambiguous {0} argument types - " +
                                                            "Did you specify the correct object references as {0} arguments?",
                                                            methodType);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);

                        return(null);
                    }
                    try
                    {
                        MethodParameter param             = MethodParameter.ForMethodOrConstructor(methodOrCtorInfo, paramIndex);
                        object          autowiredArgument = ResolveAutoWiredArgument(param, objectName, autowiredObjectNames);
                        args.rawArguments[paramIndex]      = autowiredArgument;
                        args.arguments[paramIndex]         = autowiredArgument;
                        args.preparedArguments[paramIndex] = new AutowiredArgumentMarker();
                        resolveNecessary = true;
                    }
                    catch (ObjectsException ex)
                    {
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, ex.Message);

                        return(null);
                    }
                }
            }
            foreach (string autowiredObjectName in autowiredObjectNames)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Autowiring by type from object name '" + objectName +
                              "' via " + methodType + " to object named '" + autowiredObjectName + "'");
                }
            }


            return(args);
        }
Пример #37
0
        /// <summary>
        /// Returns a value for the arithmetic multiplication operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue(context, evalContext);
            var rhs = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(lhs) && NumberUtils.IsNumber(rhs))
            {
                return(NumberUtils.Multiply(lhs, rhs));
            }

            if (lhs is IList ||
                lhs is ISet)
            {
                ISet leftset = new HybridSet(lhs as ICollection);
                ISet rightset;
                if (rhs is IList ||
                    rhs is ISet)
                {
                    rightset = new HybridSet(rhs as ICollection);
                }
                else if (rhs is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)rhs).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + lhs.GetType().FullName
                                                + "' and '"
                                                + rhs.GetType().FullName
                                                + "'.");
                }
                return(leftset.Intersect(rightset));
            }
            if (lhs is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary)lhs).Keys);
                ISet rightset;
                if (rhs is IList || rhs is ISet)
                {
                    rightset = new HybridSet(rhs as ICollection);
                }
                else if (rhs is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)rhs).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + lhs.GetType().FullName
                                                + "' and '"
                                                + rhs.GetType().FullName
                                                + "'.");
                }
                IDictionary result = new Hashtable(rightset.Count);
                foreach (var key in leftset.Intersect(rightset))
                {
                    result.Add(key, ((IDictionary)lhs)[key]);
                }
                return(result);
            }
            throw new ArgumentException("Cannot multiply instances of '"
                                        + lhs.GetType().FullName
                                        + "' and '"
                                        + rhs.GetType().FullName
                                        + "'.");
        }
Пример #38
0
        /// <summary>
        /// Gets all of the interfaces that the 
        /// supplied <see cref="System.Type"/> implements.
        /// </summary>
        /// <remarks>
        /// This includes interfaces implemented by any superclasses.
        /// </remarks>
        /// <param name="type">
        /// The type to analyse for interfaces.
        /// </param>
        /// <returns>
        /// All of the interfaces that the supplied <see cref="System.Type"/> implements.
        /// </returns>
        public static Type[] GetAllInterfacesFromType(Type type)
        {
            AssertUtils.ArgumentNotNull(type, "type");
            ISet interfaces = new HybridSet();
            do
            {
                Type[] ifcs = type.GetInterfaces();
                foreach (Type ifc in ifcs)
                {
                    interfaces.Add(ifc);
                }
                type = type.BaseType;
            } while (type != null);

            if (interfaces.Count > 0)
            {
                Type[] types = new Type[interfaces.Count];
                interfaces.CopyTo(types, 0);
                return types;
            }
            return Type.EmptyTypes;
        }
Пример #39
0
        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);
        }
Пример #40
0
        /// <summary>
        /// Returns a value for the arithmetic subtraction operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object left = GetLeftValue( context, evalContext );
            object right = GetRightValue( context, evalContext );

            if (NumberUtils.IsNumber(left) && NumberUtils.IsNumber(right))
            {
                return NumberUtils.Subtract(left, right);
            }
            else if (left is DateTime && (right is TimeSpan || right is string || NumberUtils.IsNumber(right)))
            {
                if (NumberUtils.IsNumber(right))
                {
                    right = TimeSpan.FromDays(Convert.ToDouble(right));
                }
                else if (right is string)
                {
                    right = TimeSpan.Parse((string) right);
                }
                return (DateTime) left - (TimeSpan) right;
            }
            else if (left is DateTime && right is DateTime)
            {
                return (DateTime) left - (DateTime) right;
            }
            else if (left is IList || left is ISet)
            {
                ISet leftset = new HybridSet(left as ICollection);
                ISet rightset;
                if(right is IList || right is ISet)
                {
                    rightset = new HybridSet(right as ICollection);
                }
                else if (right is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary) right).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                    + left.GetType().FullName
                    + "' and '"
                    + right.GetType().FullName
                    + "'.");
                }
                return leftset.Minus(rightset);
            }
            else if (left is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary) left).Keys);
                ISet rightset;
                if (right is IList || right is ISet)
                {
                    rightset = new HybridSet(right as ICollection);
                }
                else if (right is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary) right).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                    + left.GetType().FullName
                    + "' and '"
                    + right.GetType().FullName
                    + "'.");
                }
                IDictionary result = new Hashtable(rightset.Count);
                foreach(object key in leftset.Minus(rightset))
                {
                    result.Add(key, ((IDictionary)left)[key]);
                }
                return result;
            }
            else
            {
                throw new ArgumentException("Cannot subtract instances of '"
                    + left.GetType().FullName
                    + "' and '"
                    + right.GetType().FullName
                    + "'.");
            }
        }
Пример #41
0
        /// <summary>
        /// Retains only the elements in this set that are contained in the specified collection.
        /// </summary>
        /// <param name="c">Collection that defines the set of elements to be retained.</param>
        /// <returns><c>true</c> if this set changed as a result of this operation.</returns>
        public override bool RetainAll(ICollection c)
        {
            //Put data from C into a set so we can use the Contains() method.
            Set cSet = new HybridSet(c);

            //We are going to build a set of elements to remove.
            Set removeSet = new HybridSet();

            foreach(object o in this)
            {
                //If C does not contain O, then we need to remove O from our
                //set.  We can't do this while iterating through our set, so
                //we put it into RemoveSet for later.
                if(!cSet.Contains(o))
                    removeSet.Add(o);
            }

            return this.RemoveAll(removeSet);
        }
Пример #42
0
        public void Constructor_WithEnumerable_Call_LetterSimpleSetFactory_GetDefault_WithoutEnumerable()
        {
            var PolyMorphSet = new HybridSet <string>(_Enumerable);

            _LetterSimpleSetFactory.Received(1).GetDefault(_Enumerable);
        }
Пример #43
0
        /// <summary>
        /// Returns a value for the arithmetic multiplication operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object left  = GetLeftValue(context, evalContext);
            object right = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(left) && NumberUtils.IsNumber(right))
            {
                return(NumberUtils.Multiply(left, right));
            }
            else if (NumberUtils.IsNumber(left) && NumberUtils.TryConvertTo(ref right, ref left))
            {
                return(NumberUtils.Multiply(left, right));
            }
            else if (NumberUtils.IsNumber(right) && NumberUtils.TryConvertTo(ref left, ref right))
            {
                return(NumberUtils.Multiply(left, right));
            }
            else if (left is IList || left is ISet)
            {
                ISet leftset = new HybridSet(left as ICollection);
                ISet rightset;
                if (right is IList || right is ISet)
                {
                    rightset = new HybridSet(right as ICollection);
                }
                else if (right is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)right).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + left.GetType().FullName
                                                + "' and '"
                                                + right.GetType().FullName
                                                + "'.");
                }
                return(leftset.Intersect(rightset));
            }
            else if (left is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary)left).Keys);
                ISet rightset;
                if (right is IList || right is ISet)
                {
                    rightset = new HybridSet(right as ICollection);
                }
                else if (right is IDictionary)
                {
                    rightset = new HybridSet(((IDictionary)right).Keys);
                }
                else
                {
                    throw new ArgumentException("Cannot subtract instances of '"
                                                + left.GetType().FullName
                                                + "' and '"
                                                + right.GetType().FullName
                                                + "'.");
                }
                IDictionary result = new Hashtable(rightset.Count);
                foreach (object key in leftset.Intersect(rightset))
                {
                    result.Add(key, ((IDictionary)left)[key]);
                }
                return(result);
            }
            else
            {
                throw new ArgumentException("Cannot multiply instances of '"
                                            + left.GetType().FullName
                                            + "' and '"
                                            + right.GetType().FullName
                                            + "'.");
            }
        }
Пример #44
0
		/// <summary>
		/// Retains only the elements in this set that are contained in the
		/// specified collection.
		/// </summary>
		/// <param name="c">
		/// The collection that defines the set of elements to be retained.
		/// </param>
		/// <returns>
		/// <see langword="true"/> if this set changed as a result of this
		/// operation.
		/// </returns>
		public override sealed bool RetainAll(ICollection c)
		{
			Set temp;
			lock (c.SyncRoot)
			{
				temp = new HybridSet(c);
			}
			lock (_mSyncRoot)
			{
				return _mBasisSet.RetainAll(temp);
			}
		}