예제 #1
0
        public void IntersectWith(IEnumerable <T> other)
        {
            var wrap = other as IJavaCollectionWrapper <T>;

            if (wrap != null)
            {
                collection.RetainAll((Java.Util.ICollection <object>)wrap.Collection);
            }
            else
            {
                var remove = new Java.Util.HashSet <T>(collection);
                foreach (var e in other)
                {
                    remove.Remove(e);
                }
                collection.RemoveAll((Java.Util.ICollection <object>)remove);
            }
        }
예제 #2
0
        private static InheritanceInfo CreateInheritanceInfo(Type type)
        {
            LinkedHashSet <Type> intf = new LinkedHashSet <Type>();

            Java.Util.HashSet <Type> baseTypes = new Java.Util.HashSet <Type>();
            baseTypes.Add(typeof(object));

            // Note that JavaGetInterfaces will only return interfaces declared by the current type,
            // while .NET returns a flattened map of all interfaces.
            // http://stackoverflow.com/questions/6616055/get-all-derived-interfaces-of-a-class
            // http://stackoverflow.com/questions/9793242/type-getinterfaces-for-declared-interfaces-only

            Java.Util.IQueue <Type> toVisit = new Java.Util.LinkedList <Type>();
            toVisit.Add(type);

            while (toVisit.Peek() != null)
            {
                var currentType = toVisit.Poll();

                var gti = GenericInstanceFactory.GetGenericTypeInfo(currentType);

                bool isInterface = gti != null?gti.TypeDefinition.JavaIsInterface() : currentType.JavaIsInterface();

                if (!isInterface)
                {
                    var baseType = currentType.BaseType;
                    if (baseType != null && baseType != typeof(object))
                    {
                        toVisit.Add(baseType);
                        baseTypes.Add(baseType);
                    }
                }

                if (gti == null)
                {
                    AddInterfaces(currentType.JavaGetInterfaces(), intf, toVisit);
                    continue;
                }

                var typeDef    = gti.TypeDefinition;
                var interfaces = typeDef.JavaGetInterfaces();

                var genericInstanceClass = typeDef.GetAnnotation <ITypeReflectionInfo>(typeof(ITypeReflectionInfo));
                if (genericInstanceClass == null)
                {
                    AddInterfaces(interfaces, intf, toVisit);
                    continue;
                }

                var def = genericInstanceClass.GenericDefinitions().Select(DefinitionParser.Parse);

                if (def.Length == 0)
                {
                    AddInterfaces(interfaces, intf, toVisit);
                    continue;
                }

                for (int i = 0; i < interfaces.Length; ++i)
                {
                    interfaces[i] = ToMatchedGenericInstanceType(interfaces[i], currentType, def);
                }

                AddInterfaces(interfaces, intf, toVisit);
            }

            return(new InheritanceInfo
            {
                Interfaces = new JavaCollectionWrapper <Type>(intf).ToArray(),
                InterfacesSet = new Java.Util.HashSet <Type>(intf),
                BaseTypes = baseTypes
            });
        }
예제 #3
0
        private static InheritanceInfo CreateInheritanceInfo(Type type)
        {
            LinkedHashSet<Type> intf = new LinkedHashSet<Type>();
            Java.Util.HashSet<Type> baseTypes = new Java.Util.HashSet<Type>();
            baseTypes.Add(typeof(object));

            // Note that JavaGetInterfaces will only return interfaces declared by the current type,
            // while .NET returns a flattened map of all interfaces.
            // http://stackoverflow.com/questions/6616055/get-all-derived-interfaces-of-a-class
            // http://stackoverflow.com/questions/9793242/type-getinterfaces-for-declared-interfaces-only

            Java.Util.IQueue<Type> toVisit = new Java.Util.LinkedList<Type>();
            toVisit.Add(type);

            while (toVisit.Peek() != null)
            {
                var currentType = toVisit.Poll();

                var gti = GenericInstanceFactory.GetGenericTypeInfo(currentType);

                bool isInterface = gti != null ? gti.TypeDefinition.JavaIsInterface() : currentType.JavaIsInterface();

                if (!isInterface)
                {
                    var baseType = currentType.BaseType;
                    if (baseType != null && baseType != typeof(object))
                    {
                        toVisit.Add(baseType);
                        baseTypes.Add(baseType);
                    }
                }

                if (gti == null)
                {
                    AddInterfaces(currentType.JavaGetInterfaces(), intf, toVisit);
                    continue;
                }

                var typeDef = gti.TypeDefinition;
                var interfaces = typeDef.JavaGetInterfaces();

                var genericInstanceClass = typeDef.GetAnnotation<ITypeReflectionInfo>(typeof(ITypeReflectionInfo));
                if (genericInstanceClass == null)
                {
                    AddInterfaces(interfaces, intf, toVisit);
                    continue;
                }

                var def = genericInstanceClass.GenericDefinitions();

                if (def.Length == 0)
                {
                    AddInterfaces(interfaces, intf, toVisit);
                    continue;
                }

                for (int i = 0; i < interfaces.Length; ++i)
                    interfaces[i] = ToMatchedGenericInstanceType(interfaces[i], currentType, def);

                AddInterfaces(interfaces, intf, toVisit);
            }

            return new InheritanceInfo
            {
                Interfaces = new JavaCollectionWrapper<Type>(intf).ToArray(),
                InterfacesSet = new Java.Util.HashSet<Type>(intf),
                BaseTypes = baseTypes
            };
        }