/// <summary> /// Check if the values match and outputs a set of granular differences /// </summary> /// <param name="diffObject"></param> /// <param name="diffsForSelf"></param> /// <param name="diffsForArgument"></param> /// <returns></returns> public bool ValueMatches(IDiffObject diffObject, out IDiffObjectsCollection diffsForSelf, out IDiffObjectsCollection diffsForArgument, out IDiffObjectsCollection commonElements) { HeaderDiffObject otherObject = diffObject as HeaderDiffObject; diffsForSelf = null; diffsForArgument = null; commonElements = null; bool matches = false; if (otherObject != null) { matches = _headerLineHash == otherObject.HeaderLineHash; //if the values are different but the headers are the same if (!matches && String.Compare(_name, otherObject.Name, true) == 0) { WordsDiffer valuesDiffer = new WordsDiffer(); valuesDiffer.AddTask(_values); valuesDiffer.AddTask(otherObject.Values); valuesDiffer.Properties.Sorted = true; valuesDiffer.Properties.CaseInSensitiveSort = true; double diffRatio = valuesDiffer.DoDiff(0, 1); diffsForSelf = valuesDiffer.GetResultingDifferences(0); diffsForArgument = valuesDiffer.GetResultingDifferences(1); commonElements = valuesDiffer.GetResultingCommonElements(0); matches = diffRatio >= _valuesMinSimilarity; } } return(matches); }
/// <summary> /// Verifies if the headers are exactly equal /// </summary> /// <param name="diffObject"></param> /// <returns></returns> public bool ValueEquals(IDiffObject diffObject) { bool res = false; HeaderDiffObject otherObject = diffObject as HeaderDiffObject; if (otherObject != null) { res = _headerLineHash == otherObject.HeaderLineHash; } return(res); }
/// <summary> /// Compares the values /// </summary> /// <param name="diffObject"></param> /// <param name="ignoreCase"></param> /// <returns></returns> public CompareResult CompareValues(IDiffObject diffObject, bool ignoreCase) { HeaderDiffObject other = diffObject as HeaderDiffObject; CompareResult res = CompareResult.Greater; if (other != null) { string otherString = other.ToString(); res = (CompareResult)String.Compare(_headerLine, otherString); } return(res); }
/// <summary> /// Adds a new header to the current collection /// </summary> /// <param name="obj"></param> /// <param name="i"></param> /// <param name="pos"></param> /// <param name="val"></param> private void AddNewItem(string obj, int i, long pos, string val) { if (!IsWhiteSpace(val)) { HeaderDiffObject newHeader = new HeaderDiffObject((int)pos, val); //check if the header appears more than once, this should change the similarity //algorithm, if the header only appears once then headers with the same name //will be considered matches string hName = newHeader.Name + ":"; if ( //search ahead obj.IndexOf("\n" + hName, i + 1, StringComparison.CurrentCultureIgnoreCase) == -1 && //search behind obj.IndexOf(hName, 0, i - val.Length, StringComparison.CurrentCultureIgnoreCase) == -1 ) { newHeader.ValuesMinSimilarity = 0.0; //values don't matter } _items.Add(newHeader); } }
/// <summary> /// Returns a deep clone of the current element /// </summary> /// <returns></returns> public IDiffObject Clone() { HeaderDiffObject clone = new HeaderDiffObject(_position, _headerLine); return(clone); }