Implemented Equals() and GetHashCode() for IExpression classes.
authorBoris Kirzner <borisk@mono-cvs.ximian.com>
Thu, 22 Sep 2005 11:21:15 +0000 (11:21 -0000)
committerBoris Kirzner <borisk@mono-cvs.ximian.com>
Thu, 22 Sep 2005 11:21:15 +0000 (11:21 -0000)
svn path=/trunk/mcs/; revision=50464

mcs/class/System.Data/Mono.Data.SqlExpressions/Aggregation.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/ChangeLog
mcs/class/System.Data/Mono.Data.SqlExpressions/ColumnReference.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/Expressions.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/Functions.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/In.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/Like.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/Literal.cs
mcs/class/System.Data/Mono.Data.SqlExpressions/StringFunctions.cs

index ab6d0028d91b1e64ea044a6b3c50aaeb422aae5d..9738ef6f7c83dc74fda6fb31acf7e0c01f4534b8 100644 (file)
@@ -55,6 +55,42 @@ namespace Mono.Data.SqlExpressions {
                        this.function = function;
                        this.result = null;
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is Aggregation))
+                               return false;
+
+                       Aggregation other = (Aggregation) obj;
+                       if (!other.function.Equals( function))
+                               return false;
+
+                       if (!other.column.Equals (column))
+                               return false;           
+
+                       if (other.rows.Length != rows.Length)
+                               return false;
+
+                       for (int i=0; i < rows.Length; i++)
+                               if (other.rows [i] != rows [i])
+                                       return false;
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       int hashCode = base.GetHashCode ();
+                       hashCode ^= function.GetHashCode ();
+                       hashCode ^= column.GetHashCode ();
+                       for (int i=0; i < rows.Length; i++)
+                               hashCode ^= rows [i].GetHashCode ();
+                       
+                       return hashCode;
+               }
        
                public override object Eval (DataRow row)
                {
index 9bd1eee774c7653ab7e1134dc47e1c84df78b068..a8833ac4d50ed7832f65cb2276e70ec1eda8e232 100644 (file)
@@ -1,3 +1,9 @@
+2005-09-19 Boris Kirzner <borisk@mainsoft.com>
+       * ColumnReference.cs, Expressions.cs, Like.cs, Aggregation.cs, Literal.cs,
+       StringFunctions.cs, In.cs, Functions.cs : implemented Equals() 
+       and GetHashCode() methods for all Mono.Data.SqlExpressions classes,enabling
+       comparison of the filter expressions.
+
 2005-08-02  Sureshkumar T  <tsureshkumar@novell.com>
 
        * Tokenizer.cs: ReadString (): added an overload where the
index 488793285ee4fa434dd2f6ca79905842a6d98cac..0cb357c0b4f4d42f40bc3763d6adcae9539e8727 100644 (file)
@@ -54,6 +54,36 @@ namespace Mono.Data.SqlExpressions {
                        this.columnName = columnName;
                }
 
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is ColumnReference))
+                               return false;
+
+                       ColumnReference other = (ColumnReference) obj;
+                       if (other.refTable != refTable)
+                               return false;
+
+                       if (other.columnName != columnName)
+                               return false;           
+
+                       if (other.relationName != relationName)
+                               return false;
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       int hashCode = base.GetHashCode ();
+                       hashCode ^= refTable.GetHashCode ();
+                       hashCode ^= columnName.GetHashCode ();
+                       hashCode ^= relationName.GetHashCode ();
+                       return hashCode;
+               }
+
                public ReferencedTable ReferencedTable {
                        get { return refTable; }
                }
index 5ef521505e50135c456d75c7475981a0c7c3aef9..2ca2f428feac18a7196c202bea84bc0e9556d027 100644 (file)
@@ -50,11 +50,44 @@ namespace Mono.Data.SqlExpressions {
                {
                        return (bool) Eval (row);
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (obj == null || !(obj is BaseExpression))
+                               return false;
+                       
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return 0;
+               }
        }
 
        // abstract base classes
        internal abstract class UnaryExpression : BaseExpression {
                protected IExpression expr;
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is UnaryExpression))
+                               return false;
+
+                       UnaryExpression other = (UnaryExpression) obj;
+                       if (!other.expr.Equals (expr))
+                               return false;
+                       
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return base.GetHashCode () ^ expr.GetHashCode ();
+               }
        
                public UnaryExpression (IExpression e)
                {
@@ -68,6 +101,29 @@ namespace Mono.Data.SqlExpressions {
        
        internal abstract class BinaryExpression : BaseExpression {
                protected IExpression expr1, expr2;
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is BinaryExpression))
+                               return false;
+
+                       BinaryExpression other = (BinaryExpression) obj;
+                       if (!other.expr1.Equals (expr1) || !other.expr2.Equals (expr2))
+                               return false;
+                       
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       int hashCode = base.GetHashCode ();
+                       hashCode ^= expr1.GetHashCode ();
+                       hashCode ^= expr2.GetHashCode ();
+                       return hashCode;
+               }
        
                protected BinaryExpression (IExpression e1, IExpression e2)
                {
@@ -88,6 +144,26 @@ namespace Mono.Data.SqlExpressions {
        
        internal abstract class BinaryOpExpression : BinaryExpression {
                protected Operation op;
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is BinaryOpExpression))
+                               return false;
+
+                       BinaryOpExpression other = (BinaryOpExpression) obj;
+                       if (other.op != op)
+                               return false;
+                       
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return base.GetHashCode () ^ op.GetHashCode ();
+               }
        
                protected BinaryOpExpression (Operation op, IExpression e1, IExpression e2) : base (e1, e2)
                {
index 27cd1e9fead2bf6ac6378ea98a041782dc00becc..63b21155b6de5679a52b8705c674a4ba089a8aef 100644 (file)
@@ -42,6 +42,32 @@ namespace Mono.Data.SqlExpressions {
                        this.trueExpr = trueExpr;
                        this.falseExpr = falseExpr;
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is IifFunction))
+                               return false;
+
+                       IifFunction other = (IifFunction) obj;
+                       if (!other.falseExpr.Equals (falseExpr))
+                               return false;
+
+                       if (!other.trueExpr.Equals (trueExpr))
+                               return false;           
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       int hashCode = base.GetHashCode ();
+                       hashCode ^= falseExpr.GetHashCode ();
+                       hashCode ^= trueExpr.GetHashCode ();
+                       return hashCode;
+               }
                
                override public object Eval (DataRow row)
                {
@@ -59,6 +85,26 @@ namespace Mono.Data.SqlExpressions {
                {
                        this.defaultExpr = defaultExpr;
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is UnaryExpression))
+                               return false;
+
+                       IsNullFunction other = (IsNullFunction) obj;
+                       if (!other.defaultExpr.Equals (defaultExpr))
+                               return false;           
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return defaultExpr.GetHashCode () ^ base.GetHashCode ();
+               }
                
                override public object Eval (DataRow row)
                {
@@ -77,6 +123,26 @@ namespace Mono.Data.SqlExpressions {
                                throw new EvaluateException (String.Format ("Invalid type name '{0}'.", targetType));
                        }
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is ConvertFunction))
+                               return false;
+
+                       ConvertFunction other = (ConvertFunction) obj;
+                       if (other.targetType != targetType)
+                               return false;           
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return targetType.GetHashCode () ^ base.GetHashCode ();
+               }
                
                override public object Eval (DataRow row)
                {
index 3d20472b515d79ad2ef99d2a6d47ce592b768c35..3c2903b3e5712c9aa2cd4c6946f016c8cf962db0 100644 (file)
@@ -42,6 +42,42 @@ namespace Mono.Data.SqlExpressions {
                {
                        this.set = set;
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is In))
+                               return false;
+
+                       In other = (In) obj;
+                       if (other.set.Count != set.Count)
+                               return false;   
+       
+                       IEnumerator enumerator = set.GetEnumerator ();
+                       IEnumerator oenumerator = other.set.GetEnumerator ();
+
+                       do {
+                               if (!oenumerator.Current.Equals (enumerator.Current))
+                                       return false;
+                       }
+                       while (enumerator.MoveNext () || oenumerator.MoveNext ());
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       int hashCode = base.GetHashCode ();
+                       IEnumerator enumerator = set.GetEnumerator ();
+
+                       do {
+                               hashCode ^= enumerator.Current.GetHashCode ();
+                       }
+                       while (enumerator.MoveNext ());
+                       return hashCode;
+               }
        
                override public object Eval (DataRow row)
                {
index 80f986be033611aedee1a8c8e1d8a69cb3424b5c..76936ef9f0ace8c3063eaf74f65717eab72322ff 100644 (file)
@@ -58,6 +58,26 @@ namespace Mono.Data.SqlExpressions {
                        this.pattern = pattern;
                }
 
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is Like))
+                               return false;
+
+                       Like other = (Like) obj;
+                       if (other.pattern != pattern)
+                               return false;
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return pattern.GetHashCode () ^ base.GetHashCode ();
+               }
+
                override public object Eval (DataRow row)
                {
                        object o = expr.Eval (row);
index 0936bbbcb87c75cd32273e2b94f0ac4756068fea..28ee4e11e7bae30e0f95a3c5537e8caefdef1b76 100644 (file)
@@ -41,6 +41,30 @@ namespace Mono.Data.SqlExpressions {
                {
                        this.val = val;
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is Literal))
+                               return false;
+
+                       Literal other = (Literal) obj;
+                       if (other.val != null) {
+                               if (!other.val.Equals (val))
+                                       return false;
+                       }
+                       else if (val != null)
+                               return false;
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       return val.GetHashCode () ^ base.GetHashCode ();
+               }
        
                public override object Eval (DataRow row)
                {
index 5d8a84f0a96f3c3f79da940d3e159f0b0bada8dd..99d4d2836b52a65025861832da8faf8b3a66035c 100644 (file)
@@ -62,6 +62,32 @@ namespace Mono.Data.SqlExpressions {
                        this.start = start;
                        this.len = len;
                }
+
+               public override bool Equals(object obj)
+               {
+                       if (!base.Equals (obj))
+                               return false;
+
+                       if (!(obj is SubstringFunction))
+                               return false;
+
+                       SubstringFunction other = (SubstringFunction) obj;
+                       if (other.start != start)
+                               return false;
+
+                       if (other.len != len)
+                               return false;           
+
+                       return true;
+               }
+
+               public override int GetHashCode()
+               {
+                       int hashCode = base.GetHashCode ();
+                       hashCode ^= start.GetHashCode ();
+                       hashCode ^= len.GetHashCode ();
+                       return hashCode;
+               }
                
                override public object Eval (DataRow row)
                {