2020
2121import java .util .*;
2222
23+ import javax .annotation .Nonnull ;
24+ import javax .annotation .Nullable ;
25+
2326/**
2427 * This class for generating DiffRows for side-by-sidy view.
2528 * You can customize the way of generating. For example, show inline diffs on not, ignoring
@@ -49,6 +52,8 @@ public class DiffRowGenerator {
4952 private final String InlineOldCssClass ;
5053 private final String InlineNewCssClass ;
5154 private final int columnWidth ;
55+ @ Nullable
56+ private final String defaultString ;
5257 private final Equalizer <String > equalizer ;
5358
5459 /**
@@ -65,6 +70,8 @@ public static class Builder {
6570 private String InlineOldCssClass = "editOldInline" ;
6671 private String InlineNewCssClass = "editNewInline" ;
6772 private int columnWidth = 80 ;
73+ @ Nullable
74+ private String defaultString = "" ;
6875
6976 /**
7077 * Show inline diffs in generating diff rows or not.
@@ -148,6 +155,12 @@ public Builder columnWidth(int width) {
148155 return this ;
149156 }
150157
158+ @ Nonnull
159+ public Builder defaultString (@ Nullable String defaultString ) {
160+ this .defaultString = defaultString ;
161+ return this ;
162+ }
163+
151164 /**
152165 * Build the DiffRowGenerator. If some parameters is not set, the default values are used.
153166 * @return the customized DiffRowGenerator
@@ -166,6 +179,7 @@ private DiffRowGenerator(Builder builder) {
166179 InlineOldCssClass = builder .InlineOldCssClass ;
167180 InlineNewCssClass = builder .InlineNewCssClass ;
168181 columnWidth = builder .columnWidth ; //
182+ defaultString = builder .defaultString ;
169183 equalizer = new Equalizer <String >() {
170184 public boolean equals (String original , String revised ) {
171185 if (ignoreWhiteSpaces ) {
@@ -242,7 +256,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
242256 if (delta .getClass ().equals (InsertDelta .class )) {
243257 endPos = orig .last () + 1 ;
244258 for (String line : (List <String >) rev .getLines ()) {
245- diffRows .add (new DiffRow (Tag .INSERT , "" , line ));
259+ diffRows .add (new DiffRow (Tag .INSERT , defaultString , line ));
246260 }
247261 continue ;
248262 }
@@ -251,7 +265,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
251265 if (delta .getClass ().equals (DeleteDelta .class )) {
252266 endPos = orig .last () + 1 ;
253267 for (String line : (List <String >) orig .getLines ()) {
254- diffRows .add (new DiffRow (Tag .DELETE , line , "" ));
268+ diffRows .add (new DiffRow (Tag .DELETE , line , defaultString ));
255269 }
256270 continue ;
257271 }
@@ -268,12 +282,12 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
268282 } else if (orig .size () > rev .size ()) {
269283 for (int j = 0 ; j < orig .size (); j ++) {
270284 diffRows .add (new DiffRow (Tag .CHANGE , (String ) orig .getLines ().get (j ), rev
271- .getLines ().size () > j ? (String ) rev .getLines ().get (j ) : "" ));
285+ .getLines ().size () > j ? (String ) rev .getLines ().get (j ) : defaultString ));
272286 }
273287 } else {
274288 for (int j = 0 ; j < rev .size (); j ++) {
275289 diffRows .add (new DiffRow (Tag .CHANGE , orig .getLines ().size () > j ? (String ) orig
276- .getLines ().get (j ) : "" , (String ) rev .getLines ().get (j )));
290+ .getLines ().get (j ) : defaultString , (String ) rev .getLines ().get (j )));
277291 }
278292 }
279293 endPos = orig .last () + 1 ;
0 commit comments