3434public final class DiffUtils {
3535
3636 /**
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
3839 *
3940 * @param <T> types to be diffed
4041 * @param original The original text. Must not be {@code null}.
4142 * @param revised The revised text. Must not be {@code null}.
4243 * @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}.
4446 */
4547 public static <T > Patch <T > diff (List <T > original , List <T > revised , DiffAlgorithmListener progress ) {
4648 return DiffUtils .diff (original , revised , new MyersDiff <>(), progress );
4749 }
48-
50+
4951 public static <T > Patch <T > diff (List <T > original , List <T > revised ) {
5052 return DiffUtils .diff (original , revised , new MyersDiff <>(), null );
5153 }
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+ }
5258
5359 /**
5460 * Computes the difference between the original and revised text.
5561 */
5662 public static Patch <String > diff (String sourceText , String targetText ,
5763 DiffAlgorithmListener progress ) {
5864 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 );
6167 }
6268
6369 /**
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
6572 *
6673 * @param source The original text. Must not be {@code null}.
6774 * @param target The revised text. Must not be {@code null}.
6875 *
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}.
7280 */
7381 public static <T > Patch <T > diff (List <T > source , List <T > target ,
7482 BiPredicate <T , T > equalizer ) {
@@ -79,40 +87,51 @@ public static <T> Patch<T> diff(List<T> source, List<T> target,
7987 return DiffUtils .diff (source , target , new MyersDiff <>());
8088 }
8189
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+
8295 /**
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
8498 *
8599 * @param original The original text. Must not be {@code null}.
86100 * @param revised The revised text. Must not be {@code null}.
87101 * @param algorithm The diff algorithm. Must not be {@code null}.
88102 * @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}.
90106 */
91107 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 ) {
93110 Objects .requireNonNull (original , "original must not be null" );
94111 Objects .requireNonNull (revised , "revised must not be null" );
95112 Objects .requireNonNull (algorithm , "algorithm must not be null" );
96113
97- return Patch .generate (original , revised , algorithm .computeDiff (original , revised , progress ));
114+ return Patch .generate (original , revised , algorithm .computeDiff (original , revised , progress ), includeEqualParts );
98115 }
99-
116+
100117 /**
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
102120 *
103121 * @param original The original text. Must not be {@code null}.
104122 * @param revised The revised text. Must not be {@code null}.
105123 * @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}.
107126 */
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+ }
112130
113131 /**
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.
116135 *
117136 * @param original
118137 * @param revised
0 commit comments