using System;
using System.Collections.Generic;
using System.Text;

namespace FormulaEditor
{
    public class StringEqualityOperation : IObjectOperation, IBinaryAcceptor, IBinaryDetector
    {

        static private readonly Boolean b = false;

        static public readonly StringEqualityOperation Object = new StringEqualityOperation();


        protected StringEqualityOperation()
        {
        }

        #region IObjectOperation Members

        int IObjectOperation.Arity
        {
            get { return 2; }
        }

        object IObjectOperation.this[object[] x]
        {
            get { return ("" + x[0]).Equals("" + x[1]); }
        }

        object IObjectOperation.ReturnType
        {
            get { return b; }
        }

        bool IObjectOperation.IsPowered
        {
            get { return false; }
        }

        #endregion

        #region IBinaryAcceptor Members

        IObjectOperation IBinaryAcceptor.Accept(object typeA, object typeB)
        {
            return this;
        }

        #endregion

        #region IBinaryDetector Members

        BinaryAssociationDirection IBinaryDetector.AssociationDirection
        {
            get { return BinaryAssociationDirection.RightLeft; }
        }

        IBinaryAcceptor IBinaryDetector.Detect(MathSymbol s)
        {
            if (s is BinarySymbol)
            {
                char c = s.Symbol;
                if (c == '=')
                {
                    return Object;
                }
                if (c == '\u2260')
                {
                    return StringObjectUnequalityOperation.Object;
                }
            }
            return null;
        }

        #endregion
    }
}
