Example #1
0
        /// <summary>
        /// Compares an <see cref="IPersistentVector">IPersistentVector</see> to another object for equality.
        /// </summary>
        /// <param name="v">The <see cref="IPersistentVector">IPersistentVector</see> to compare.</param>
        /// <param name="obj">The other object to compare.</param>
        /// <returns><value>true</value> if the specified Object is equal to the current Object;
        /// otherwise, <value>false</value>.
        /// </returns>
        static public bool doEquals(IPersistentVector v, object obj)
        {
            if (obj is IList || obj is IPersistentVector)
            {
                IList ma = obj as IList;

                if (ma.Count != v.count() || ma.GetHashCode() != v.GetHashCode())
                {
                    return(false);
                }

                for (int i = 0; i < v.count(); i++)
                {
                    if (!Util.equals(v.nth(i), ma[i]))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                if (!(obj is Sequential))
                {
                    return(false);
                }

                ISeq ms = RT.seq(obj);


                for (int i = 0; i < v.count(); i++, ms = ms.next())
                {
                    if (ms == null || !Util.equals(v.nth(i), ms.first()))
                    {
                        return(false);
                    }
                }
                if (ms != null)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Compares an <see cref="IPersistentVector">IPersistentVector</see> to another object for equality.
        /// </summary>
        /// <param name="v">The <see cref="IPersistentVector">IPersistentVector</see> to compare.</param>
        /// <param name="obj">The other object to compare.</param>
        /// <returns><value>true</value> if the specified Object is equal to the current Object; 
        /// otherwise, <value>false</value>.
        /// </returns>
        public static bool doEquals(IPersistentVector v, object obj)
        {
            if (obj is IList || obj is IPersistentVector)
            {
                IList ma = obj as IList;

                if (ma.Count != v.count() || ma.GetHashCode() != v.GetHashCode())
                    return false;

                for (int i = 0; i < v.count(); i++)
                {
                    if (!Util.equals(v.nth(i), ma[i]))
                        return false;
                }
                return true;
            }
            else
            {
                if (!(obj is Sequential))
                    return false;

                ISeq ms = RT.seq(obj);

                for (int i = 0; i < v.count(); i++, ms = ms.next())
                {
                    if (ms == null || !Util.equals(v.nth(i), ms.first()))
                        return false;
                }
                if (ms != null)
                    return false;
            }
            return true;
        }
        /// <summary>
        /// Compares an <see cref="IPersistentVector">IPersistentVector</see> to another object for equality.
        /// </summary>
        /// <param name="v">The <see cref="IPersistentVector">IPersistentVector</see> to compare.</param>
        /// <param name="obj">The other object to compare.</param>
        /// <returns><value>true</value> if the specified Object is equal to the current Object; 
        /// otherwise, <value>false</value>.
        /// </returns>
        public static bool doEquals(IPersistentVector v, object obj)
        {
            if ( obj is IList || obj is IPersistentVector )
            {
                IList ma = obj as IList;

                if (ma.Count != v.count() || ma.GetHashCode() != v.GetHashCode())
                    return false;

                for ( int i=0; i<v.count(); i++ )
                {
                    if (!Util.equals(v.nth(i), ma[i]))
                        return false;
                }
                return true;
            }

            // Example in original code of Sequential/IPersistentVector conflation.

            //if(!(obj instanceof Sequential))
            //        return false;
            //    ISeq ms = ((IPersistentCollection) obj).seq();
            //    for(int i = 0; i < v.count(); i++, ms = ms.rest())
            //        {
            //        if(ms == null || !Util.equals(v.nth(i), ms.first()))
            //            return false;
            //        }
            //    if(ms != null)
            //        return false;
            //    }

            //return true;

            ISeq ms = obj as ISeq;
            if (ms == null)
            {
                IPersistentCollection mc = obj as IPersistentCollection;
                if (mc == null)
                    return false;
                ms = mc.seq();
            }

            // Once we have the ISeq, we're ready to go.

            for (int i = 0; i < v.count(); i++, ms = ms.rest())
            {
                if (ms == null || !Util.equals(v.nth(i), ms.first()))
                    return false;
            }
            if (ms != null)
                return false;

            return true;
        }