@@ -22,11 +22,9 @@ package io.github.petertrr.diffutils
2222
2323import io.github.petertrr.diffutils.algorithm.DiffAlgorithm
2424import io.github.petertrr.diffutils.algorithm.DiffAlgorithmListener
25- import io.github.petertrr.diffutils.algorithm.DiffEqualizer
2625import io.github.petertrr.diffutils.algorithm.NoopAlgorithmListener
2726import io.github.petertrr.diffutils.algorithm.myers.MyersDiff
2827import io.github.petertrr.diffutils.patch.Patch
29- import io.github.petertrr.diffutils.patch.PatchFailedException
3028import io.github.petertrr.diffutils.text.DiffRowGenerator
3129import kotlin.jvm.JvmName
3230import kotlin.jvm.JvmOverloads
@@ -35,16 +33,16 @@ import kotlin.jvm.JvmOverloads
3533private val lineBreak = Regex (" \r\n |\r |\n " )
3634
3735/* *
38- * Computes the difference between the source and target text .
36+ * Computes the difference between two strings .
3937 *
4038 * By default, uses the Myers algorithm.
4139 *
42- * @param sourceText The original text
43- * @param targetText The target text
40+ * @param sourceText A string representing the original text
41+ * @param targetText A string representing the revised text
4442 * @param algorithm The diff algorithm to use
4543 * @param progress The diff algorithm progress listener
4644 * @param includeEqualParts Whether to include equal data parts into the patch. `false` by default.
47- * @return The patch describing the difference between the original and target text
45+ * @return The patch describing the difference between the original and revised strings
4846 */
4947@JvmOverloads
5048public fun diff (
@@ -62,37 +60,17 @@ public fun diff(
6260 includeEqualParts = includeEqualParts,
6361 )
6462
65- /* *
66- * Computes the difference between the source and target list of elements using the Myers algorithm.
67- *
68- * @param source The original elements
69- * @param target The target elements
70- * @param equalizer The equalizer to replace the default compare algorithm [Any.equals].
71- * If `null`, the default equalizer of the default algorithm is used.
72- * @return The patch describing the difference between the source and target sequences
73- */
74- public fun <T > diff (
75- source : List <T >,
76- target : List <T >,
77- equalizer : DiffEqualizer <T >,
78- ): Patch <T > =
79- diff(
80- source = source,
81- target = target,
82- algorithm = MyersDiff (equalizer),
83- )
84-
8563/* *
8664 * Computes the difference between the original and target list of elements.
8765 *
88- * By default, uses the Meyers algorithm.
66+ * By default, uses the Myers algorithm.
8967 *
90- * @param source The original elements
91- * @param target The target elements
68+ * @param source A list representing the original sequence of elements
69+ * @param target A list representing the revised sequence of elements
9270 * @param algorithm The diff algorithm to use
9371 * @param progress The diff algorithm progress listener
94- * @param includeEqualParts Whether to include equal data parts into the patch. `false` by default.
95- * @return The patch describing the difference between the original and target sequences
72+ * @param includeEqualParts Whether to include equal parts in the resulting patch. `false` by default.
73+ * @return The patch describing the difference between the original and revised sequences
9674 */
9775@JvmOverloads
9876public fun <T > diff (
@@ -114,6 +92,10 @@ public fun <T> diff(
11492 *
11593 * This one uses the "trick" to make out of texts lists of characters,
11694 * like [DiffRowGenerator] does and merges those changes at the end together again.
95+ *
96+ * @param original A string representing the original text
97+ * @param revised A string representing the revised text
98+ * @return The patch describing the difference between the original and revised text
11799 */
118100public fun diffInline (original : String , revised : String ): Patch <String > {
119101 val origChars = original.toCharArray()
@@ -142,22 +124,21 @@ public fun diffInline(original: String, revised: String): Patch<String> {
142124}
143125
144126/* *
145- * Patch the original text with the given patch .
127+ * Applies the given patch to the original list and returns the revised list .
146128 *
147- * @param original The original text
129+ * @param original A list representing the original sequence of elements
148130 * @param patch The patch to apply
149- * @return The revised text
150- * @throws PatchFailedException If the patch cannot be applied
131+ * @return A list representing the revised sequence of elements
151132 */
152133public fun <T > patch (original : List <T >, patch : Patch <T >): List <T > =
153134 patch.applyTo(original)
154135
155136/* *
156- * Unpatch the revised text for a given patch
137+ * Applies the given patch to the revised list and returns the original list.
157138 *
158- * @param revised The revised text
159- * @param patch The given patch
160- * @return The original text
139+ * @param revised A list representing the revised sequence of elements
140+ * @param patch The patch to apply
141+ * @return A list representing the original sequence of elements
161142 */
162143public fun <T > unpatch (revised : List <T >, patch : Patch <T >): List <T > =
163144 patch.restore(revised)
0 commit comments