Esempio n. 1
0
        /**
         * Compares two STUN Messages. Messages are considered equal when their
         * type, length, and all their attributes are equal.
         *
         * @param obj the object to compare this message with.
         * @return true if the messages are equal and false otherwise.
         */
        public override bool Equals(Object obj)
        {
            if (!(obj is Message) ||
                obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            Message msg = (Message)obj;

            if (msg.GetMessageType() != GetMessageType())
            {
                return(false);
            }
            if (msg.GetDataLength() != GetDataLength())
            {
                return(false);
            }

            //compare attributes
            for (int x = 0; x < this.attributes.Count; x++)
            {
                Attribute localAtt = (Attribute)this.attributes[x];

                if (!localAtt.Equals(msg.GetAttribute(localAtt.GetAttributeType())))
                {
                    return(false);
                }
            }

            return(true);
        }