34
34
public final class DiffUtils {
35
35
36
36
/**
37
- * Computes the difference between the original and revised list of elements with default diff algorithm
37
+ * Computes the difference between the original and revised list of elements with default diff
38
+ * algorithm
38
39
*
39
40
* @param <T> types to be diffed
40
41
* @param original The original text. Must not be {@code null}.
41
42
* @param revised The revised text. Must not be {@code null}.
42
43
* @param progress progress listener
43
- * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
44
+ * @return The patch describing the difference between the original and revised sequences. Never
45
+ * {@code null}.
44
46
*/
45
47
public static <T > Patch <T > diff (List <T > original , List <T > revised , DiffAlgorithmListener progress ) {
46
48
return DiffUtils .diff (original , revised , new MyersDiff <>(), progress );
47
49
}
48
-
50
+
49
51
public static <T > Patch <T > diff (List <T > original , List <T > revised ) {
50
52
return DiffUtils .diff (original , revised , new MyersDiff <>(), null );
51
53
}
54
+
55
+ public static <T > Patch <T > diff (List <T > original , List <T > revised , boolean includeEqualParts ) {
56
+ return DiffUtils .diff (original , revised , new MyersDiff <>(), null , includeEqualParts );
57
+ }
52
58
53
59
/**
54
60
* Computes the difference between the original and revised text.
55
61
*/
56
62
public static Patch <String > diff (String sourceText , String targetText ,
57
63
DiffAlgorithmListener progress ) {
58
64
return DiffUtils .diff (
59
- Arrays .asList (sourceText .split ("\n " )),
60
- Arrays .asList (targetText .split ("\n " )), progress );
65
+ Arrays .asList (sourceText .split ("\n " )),
66
+ Arrays .asList (targetText .split ("\n " )), progress );
61
67
}
62
68
63
69
/**
64
- * Computes the difference between the original and revised list of elements with default diff algorithm
70
+ * Computes the difference between the original and revised list of elements with default diff
71
+ * algorithm
65
72
*
66
73
* @param source The original text. Must not be {@code null}.
67
74
* @param target The revised text. Must not be {@code null}.
68
75
*
69
- * @param equalizer the equalizer object to replace the default compare algorithm (Object.equals). If {@code null}
70
- * the default equalizer of the default algorithm is used..
71
- * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
76
+ * @param equalizer the equalizer object to replace the default compare algorithm
77
+ * (Object.equals). If {@code null} the default equalizer of the default algorithm is used..
78
+ * @return The patch describing the difference between the original and revised sequences. Never
79
+ * {@code null}.
72
80
*/
73
81
public static <T > Patch <T > diff (List <T > source , List <T > target ,
74
82
BiPredicate <T , T > equalizer ) {
@@ -79,40 +87,51 @@ public static <T> Patch<T> diff(List<T> source, List<T> target,
79
87
return DiffUtils .diff (source , target , new MyersDiff <>());
80
88
}
81
89
90
+ public static <T > Patch <T > diff (List <T > original , List <T > revised ,
91
+ DiffAlgorithmI <T > algorithm , DiffAlgorithmListener progress ) {
92
+ return diff (original , revised , algorithm , progress , false );
93
+ }
94
+
82
95
/**
83
- * Computes the difference between the original and revised list of elements with default diff algorithm
96
+ * Computes the difference between the original and revised list of elements with default diff
97
+ * algorithm
84
98
*
85
99
* @param original The original text. Must not be {@code null}.
86
100
* @param revised The revised text. Must not be {@code null}.
87
101
* @param algorithm The diff algorithm. Must not be {@code null}.
88
102
* @param progress The diff algorithm listener.
89
- * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
103
+ * @param includeEqualParts Include equal data parts into the patch.
104
+ * @return The patch describing the difference between the original and revised sequences. Never
105
+ * {@code null}.
90
106
*/
91
107
public static <T > Patch <T > diff (List <T > original , List <T > revised ,
92
- DiffAlgorithmI <T > algorithm , DiffAlgorithmListener progress ) {
108
+ DiffAlgorithmI <T > algorithm , DiffAlgorithmListener progress ,
109
+ boolean includeEqualParts ) {
93
110
Objects .requireNonNull (original , "original must not be null" );
94
111
Objects .requireNonNull (revised , "revised must not be null" );
95
112
Objects .requireNonNull (algorithm , "algorithm must not be null" );
96
113
97
- return Patch .generate (original , revised , algorithm .computeDiff (original , revised , progress ));
114
+ return Patch .generate (original , revised , algorithm .computeDiff (original , revised , progress ), includeEqualParts );
98
115
}
99
-
116
+
100
117
/**
101
- * Computes the difference between the original and revised list of elements with default diff algorithm
118
+ * Computes the difference between the original and revised list of elements with default diff
119
+ * algorithm
102
120
*
103
121
* @param original The original text. Must not be {@code null}.
104
122
* @param revised The revised text. Must not be {@code null}.
105
123
* @param algorithm The diff algorithm. Must not be {@code null}.
106
- * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
124
+ * @return The patch describing the difference between the original and revised sequences. Never
125
+ * {@code null}.
107
126
*/
108
- public static <T > Patch <T > diff (List <T > original , List <T > revised ,
109
- DiffAlgorithmI <T > algorithm ) {
110
- return diff (original , revised , algorithm , null );
111
- }
127
+ public static <T > Patch <T > diff (List <T > original , List <T > revised , DiffAlgorithmI <T > algorithm ) {
128
+ return diff (original , revised , algorithm , null );
129
+ }
112
130
113
131
/**
114
- * Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of
115
- * characters, like DiffRowGenerator does and merges those changes at the end together again.
132
+ * Computes the difference between the given texts inline. This one uses the "trick" to make out
133
+ * of texts lists of characters, like DiffRowGenerator does and merges those changes at the end
134
+ * together again.
116
135
*
117
136
* @param original
118
137
* @param revised
0 commit comments