|
23 | 23 | import javax.annotation.Nonnull;
|
24 | 24 | import javax.annotation.Nullable;
|
25 | 25 |
|
| 26 | +import com.google.common.base.Function; |
26 | 27 | import com.google.common.base.Joiner;
|
| 28 | +import com.google.common.collect.Lists; |
27 | 29 |
|
28 | 30 | /**
|
29 | 31 | * This class for generating DiffRows for side-by-sidy view.
|
@@ -76,15 +78,9 @@ public static class Builder {
|
76 | 78 | private String defaultString = "";
|
77 | 79 | private Equalizer<String> stringEqualizer = new Equalizer<String>() {
|
78 | 80 | 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); |
86 | 82 | }
|
87 |
| - };; |
| 83 | + }; |
88 | 84 |
|
89 | 85 | /**
|
90 | 86 | * Show inline diffs in generating diff rows or not.
|
@@ -205,6 +201,20 @@ private DiffRowGenerator(Builder builder) {
|
205 | 201 | * @return the DiffRows between original and revised texts
|
206 | 202 | */
|
207 | 203 | 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 | + } |
208 | 218 | return generateDiffRows(original, revised, DiffUtils.diff(original, revised, equalizer));
|
209 | 219 | }
|
210 | 220 |
|
|
0 commit comments