Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37556b7

Browse filesBrowse files
committed
passing through exceptions
1 parent eeae5dd commit 37556b7
Copy full SHA for 37556b7

File tree

4 files changed

+18
-21
lines changed
Filter options

4 files changed

+18
-21
lines changed

‎src/main/java/difflib/DiffUtils.java

Copy file name to clipboardExpand all lines: src/main/java/difflib/DiffUtils.java
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import difflib.patch.Patch;
2626
import difflib.patch.ChangeDelta;
2727
import difflib.algorithm.DiffAlgorithm;
28+
import difflib.algorithm.DiffException;
2829
import difflib.patch.Equalizer;
2930
import difflib.algorithm.myers.MyersDiff;
3031
import java.util.ArrayList;
@@ -43,7 +44,7 @@
4344
*/
4445
public final class DiffUtils {
4546

46-
private static Pattern unifiedDiffChunkRe = Pattern
47+
private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP = Pattern
4748
.compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$");
4849

4950
/**
@@ -55,7 +56,7 @@ public final class DiffUtils {
5556
* @return The patch describing the difference between the original and revised sequences. Never
5657
* {@code null}.
5758
*/
58-
public static <T> Patch<T> diff(List<T> original, List<T> revised) {
59+
public static <T> Patch<T> diff(List<T> original, List<T> revised) throws DiffException {
5960
return DiffUtils.diff(original, revised, new MyersDiff<>());
6061
}
6162

@@ -72,7 +73,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised) {
7273
* {@code null}.
7374
*/
7475
public static <T> Patch<T> diff(List<T> original, List<T> revised,
75-
Equalizer<T> equalizer) {
76+
Equalizer<T> equalizer) throws DiffException {
7677
if (equalizer != null) {
7778
return DiffUtils.diff(original, revised,
7879
new MyersDiff<>(equalizer));
@@ -91,7 +92,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
9192
* {@code null}.
9293
*/
9394
public static <T> Patch<T> diff(List<T> original, List<T> revised,
94-
DiffAlgorithm<T> algorithm) {
95+
DiffAlgorithm<T> algorithm) throws DiffException {
9596
if (original == null) {
9697
throw new IllegalArgumentException("original must not be null");
9798
}
@@ -113,7 +114,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
113114
* @param revised
114115
* @return
115116
*/
116-
public static Patch<String> diffInline(String original, String revised) {
117+
public static Patch<String> diffInline(String original, String revised) throws DiffException {
117118
LinkedList<String> origList = new LinkedList<>();
118119
LinkedList<String> revList = new LinkedList<>();
119120
for (Character character : original.toCharArray()) {
@@ -190,7 +191,7 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
190191
}
191192
continue;
192193
}
193-
Matcher m = unifiedDiffChunkRe.matcher(line);
194+
Matcher m = UNIFIED_DIFF_CHUNK_REGEXP.matcher(line);
194195
if (m.find()) {
195196
// Process the lines in the previous chunk
196197
if (!rawChunk.isEmpty()) {

‎src/main/java/difflib/algorithm/DiffAlgorithm.java

Copy file name to clipboardExpand all lines: src/main/java/difflib/algorithm/DiffAlgorithm.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface DiffAlgorithm<T> {
3838
* @param revised The revised sequence. Must not be {@code null}.
3939
* @return The patch representing the diff of the given sequences. Never {@code null}.
4040
*/
41-
public Patch<T> diff(T[] original, T[] revised);
41+
public Patch<T> diff(T[] original, T[] revised) throws DiffException;
4242

4343
/**
4444
* Computes the difference between the original sequence and the revised sequence and returns it
@@ -48,5 +48,5 @@ public interface DiffAlgorithm<T> {
4848
* @param revised The revised sequence. Must not be {@code null}.
4949
* @return The patch representing the diff of the given sequences. Never {@code null}.
5050
*/
51-
public Patch<T> diff(List<T> original, List<T> revised);
51+
public Patch<T> diff(List<T> original, List<T> revised) throws DiffException;
5252
}

‎src/main/java/difflib/algorithm/myers/MyersDiff.java

Copy file name to clipboardExpand all lines: src/main/java/difflib/algorithm/myers/MyersDiff.java
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import difflib.patch.ChangeDelta;
2929
import difflib.algorithm.DiffAlgorithm;
3030
import difflib.*;
31+
import difflib.algorithm.DiffException;
3132
import java.lang.reflect.Array;
3233
import java.util.ArrayList;
3334
import java.util.Arrays;
@@ -86,7 +87,7 @@ public MyersDiff(final Equalizer<T> equalizer) {
8687
* @return Returns an empty diff if get the error while procession the difference.
8788
*/
8889
@Override
89-
public Patch<T> diff(final T[] original, final T[] revised) {
90+
public Patch<T> diff(final T[] original, final T[] revised) throws DiffException {
9091
return diff(Arrays.asList(original), Arrays.asList(revised));
9192
}
9293

@@ -96,21 +97,15 @@ public Patch<T> diff(final T[] original, final T[] revised) {
9697
* Return empty diff if get the error while procession the difference.
9798
*/
9899
@Override
99-
public Patch<T> diff(final List<T> original, final List<T> revised) {
100+
public Patch<T> diff(final List<T> original, final List<T> revised) throws DiffException {
100101
if (original == null) {
101102
throw new IllegalArgumentException("original list must not be null");
102103
}
103104
if (revised == null) {
104105
throw new IllegalArgumentException("revised list must not be null");
105106
}
106-
PathNode path;
107-
try {
108-
path = buildPath(original, revised);
109-
return buildRevision(path, original, revised);
110-
} catch (DifferentiationFailedException e) {
111-
e.printStackTrace();
112-
}
113-
return new Patch<>();
107+
PathNode path = buildPath(original, revised);
108+
return buildRevision(path, original, revised);
114109
}
115110

116111
/**

‎src/main/java/difflib/text/DiffRowGenerator.java

Copy file name to clipboardExpand all lines: src/main/java/difflib/text/DiffRowGenerator.java
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import difflib.patch.Delta;
2626
import difflib.text.DiffRow.Tag;
2727
import difflib.DiffUtils;
28+
import difflib.algorithm.DiffException;
2829
import difflib.patch.InsertDelta;
2930
import difflib.patch.Patch;
3031
import difflib.patch.Equalizer;
@@ -193,7 +194,7 @@ public boolean equals(String original, String revised) {
193194
* @param revised the revised text
194195
* @return the DiffRows between original and revised texts
195196
*/
196-
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised) {
197+
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised) throws DiffException {
197198
return generateDiffRows(original, revised, DiffUtils.diff(original, revised, equalizer));
198199
}
199200

@@ -206,7 +207,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
206207
* @param patch the given patch
207208
* @return the DiffRows between original and revised texts
208209
*/
209-
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised, Patch<String> patch) {
210+
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised, Patch<String> patch) throws DiffException {
210211
// normalize the lines (expand tabs, escape html entities)
211212
original = StringUtils.normalize(original);
212213
revised = StringUtils.normalize(revised);
@@ -288,7 +289,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
288289
*
289290
* @param delta the given delta
290291
*/
291-
private void addInlineDiffs(Delta<String> delta) {
292+
private void addInlineDiffs(Delta<String> delta) throws DiffException {
292293
List<String> orig = (List<String>) delta.getOriginal().getLines();
293294
List<String> rev = (List<String>) delta.getRevised().getLines();
294295
LinkedList<String> origList = new LinkedList<>();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.