Skip to content

Commit bbf6ec6

Browse files
committed
fix: restore public delegator methods in DiffUtils for backward compatibility and fix PMD violations
1 parent 7b940ff commit bbf6ec6

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

java-diff-utils/src/main/java/com/github/difflib/DiffUtils.java

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
5454
*/
5555
public static <T> Patch<T> diff(
5656
List<? extends T> original, List<? extends T> revised, DiffAlgorithmListener progress) {
57-
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), progress);
57+
return diff(original, revised, DEFAULT_DIFF.create(), progress);
5858
}
5959

6060
/**
@@ -66,7 +66,7 @@ public static <T> Patch<T> diff(
6666
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
6767
*/
6868
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised) {
69-
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null);
69+
return diff(original, revised, DEFAULT_DIFF.create(), null);
7070
}
7171

7272
/**
@@ -79,7 +79,7 @@ public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> re
7979
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
8080
*/
8181
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised, boolean includeEqualParts) {
82-
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts);
82+
return diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts);
8383
}
8484

8585
/**
@@ -91,7 +91,7 @@ public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> re
9191
* @return The patch describing the difference between the original and revised strings. Never {@code null}.
9292
*/
9393
public static Patch<String> diff(String sourceText, String targetText, DiffAlgorithmListener progress) {
94-
return DiffUtils.diff(Arrays.asList(sourceText.split("\n")), Arrays.asList(targetText.split("\n")), progress);
94+
return diff(Arrays.asList(sourceText.split("\n")), Arrays.asList(targetText.split("\n")), progress);
9595
}
9696

9797
/**
@@ -109,9 +109,9 @@ public static Patch<String> diff(String sourceText, String targetText, DiffAlgor
109109
public static <T> Patch<T> diff(
110110
List<? extends T> source, List<? extends T> target, BiPredicate<? super T, ? super T> equalizer) {
111111
if (equalizer != null) {
112-
return DiffUtils.diff(source, target, DEFAULT_DIFF.create(equalizer));
112+
return diff(source, target, DEFAULT_DIFF.create(equalizer));
113113
}
114-
return DiffUtils.diff(source, target, DEFAULT_DIFF.create());
114+
return diff(source, target, DEFAULT_DIFF.create());
115115
}
116116

117117
public static <T> Patch<T> diff(
@@ -162,5 +162,44 @@ public static <T> Patch<T> diff(
162162
return diff(original, revised, algorithm, null);
163163
}
164164

165+
166+
/**
167+
* Computes the difference between the given texts inline. Splits the texts
168+
* into tokens and delegates to the default diff algorithm.
169+
*
170+
* @param original the original text. Must not be {@code null}.
171+
* @param revised the revised text. Must not be {@code null}.
172+
* @return The patch describing the difference between the original and revised texts.
173+
*/
174+
public static Patch<String> diffInline(String original, String revised) {
175+
return InlineDiffUtils.diffInline(original, revised);
176+
}
177+
178+
/**
179+
* Applies the given patch to the original list and returns the revised list.
180+
*
181+
* @param <T> the type of elements in the lists.
182+
* @param original the original list. Must not be {@code null}.
183+
* @param patch the patch to apply. Must not be {@code null}.
184+
* @return the revised list.
185+
* @throws com.github.difflib.patch.PatchFailedException if the patch cannot be applied.
186+
*/
187+
public static <T> List<T> patch(List<? extends T> original, Patch<T> patch)
188+
throws com.github.difflib.patch.PatchFailedException {
189+
return PatchUtils.patch(original, patch);
190+
}
191+
192+
/**
193+
* Applies the given patch in reverse to the revised list and returns the original list.
194+
*
195+
* @param <T> the type of elements in the lists.
196+
* @param revised the revised list. Must not be {@code null}.
197+
* @param patch the patch to reverse-apply. Must not be {@code null}.
198+
* @return the reconstructed original list.
199+
*/
200+
public static <T> List<T> unpatch(List<? extends T> revised, Patch<T> patch) {
201+
return PatchUtils.unpatch(revised, patch);
202+
}
203+
165204
private DiffUtils() {}
166205
}

java-diff-utils/src/main/java/com/github/difflib/PatchUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public final class PatchUtils {
1313
* Applies the given patch to the original list and returns the revised list.
1414
*
1515
* @param original a {@link List} representing the original list.
16-
* @param patch a {@link List} representing the patch to apply.
16+
* @param patch a {@link Patch} representing the patch to apply.
1717
* @return the revised list.
1818
* @throws PatchFailedException if the patch cannot be applied.
1919
*/

java-diff-utils/src/main/java/com/github/difflib/text/InlineDiffAnnotatorConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* <p>Instances are created once per {@link DiffRowGenerator} construction and reused
1616
* for every delta processed.
1717
*/
18-
public final class InlineDiffAnnotatorConfig {
18+
final class InlineDiffAnnotatorConfig {
1919

2020
final boolean reportLinesUnchanged;
2121
final Function<String, String> lineNormalizer;

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ private void initFileIfNecessary() {
283283
}
284284
}
285285

286+
@SuppressWarnings("unused")
286287
private void processDiff(MatchResult match, String line) {
287288
// initFileIfNecessary();
288289
LOG.log(Level.FINE, "start {0}", line);
@@ -292,6 +293,7 @@ private void processDiff(MatchResult match, String line) {
292293
actualFile.setDiffCommand(line);
293294
}
294295

296+
@SuppressWarnings("unused")
295297
private void processSimilarityIndex(MatchResult match, String line) {
296298
actualFile.setSimilarityIndex(Integer.valueOf(match.group(1)));
297299
}
@@ -343,6 +345,7 @@ private void finalizeChunk() {
343345
}
344346
}
345347

348+
@SuppressWarnings("unused")
346349
private void processNormalLine(MatchResult match, String line) {
347350
String cline = line.substring(1);
348351
originalTxt.add(cline);

0 commit comments

Comments
 (0)