Beispiel #1
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 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);
        }