20
20
21
21
import java .util .*;
22
22
23
+ import javax .annotation .Nonnull ;
24
+ import javax .annotation .Nullable ;
25
+
23
26
/**
24
27
* This class for generating DiffRows for side-by-sidy view.
25
28
* You can customize the way of generating. For example, show inline diffs on not, ignoring
@@ -49,6 +52,8 @@ public class DiffRowGenerator {
49
52
private final String InlineOldCssClass ;
50
53
private final String InlineNewCssClass ;
51
54
private final int columnWidth ;
55
+ @ Nullable
56
+ private final String defaultString ;
52
57
private final Equalizer <String > equalizer ;
53
58
54
59
/**
@@ -65,6 +70,8 @@ public static class Builder {
65
70
private String InlineOldCssClass = "editOldInline" ;
66
71
private String InlineNewCssClass = "editNewInline" ;
67
72
private int columnWidth = 80 ;
73
+ @ Nullable
74
+ private String defaultString = "" ;
68
75
69
76
/**
70
77
* Show inline diffs in generating diff rows or not.
@@ -148,6 +155,12 @@ public Builder columnWidth(int width) {
148
155
return this ;
149
156
}
150
157
158
+ @ Nonnull
159
+ public Builder defaultString (@ Nullable String defaultString ) {
160
+ this .defaultString = defaultString ;
161
+ return this ;
162
+ }
163
+
151
164
/**
152
165
* Build the DiffRowGenerator. If some parameters is not set, the default values are used.
153
166
* @return the customized DiffRowGenerator
@@ -166,6 +179,7 @@ private DiffRowGenerator(Builder builder) {
166
179
InlineOldCssClass = builder .InlineOldCssClass ;
167
180
InlineNewCssClass = builder .InlineNewCssClass ;
168
181
columnWidth = builder .columnWidth ; //
182
+ defaultString = builder .defaultString ;
169
183
equalizer = new Equalizer <String >() {
170
184
public boolean equals (String original , String revised ) {
171
185
if (ignoreWhiteSpaces ) {
@@ -242,7 +256,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
242
256
if (delta .getClass ().equals (InsertDelta .class )) {
243
257
endPos = orig .last () + 1 ;
244
258
for (String line : (List <String >) rev .getLines ()) {
245
- diffRows .add (new DiffRow (Tag .INSERT , "" , line ));
259
+ diffRows .add (new DiffRow (Tag .INSERT , defaultString , line ));
246
260
}
247
261
continue ;
248
262
}
@@ -251,7 +265,7 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
251
265
if (delta .getClass ().equals (DeleteDelta .class )) {
252
266
endPos = orig .last () + 1 ;
253
267
for (String line : (List <String >) orig .getLines ()) {
254
- diffRows .add (new DiffRow (Tag .DELETE , line , "" ));
268
+ diffRows .add (new DiffRow (Tag .DELETE , line , defaultString ));
255
269
}
256
270
continue ;
257
271
}
@@ -268,12 +282,12 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
268
282
} else if (orig .size () > rev .size ()) {
269
283
for (int j = 0 ; j < orig .size (); j ++) {
270
284
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 ));
272
286
}
273
287
} else {
274
288
for (int j = 0 ; j < rev .size (); j ++) {
275
289
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 )));
277
291
}
278
292
}
279
293
endPos = orig .last () + 1 ;
0 commit comments