1515 */
1616package com .github .difflib ;
1717
18+ import com .github .difflib .algorithm .DiffAlgorithmFactory ;
1819import com .github .difflib .algorithm .DiffAlgorithmI ;
1920import com .github .difflib .algorithm .DiffAlgorithmListener ;
20- import com .github .difflib .algorithm .myers .MyersDiff ;
21+ import com .github .difflib .algorithm .myers .MeyersDiff ;
2122import com .github .difflib .patch .AbstractDelta ;
2223import com .github .difflib .patch .Patch ;
2324import com .github .difflib .patch .PatchFailedException ;
3435public final class DiffUtils {
3536
3637/**
37- * Computes the difference between the original and revised list of elements with default diff
38- * algorithm
38+ * This factory generates the DEFAULT_DIFF algorithm for all these routines.
39+ */
40+ static DiffAlgorithmFactory DEFAULT_DIFF =MeyersDiff .factory ();
41+
42+ public static void withDefaultDiffAlgorithmFactory (DiffAlgorithmFactory factory ) {
43+ DEFAULT_DIFF =factory ;
44+ }
45+
46+ /**
47+ * Computes the difference between the original and revised list of elements
48+ * with default diff algorithm
3949 *
4050 * @param <T> types to be diffed
4151 * @param original The original text. Must not be {@code null}.
4252 * @param revised The revised text. Must not be {@code null}.
4353 * @param progress progress listener
44- * @return The patch describing the difference between the original and revised sequences. Never
45- * {@code null}.
54+ * @return The patch describing the difference between the original and
55+ *revised sequences. Never {@code null}.
4656 */
4757public static <T >Patch <T >diff (List <T >original ,List <T >revised ,DiffAlgorithmListener progress ) {
48- return DiffUtils .diff (original ,revised ,new MyersDiff <> (),progress );
58+ return DiffUtils .diff (original ,revised ,DEFAULT_DIFF . create (),progress );
4959 }
5060
5161public static <T >Patch <T >diff (List <T >original ,List <T >revised ) {
52- return DiffUtils .diff (original ,revised ,new MyersDiff <> (),null );
62+ return DiffUtils .diff (original ,revised ,DEFAULT_DIFF . create (),null );
5363 }
54-
64+
5565public static <T >Patch <T >diff (List <T >original ,List <T >revised ,boolean includeEqualParts ) {
56- return DiffUtils .diff (original ,revised ,new MyersDiff <> (),null ,includeEqualParts );
66+ return DiffUtils .diff (original ,revised ,DEFAULT_DIFF . create (),null ,includeEqualParts );
5767 }
5868
5969/**
@@ -67,45 +77,46 @@ public static Patch<String> diff(String sourceText, String targetText,
6777 }
6878
6979/**
70- * Computes the difference between the original and revised list of elements with default diff
71- * algorithm
80+ * Computes the difference between the original and revised list of elements
81+ *with default diff algorithm
7282 *
7383 * @param source The original text. Must not be {@code null}.
7484 * @param target The revised text. Must not be {@code null}.
7585 *
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}.
86+ * @param equalizer the equalizer object to replace the default compare
87+ * algorithm (Object.equals). If {@code null} the default equalizer of the
88+ * default algorithm is used..
89+ * @return The patch describing the difference between the original and
90+ * revised sequences. Never {@code null}.
8091 */
8192public static <T >Patch <T >diff (List <T >source ,List <T >target ,
8293BiPredicate <T ,T >equalizer ) {
8394if (equalizer !=null ) {
8495return DiffUtils .diff (source ,target ,
85- new MyersDiff <> (equalizer ));
96+ DEFAULT_DIFF . create (equalizer ));
8697 }
87- return DiffUtils .diff (source ,target ,new MyersDiff <>());
98+ return DiffUtils .diff (source ,target ,new MeyersDiff <>());
8899 }
89100
90101public static <T >Patch <T >diff (List <T >original ,List <T >revised ,
91102DiffAlgorithmI <T >algorithm ,DiffAlgorithmListener progress ) {
92103return diff (original ,revised ,algorithm ,progress ,false );
93104 }
94-
105+
95106/**
96- * Computes the difference between the original and revised list of elements with default diff
97- * algorithm
107+ * Computes the difference between the original and revised list of elements
108+ *with default diff algorithm
98109 *
99110 * @param original The original text. Must not be {@code null}.
100111 * @param revised The revised text. Must not be {@code null}.
101112 * @param algorithm The diff algorithm. Must not be {@code null}.
102113 * @param progress The diff algorithm listener.
103114 * @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}.
115+ * @return The patch describing the difference between the original and
116+ *revised sequences. Never {@code null}.
106117 */
107118public static <T >Patch <T >diff (List <T >original ,List <T >revised ,
108- DiffAlgorithmI <T >algorithm ,DiffAlgorithmListener progress ,
119+ DiffAlgorithmI <T >algorithm ,DiffAlgorithmListener progress ,
109120boolean includeEqualParts ) {
110121Objects .requireNonNull (original ,"original must not be null" );
111122Objects .requireNonNull (revised ,"revised must not be null" );
@@ -115,23 +126,23 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
115126 }
116127
117128/**
118- * Computes the difference between the original and revised list of elements with default diff
119- * algorithm
129+ * Computes the difference between the original and revised list of elements
130+ *with default diff algorithm
120131 *
121132 * @param original The original text. Must not be {@code null}.
122133 * @param revised The revised text. Must not be {@code null}.
123134 * @param algorithm The diff algorithm. Must not be {@code null}.
124- * @return The patch describing the difference between the original and revised sequences. Never
125- * {@code null}.
135+ * @return The patch describing the difference between the original and
136+ *revised sequences. Never {@code null}.
126137 */
127138public static <T >Patch <T >diff (List <T >original ,List <T >revised ,DiffAlgorithmI <T >algorithm ) {
128139return diff (original ,revised ,algorithm ,null );
129140 }
130141
131142/**
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.
143+ * Computes the difference between the given texts inline. This one uses the
144+ *"trick" to make out of texts lists of characters, like DiffRowGenerator
145+ *does and merges those changes at the end together again.
135146 *
136147 * @param original
137148 * @param revised