public static bool setEquals(IPersistentSet s1, object obj)
        {
            // I really can't do what the Java version does.
            // It casts to a Set.  No such thing here.  We'll use IPersistentSet instead.


            if (s1 == obj)
            {
                return(true);
            }

#if CLR2
            // No System.Collections.Generic.ISet<T>
#else
            ISet <Object> is2 = obj as ISet <Object>;
            if (is2 != null)
            {
                if (is2.Count != s1.count())
                {
                    return(false);
                }
                foreach (Object elt in is2)
                {
                    if (!s1.contains(elt))
                    {
                        return(false);
                    }
                }
                return(true);
            }
#endif

            IPersistentSet s2 = obj as IPersistentSet;
            if (s2 == null)
            {
                return(false);
            }

            if (s2.count() != s1.count())
            {
                return(false);
            }

            for (ISeq seq = s2.seq(); seq != null; seq = seq.next())
            {
                if (!s1.contains(seq.first()))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        public void CreateOnEmptyListReturnsEmptySet()
        {
            ArrayList      a = new ArrayList();
            IPersistentSet m = PersistentHashSet.createWithCheck(a);

            Expect(m.count(), EqualTo(0));
        }
Example #3
0
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj">The Object to compare with the current Object.</param>
        /// <returns><value>true</value> if the specified Object is equal to the current Object;
        /// otherwise, <value>false</value>.
        /// </returns>
        public override bool Equals(object obj)
        {
            // I really can't do what the Java version does.
            // It casts to a Set.  No such thing here.  We'll use IPersistentSet instead.

            IPersistentSet s = obj as IPersistentSet;

            if (s == null)
            {
                return(false);
            }

            if (s.count() != count() || s.GetHashCode() != GetHashCode())
            {
                return(false);
            }

            for (ISeq seq = s.seq(); seq != null; seq = seq.next())
            {
                if (!contains(seq.first()))
                {
                    return(false);
                }
            }

            return(true);
        }
        public static bool setEquals(IPersistentSet s1, object obj)
        {
            // I really can't do what the Java version does.
            // It casts to a Set.  No such thing here.  We'll use IPersistentSet instead.


            if (s1 == obj)
            {
                return(true);
            }

            if (obj is ISet <Object> is2)
            {
                if (is2.Count != s1.count())
                {
                    return(false);
                }
                foreach (Object elt in is2)
                {
                    if (!s1.contains(elt))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            if (!(obj is IPersistentSet s2))
            {
                return(false);
            }

            if (s2.count() != s1.count())
            {
                return(false);
            }

            for (ISeq seq = s2.seq(); seq != null; seq = seq.next())
            {
                if (!s1.contains(seq.first()))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
        public void CreateOnEmptyISeqReturnsEmptySet()
        {
            object[]       items = new object[] { };
            ArrayList      a     = new ArrayList(items);
            ISeq           s     = PersistentList.create(a).seq();
            IPersistentSet m     = PersistentHashSet.create(s);

            Expect(m.count(), EqualTo(0));
        }
Example #6
0
        public void CreateOnISeqReturnsSet()
        {
            object[]       items = new object[] { 1, "a" };
            ArrayList      a     = new ArrayList(items);
            ISeq           s     = PersistentList.create(a).seq();
            IPersistentSet m     = PersistentHashSet.create(s);

            Expect(m.count(), EqualTo(2));
            Expect(m.contains(1));
            Expect(m.contains("a"));
            Expect(m.contains(3), False);
        }
Example #7
0
        public void CreateOnListReturnsSet()
        {
            object[]  items = new object[] { 1, "a" };
            ArrayList a     = new ArrayList(items);

            IPersistentSet m = PersistentHashSet.createWithCheck(a);

            Expect(m.count(), EqualTo(2));
            Expect(m.contains(1));
            Expect(m.contains("a"));
            Expect(m.contains(3), False);
        }
Example #8
0
        private static List <CustomAttributeBuilder> CreateCustomAttributeBuilders(IMapEntry me)
        {
            Type           t     = (Type)me.key();
            IPersistentSet inits = (IPersistentSet)me.val();

            List <CustomAttributeBuilder> builders = new List <CustomAttributeBuilder>(inits.count());

            for (ISeq s = RT.seq(inits); s != null; s = s.next())
            {
                IPersistentMap init = (IPersistentMap)s.first();
                builders.Add(CreateCustomAttributeBuilder(t, init));
            }

            return(builders);
        }
Example #9
0
        private static Expression GenerateSetExpr(IPersistentSet set)
        {
            Expression[] args = new Expression[set.count()];
            int i = 0;
            for (ISeq s = RT.seq(set); s != null; s = s.next(), i++)
                args[i] = MaybeBox(Generate(s.first()));

            Expression argArray = Expression.NewArrayInit(typeof(object), args);

            Expression ret = Expression.Call(Method_CGen_MakeSet, argArray);
            ret = OptionallyGenerateMetaInit(set, ret);

            return ret;
        }