2929import java .util .ListIterator ;
3030
3131/**
32- * Describes the patch holding all deltas between the original and revised texts.
33- *
32+ * Describes the patch holding all deltas between the original and revised
33+ * texts.
34+ *
3435 * @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
3536 * @param <T> The type of the compared elements in the 'lines'.
3637 */
@@ -57,10 +58,25 @@ public List<T> applyTo(List<T> target) throws PatchFailedException {
5758 ListIterator <AbstractDelta <T >> it = getDeltas ().listIterator (deltas .size ());
5859 while (it .hasPrevious ()) {
5960 AbstractDelta <T > delta = it .previous ();
60- delta .verifyAntApplyTo (result );
61+ VerifyChunk valid = delta .verifyAntApplyTo (result );
62+ if (valid != VerifyChunk .OK ) {
63+
64+ }
6165 }
6266 return result ;
6367 }
68+
69+ private ConflictOutput <T > conflictOutput = (VerifyChunk verifyChunk , AbstractDelta <T > delta , List <T > result ) -> {
70+ throw new PatchFailedException ("could not apply patch due to " + verifyChunk .toString ());
71+ };
72+
73+ /**
74+ * Alter normal conflict output behaviour to e.g. inclide some conflict statements in the result, like git does it.
75+ */
76+ public Patch withConflictOutput (ConflictOutput <T > conflictOutput ) {
77+ this .conflictOutput = conflictOutput ;
78+ return this ;
79+ }
6480
6581 /**
6682 * Restore the text to original. Opposite to applyTo() method.
@@ -114,14 +130,14 @@ public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Chan
114130 Patch <T > patch = new Patch <>(_changes .size ());
115131 int startOriginal = 0 ;
116132 int startRevised = 0 ;
117-
133+
118134 List <Change > changes = _changes ;
119-
135+
120136 if (includeEquals ) {
121137 changes = new ArrayList <Change >(_changes );
122138 Collections .sort (changes , comparing (d -> d .startOriginal ));
123139 }
124-
140+
125141 for (Change change : changes ) {
126142
127143 if (includeEquals && startOriginal < change .startOriginal ) {
0 commit comments