equiv() private method

private equiv ( bool x, bool y ) : bool
x bool
y bool
return bool
Example #1
0
        /// <summary>
        /// Determine if an object is equivalent to this (handles all collections).
        /// </summary>
        /// <param name="o">The object to compare.</param>
        /// <returns><c>true</c> if the object is equivalent; <c>false</c> otherwise.</returns>
        /// <remarks>
        /// In Java Rev 1215, Added equiv.  Same as the definition in Equals, as in they took out the hashcode comparison.
        /// Different, as in Util.Equal above became Util.equals. and below it is Util.equiv.
        /// </remarks>
        public bool equiv(object obj)
        {
            //if(!(obj instanceof Map))
            //    return false;
            //Map m = (Map) obj;

            IDictionary d = obj as IDictionary;

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

            // Java had the following.
            // This works on other APersistentMap implementations, but not on
            //  arbitrary dictionaries.
            //if (d.Count != this.Count || d.GetHashCode() != this.GetHashCode())
            //    return false;

            if (d.Count != this.Count)
            {
                return(false);
            }

            for (ISeq s = seq(); s != null; s = s.next())
            {
                IMapEntry me    = (IMapEntry)s.first();
                bool      found = d.Contains(me.key());
                if (!found || !Util.equiv(me.val(), d[me.key()]))
                {
                    return(false);
                }
            }
            return(true);
        }
 /// <summary>
 /// Compare two keys for equality.
 /// </summary>
 /// <param name="k1">The first key to compare.</param>
 /// <param name="k2">The second key to compare.</param>
 /// <returns></returns>
 /// <remarks>Handles nulls properly.</remarks>
 static bool EqualKey(object k1, object k2)
 {
     if (k1 is Keyword)
     {
         return(k1 == k2);
     }
     return(Util.equiv(k1, k2));
 }
        static bool doEquiv(IPersistentVector v, object obj)
        {
            if (obj is IPersistentVector ipv)
            {
                if (ipv.count() != v.count())
                {
                    return(false);
                }

                for (int i = 0; i < v.count(); i++)
                {
                    if (!Util.equiv(v.nth(i), ipv.nth(i)))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            if (obj is IList ilist)
            {
                if (ilist.Count != v.count())   // THis test in the JVM code can't be right:  || ma.GetHashCode() != v.GetHashCode())
                {
                    return(false);
                }

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

            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.equiv(v.nth(i), ms.first()))
                {
                    return(false);
                }
            }
            if (ms != null)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
 public bool Contains(object value)
 {
     for (ISeq s = seq(); s != null; s = s.next())
     {
         if (Util.equiv(s.first(), value))
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
        public int IndexOf(object value)
        {
            ISeq s = seq();

            for (int i = 0; s != null; s = s.next(), i++)
            {
                if (Util.equiv(s.first(), value))
                {
                    return(i);
                }
            }
            return(-1);
        }
Example #6
0
        public bool equiv(object o)
        {
            if (!(o is Sequential))
            {
                return(false);
            }

            ISeq ms = RT.seq(o);

            for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next())
            {
                if (ms == null || !Util.equiv(s.first(), ms.first()))
                {
                    return(false);
                }
            }
            return(ms.next() == null);
        }
Example #7
0
        static bool doEquiv(IPersistentVector v, object obj)
        {
            if (obj is IList || obj is IPersistentVector)
            {
                ICollection ma = (ICollection)obj;
                if (ma.Count != v.count())
                {
                    return(false);
                }
                IEnumerator ima = ma.GetEnumerator();
                foreach (object ov in ((IList)v))
                {
                    ima.MoveNext();
                    if (!Util.equiv(ov, ima.Current))
                    {
                        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.equiv(v.nth(i), ms.first()))
                    {
                        return(false);
                    }
                }
                if (ms != null)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #8
0
        /// <summary>
        /// Determine if an object is equivalent to this (handles all collections).
        /// </summary>
        /// <param name="o">The object to compare.</param>
        /// <returns><c>true</c> if the object is equivalent; <c>false</c> otherwise.</returns>
        public bool equiv(object o)
        {
            if (!(o is Sequential || o is IList))
            {
                return(false);
            }

            ISeq ms = RT.seq(o);

            for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next())
            {
                if (ms == null || !Util.equiv(s.first(), ms.first()))
                {
                    return(false);
                }
            }

            return(ms == null); // hit end of sequence on both sequences
        }
Example #9
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is Sequential || obj is IList))
            {
                return(false);
            }
            ISeq ms = RT.seq(obj);

            for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next())
            {
                if (ms == null || !Util.equiv(s.first(), ms.first()))
                {
                    return(false);
                }
            }
            return(ms == null);
        }
Example #10
0
 /// <summary>
 /// Compare two keys for equality.
 /// </summary>
 /// <param name="k1">The first key to compare.</param>
 /// <param name="k2">The second key to compare.</param>
 /// <returns></returns>
 /// <remarks>Handles nulls properly.</remarks>
 static bool EqualKey(object k1, object k2)
 {
     return(Util.equiv(k1, k2));
 }