Skip to content

Commit 9a39411

Browse files
committed
removed diff exception
1 parent ae23408 commit 9a39411

15 files changed

+79
-158
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project uses a custom versioning scheme (and not [Semantic Versioning](http
77

88
## [Unreleased]
99

10+
* **API** change: removed DiffException completely
1011
* added possibility to **process diffs** to for instance show whitespace characters
1112

1213
## [4.4] – 2019-11-06

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.github.difflib.algorithm.DiffAlgorithmI;
1919
import com.github.difflib.algorithm.DiffAlgorithmListener;
20-
import com.github.difflib.algorithm.DiffException;
2120
import com.github.difflib.algorithm.myers.MyersDiff;
2221
import com.github.difflib.patch.AbstractDelta;
2322
import com.github.difflib.patch.Patch;
@@ -43,21 +42,20 @@ public final class DiffUtils {
4342
* @param revised The revised text. Must not be {@code null}.
4443
* @param progress progress listener
4544
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
46-
* @throws com.github.difflib.algorithm.DiffException
4745
*/
48-
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmListener progress) throws DiffException {
46+
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmListener progress) {
4947
return DiffUtils.diff(original, revised, new MyersDiff<>(), progress);
5048
}
5149

52-
public static <T> Patch<T> diff(List<T> original, List<T> revised) throws DiffException {
50+
public static <T> Patch<T> diff(List<T> original, List<T> revised) {
5351
return DiffUtils.diff(original, revised, new MyersDiff<>(), null);
5452
}
5553

5654
/**
5755
* Computes the difference between the original and revised text.
5856
*/
5957
public static Patch<String> diff(String sourceText, String targetText,
60-
DiffAlgorithmListener progress) throws DiffException {
58+
DiffAlgorithmListener progress) {
6159
return DiffUtils.diff(
6260
Arrays.asList(sourceText.split("\n")),
6361
Arrays.asList(targetText.split("\n")), progress);
@@ -74,7 +72,7 @@ public static Patch<String> diff(String sourceText, String targetText,
7472
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
7573
*/
7674
public static <T> Patch<T> diff(List<T> source, List<T> target,
77-
BiPredicate<T, T> equalizer) throws DiffException {
75+
BiPredicate<T, T> equalizer) {
7876
if (equalizer != null) {
7977
return DiffUtils.diff(source, target,
8078
new MyersDiff<>(equalizer));
@@ -92,7 +90,7 @@ public static <T> Patch<T> diff(List<T> source, List<T> target,
9290
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
9391
*/
9492
public static <T> Patch<T> diff(List<T> original, List<T> revised,
95-
DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) throws DiffException {
93+
DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) {
9694
Objects.requireNonNull(original, "original must not be null");
9795
Objects.requireNonNull(revised, "revised must not be null");
9896
Objects.requireNonNull(algorithm, "algorithm must not be null");
@@ -109,7 +107,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
109107
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
110108
*/
111109
public static <T> Patch<T> diff(List<T> original, List<T> revised,
112-
DiffAlgorithmI<T> algorithm) throws DiffException {
110+
DiffAlgorithmI<T> algorithm) {
113111
return diff(original, revised, algorithm, null);
114112
}
115113

@@ -121,7 +119,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
121119
* @param revised
122120
* @return
123121
*/
124-
public static Patch<String> diffInline(String original, String revised) throws DiffException {
122+
public static Patch<String> diffInline(String original, String revised) {
125123
List<String> origList = new ArrayList<>();
126124
List<String> revList = new ArrayList<>();
127125
for (Character character : original.toCharArray()) {

java-diff-utils/src/main/java/com/github/difflib/algorithm/DiffAlgorithmI.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Interface of a diff algorithm.
2323
*
2424
* @author Tobias Warneke (t.warneke@gmx.net)
25+
* @param <T> type of data that is diffed.
2526
*/
2627
public interface DiffAlgorithmI<T> {
2728

@@ -32,9 +33,8 @@ public interface DiffAlgorithmI<T> {
3233
* @param target target data
3334
* @param progress progress listener
3435
* @return
35-
* @throws DiffException
3636
*/
37-
List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) throws DiffException;
37+
List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress);
3838

3939
/**
4040
* Simple extension to compute a changeset using arrays.
@@ -43,9 +43,8 @@ public interface DiffAlgorithmI<T> {
4343
* @param target
4444
* @param progress
4545
* @return
46-
* @throws com.github.difflib.algorithm.DiffException
4746
*/
48-
default List<Change> computeDiff(T[] source, T[] target, DiffAlgorithmListener progress) throws DiffException {
47+
default List<Change> computeDiff(T[] source, T[] target, DiffAlgorithmListener progress) {
4948
return computeDiff(Arrays.asList(source), Arrays.asList(target), progress);
5049
}
5150
}

java-diff-utils/src/main/java/com/github/difflib/algorithm/DiffException.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

java-diff-utils/src/main/java/com/github/difflib/algorithm/DifferentiationFailedException.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.github.difflib.algorithm.Change;
1919
import com.github.difflib.algorithm.DiffAlgorithmI;
2020
import com.github.difflib.algorithm.DiffAlgorithmListener;
21-
import com.github.difflib.algorithm.DiffException;
22-
import com.github.difflib.algorithm.DifferentiationFailedException;
2321
import com.github.difflib.patch.DeltaType;
2422
import com.github.difflib.patch.Patch;
2523
import java.util.ArrayList;
@@ -50,7 +48,7 @@ public MyersDiff(final BiPredicate<T, T> equalizer) {
5048
* Return empty diff if get the error while procession the difference.
5149
*/
5250
@Override
53-
public List<Change> computeDiff(final List<T> source, final List<T> target, DiffAlgorithmListener progress) throws DiffException {
51+
public List<Change> computeDiff(final List<T> source, final List<T> target, DiffAlgorithmListener progress) {
5452
Objects.requireNonNull(source, "source list must not be null");
5553
Objects.requireNonNull(target, "target list must not be null");
5654

@@ -74,8 +72,7 @@ public List<Change> computeDiff(final List<T> source, final List<T> target, Diff
7472
* @return A minimum {@link PathNode Path} accross the differences graph.
7573
* @throws DifferentiationFailedException if a diff path could not be found.
7674
*/
77-
private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmListener progress)
78-
throws DifferentiationFailedException {
75+
private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmListener progress) {
7976
Objects.requireNonNull(orig, "original sequence is null");
8077
Objects.requireNonNull(rev, "revised sequence is null");
8178

@@ -132,7 +129,7 @@ private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmL
132129
diagonal[middle + d - 1] = null;
133130
}
134131
// According to Myers, this cannot happen
135-
throw new DifferentiationFailedException("could not find a diff path");
132+
throw new IllegalStateException("could not find a diff path");
136133
}
137134

138135
/**

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.github.difflib.text;
1717

1818
import com.github.difflib.DiffUtils;
19-
import com.github.difflib.algorithm.DiffException;
2019
import com.github.difflib.patch.AbstractDelta;
2120
import com.github.difflib.patch.ChangeDelta;
2221
import com.github.difflib.patch.Chunk;
@@ -187,8 +186,7 @@ private DiffRowGenerator(Builder builder) {
187186
* @param revised the revised text
188187
* @return the DiffRows between original and revised texts
189188
*/
190-
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised)
191-
throws DiffException {
189+
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised) {
192190
return generateDiffRows(original, DiffUtils.diff(original, revised, equalizer));
193191
}
194192

@@ -200,8 +198,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
200198
* @param patch the given patch
201199
* @return the DiffRows between original and revised texts
202200
*/
203-
public List<DiffRow> generateDiffRows(final List<String> original, Patch<String> patch)
204-
throws DiffException {
201+
public List<DiffRow> generateDiffRows(final List<String> original, Patch<String> patch) {
205202
List<DiffRow> diffRows = new ArrayList<>();
206203
int endPos = 0;
207204
final List<AbstractDelta<String>> deltaList = patch.getDeltas();
@@ -291,8 +288,7 @@ List<String> normalizeLines(List<String> list) {
291288
*
292289
* @param delta the given delta
293290
*/
294-
private List<DiffRow> generateInlineDiffs(AbstractDelta<String> delta)
295-
throws DiffException {
291+
private List<DiffRow> generateInlineDiffs(AbstractDelta<String> delta) {
296292
List<String> orig = normalizeLines(delta.getSource().getLines());
297293
List<String> rev = normalizeLines(delta.getTarget().getLines());
298294
List<String> origList;

java-diff-utils/src/test/java/com/github/difflib/DiffUtilsTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.difflib;
22

3-
import com.github.difflib.algorithm.DiffException;
43
import com.github.difflib.patch.ChangeDelta;
54
import com.github.difflib.patch.Chunk;
65
import com.github.difflib.patch.DeleteDelta;
@@ -28,7 +27,7 @@
2827
public class DiffUtilsTest {
2928

3029
@Test
31-
public void testDiff_Insert() throws DiffException {
30+
public void testDiff_Insert() {
3231
final Patch<String> patch = DiffUtils.diff(Arrays.asList("hhh"), Arrays.
3332
asList("hhh", "jjj", "kkk"));
3433
assertNotNull(patch);
@@ -40,7 +39,7 @@ public void testDiff_Insert() throws DiffException {
4039
}
4140

4241
@Test
43-
public void testDiff_Delete() throws DiffException {
42+
public void testDiff_Delete() {
4443
final Patch<String> patch = DiffUtils.diff(Arrays.asList("ddd", "fff", "ggg"), Arrays.
4544
asList("ggg"));
4645
assertNotNull(patch);
@@ -52,7 +51,7 @@ public void testDiff_Delete() throws DiffException {
5251
}
5352

5453
@Test
55-
public void testDiff_Change() throws DiffException {
54+
public void testDiff_Change() {
5655
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc");
5756
final List<String> changeTest_to = Arrays.asList("aaa", "zzz", "ccc");
5857

@@ -66,14 +65,14 @@ public void testDiff_Change() throws DiffException {
6665
}
6766

6867
@Test
69-
public void testDiff_EmptyList() throws DiffException {
68+
public void testDiff_EmptyList() {
7069
final Patch<String> patch = DiffUtils.diff(new ArrayList<>(), new ArrayList<>());
7170
assertNotNull(patch);
7271
assertEquals(0, patch.getDeltas().size());
7372
}
7473

7574
@Test
76-
public void testDiff_EmptyListWithNonEmpty() throws DiffException {
75+
public void testDiff_EmptyListWithNonEmpty() {
7776
final Patch<String> patch = DiffUtils.diff(new ArrayList<>(), Arrays.asList("aaa"));
7877
assertNotNull(patch);
7978
assertEquals(1, patch.getDeltas().size());
@@ -82,7 +81,7 @@ public void testDiff_EmptyListWithNonEmpty() throws DiffException {
8281
}
8382

8483
@Test
85-
public void testDiffInline() throws DiffException {
84+
public void testDiffInline() {
8685
final Patch<String> patch = DiffUtils.diffInline("", "test");
8786
assertEquals(1, patch.getDeltas().size());
8887
assertTrue(patch.getDeltas().get(0) instanceof InsertDelta);
@@ -92,7 +91,7 @@ public void testDiffInline() throws DiffException {
9291
}
9392

9493
@Test
95-
public void testDiffInline2() throws DiffException {
94+
public void testDiffInline2() {
9695
final Patch<String> patch = DiffUtils.diffInline("es", "fest");
9796
assertEquals(2, patch.getDeltas().size());
9897
assertTrue(patch.getDeltas().get(0) instanceof InsertDelta);
@@ -105,7 +104,7 @@ public void testDiffInline2() throws DiffException {
105104
}
106105

107106
@Test
108-
public void testDiffIntegerList() throws DiffException {
107+
public void testDiffIntegerList() {
109108
List<Integer> original = Arrays.asList(1, 2, 3, 4, 5);
110109
List<Integer> revised = Arrays.asList(2, 3, 4, 6);
111110

@@ -121,7 +120,7 @@ public void testDiffIntegerList() throws DiffException {
121120
}
122121

123122
@Test
124-
public void testDiffMissesChangeForkDnaumenkoIssue31() throws DiffException {
123+
public void testDiffMissesChangeForkDnaumenkoIssue31() {
125124
List<String> original = Arrays.asList("line1", "line2", "line3");
126125
List<String> revised = Arrays.asList("line1", "line2-2", "line4");
127126

@@ -135,7 +134,7 @@ public void testDiffMissesChangeForkDnaumenkoIssue31() throws DiffException {
135134
*/
136135
@Test
137136
@Disabled
138-
public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException {
137+
public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException {
139138
ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip");
140139

141140
Patch<String> patch = DiffUtils.diff(
@@ -154,7 +153,7 @@ public static List<String> readStringListFromInputStream(InputStream is) throws
154153
}
155154

156155
@Test
157-
public void testDiffMyersExample1() throws DiffException {
156+
public void testDiffMyersExample1() {
158157
final Patch<String> patch = DiffUtils.diff(Arrays.asList("A", "B", "C", "A", "B", "B", "A"), Arrays.asList("C", "B", "A", "B", "A", "C"));
159158
assertNotNull(patch);
160159
assertEquals(4, patch.getDeltas().size());

0 commit comments

Comments
 (0)