Esempio n. 1
0
        public bool ValueEquals(IDiffObject diffObject)
        {
            bool res = false;
            BaseTextDiffObject other = diffObject as BaseTextDiffObject;

            if (other != null)
            {
                res = _valueHash == other.ValueHash;
            }
            return(res);
        }
Esempio n. 2
0
        public bool ValueMatches(IDiffObject diffObject)
        {
            BaseTextDiffObject otherObject = diffObject as BaseTextDiffObject;
            bool equals = false;

            if (otherObject != null)
            {
                equals = this.ValueHash == otherObject.ValueHash;

                if (!equals && SimilarityFactor < 1)
                {
                    equals = ASESimilarityAlgorithm.CalculateSimilarity(this.Value, otherObject.Value) >= this.SimilarityFactor;
                }
            }
            return(equals);
        }
Esempio n. 3
0
        /// <summary>
        /// Compares the current element against the given argument
        /// </summary>
        /// <param name="diffObject"></param>
        /// <param name="ignoreCase"></param>
        /// <returns></returns>
        public CompareResult CompareValues(IDiffObject diffObject, bool ignoreCase)
        {
            BaseTextDiffObject otherObject = diffObject as BaseTextDiffObject;
            CompareResult      result;

            if (diffObject != null)
            {
                result = (CompareResult)String.Compare(_value, otherObject.Value, ignoreCase);
            }
            else
            {
                throw new ArgumentException("Invalid comparison argument. Has to be of type TextDiffObject or not null");
            }

            return(result);
        }
Esempio n. 4
0
        public bool Merge(IDiffObject objectToMergeWith)
        {
            bool success = false;

            BaseTextDiffObject otherObject = objectToMergeWith as BaseTextDiffObject;

            if (otherObject != null)
            {
                if (_position + _length == objectToMergeWith.Position)
                {
                    _value += otherObject.Value;
                    _length = _value.Length;
                    success = true;
                }
            }

            return(success);
        }
Esempio n. 5
0
        /// <summary>
        /// Checks is the value is equal. If not where applicable a collection of granular differences is outputed
        /// </summary>
        /// <param name="diffObject"></param>
        /// <param name="diffsForSelf"></param>
        /// <param name="diffsForArgument"></param>
        /// <param name="commonElements"></param>
        /// <returns></returns>
        public bool ValueMatches(IDiffObject diffObject, out IDiffObjectsCollection diffsForSelf, out IDiffObjectsCollection diffsForArgument, out IDiffObjectsCollection commonElements)
        {
            BaseTextDiffObject otherObject = diffObject as BaseTextDiffObject;

            diffsForSelf     = null;
            diffsForArgument = null;
            commonElements   = null;
            bool matches = false;

            if (otherObject != null)
            {
                matches = this.ValueHash == otherObject.ValueHash;

                if (!matches)
                {
                    double simFactor = ASESimilarityAlgorithm.CalculateSimilarity(this.Value, otherObject.Value);

                    LettersDiffer granularDiffer = InitGranularDiffer();

                    if (simFactor > 0 && granularDiffer != null)
                    {
                        //calculate granular differences
                        granularDiffer.AddTask(Value, Position);                         //imports the current word into a letters collection starting from the position of the current element
                        granularDiffer.AddTask(otherObject.Value, otherObject.Position);

                        double diffRatio = granularDiffer.DoDiff(0, 1);

                        diffsForSelf     = granularDiffer.GetResultingDifferences(0);
                        diffsForArgument = granularDiffer.GetResultingDifferences(1);
                        commonElements   = granularDiffer.GetResultingCommonElements(0);

                        matches = diffRatio >= this.SimilarityFactor;
                    }
                }
            }

            return(matches);
        }