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
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Commit ff5cefc

Browse filesBrowse files
committed
refs KengoTODA#1: Equalizer does not have to care about ignoreWhiteSpace.
Now we have 2 classes which has to care about `ignoreWhiteSpace` and here is 2 bugs: 1. it converts `null` to empty string 2. `Builder.ignoreWhiteSpace` doesn't work when we set custom Equalizer This change solves these problem.
1 parent 05ae3ef commit ff5cefc
Copy full SHA for ff5cefc

1 file changed

+18-8Lines changed: 18 additions & 8 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: src/main/java/difflib/DiffRowGenerator.java
+18-8Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import javax.annotation.Nonnull;
2424
import javax.annotation.Nullable;
2525

26+
import com.google.common.base.Function;
2627
import com.google.common.base.Joiner;
28+
import com.google.common.collect.Lists;
2729

2830
/**
2931
* This class for generating DiffRows for side-by-sidy view.
@@ -76,15 +78,9 @@ public static class Builder {
7678
private String defaultString = "";
7779
private Equalizer<String> stringEqualizer = new Equalizer<String>() {
7880
public boolean equals(String original, String revised) {
79-
if (ignoreWhiteSpaces) {
80-
original = original == null ? "" : original;
81-
revised = revised == null ? "" : revised;
82-
original = original.trim().replaceAll("\\s+", " ");
83-
revised = revised.trim().replaceAll("\\s+", " ");
84-
}
85-
return original.equals(revised);
81+
return Objects.equals(original, revised);
8682
}
87-
};;
83+
};
8884

8985
/**
9086
* Show inline diffs in generating diff rows or not.
@@ -205,6 +201,20 @@ private DiffRowGenerator(Builder builder) {
205201
* @return the DiffRows between original and revised texts
206202
*/
207203
public List<DiffRow> generateDiffRows(List<String> original, List<String> revised) {
204+
if (ignoreWhiteSpaces) {
205+
Function<String, String> whiteSpaceReplacer = new Function<String, String>(){
206+
@Override
207+
public String apply(String string) {
208+
if (string == null) {
209+
return null;
210+
} else {
211+
return string.trim().replaceAll("\\s+", " ");
212+
}
213+
}
214+
};
215+
original = Lists.transform(original, whiteSpaceReplacer);
216+
revised = Lists.transform(revised, whiteSpaceReplacer);
217+
}
208218
return generateDiffRows(original, revised, DiffUtils.diff(original, revised, equalizer));
209219
}
210220

0 commit comments

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