private static IEnumerable <DiffElement <T> > AlignElementsImplementation <T>([NotNull] IList <T> collection1, [NotNull] IList <T> collection2, [NotNull] IEnumerable <DiffSection> diffSections, [NotNull] IDiffElementAligner <T> aligner) { int start1 = 0; int start2 = 0; foreach (var section in diffSections) { if (section.IsMatch) { for (int index = 0; index < section.LengthInCollection1; index++) { yield return(new DiffElement <T>(collection1[start1], collection2[start2], DiffOperation.Match)); start1++; start2++; } } else { foreach (var element in aligner.Align(collection1, start1, section.LengthInCollection1, collection2, start2, section.LengthInCollection2)) { yield return(element); } start1 += section.LengthInCollection1; start2 += section.LengthInCollection2; } } }
public IEnumerable <DiffElement <T> > Align([NotNull] IList <T> collection1, int start1, int length1, [NotNull] IList <T> collection2, int start2, int length2) { if (collection1 == null) { throw new ArgumentNullException(nameof(collection1)); } if (collection2 == null) { throw new ArgumentNullException(nameof(collection2)); } if (length1 > 0 && length2 > 0) { var elements = TryAlignSections(collection1, start1, length1, collection2, start2, length2); if (elements.Count > 0) { return(elements); } } return(_BasicAligner.Align(collection1, start1, length1, collection2, start2, length2)); }
/// <summary> /// Align the specified portions of the two collections and output element-by-element operations for the aligned elements. /// </summary> /// <param name="collection1"> /// The first collection. /// </param> /// <param name="start1"> /// The start of the portion to look at in the first collection, <paramref name="collection1"/>. /// </param> /// <param name="length1"> /// The length of the portion to look at in the first collection, <paramref name="collection1"/>. /// </param> /// <param name="collection2"> /// The second collection. /// </param> /// <param name="start2"> /// The start of the portion to look at in the second collection, <paramref name="collection2"/>. /// </param> /// <param name="length2"> /// The length of the portion to look at in the second collection, <paramref name="collection2"/>. /// </param> /// <returns> /// A collection of <see cref="DiffElement{T}"/> values, one for each aligned element. /// </returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="collection1"/> is <c>null</c>.</para> /// <para>- or -</para> /// <para><paramref name="collection2"/> is <c>null</c>.</para> /// </exception> public IEnumerable <DiffElement <string> > Align(IList <string> collection1, int start1, int length1, IList <string> collection2, int start2, int length2) { return(_Aligner.Align(collection1, start1, length1, collection2, start2, length2)); }