29
29
import java .util .ListIterator ;
30
30
31
31
/**
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
+ *
34
35
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
35
36
* @param <T> The type of the compared elements in the 'lines'.
36
37
*/
@@ -57,10 +58,25 @@ public List<T> applyTo(List<T> target) throws PatchFailedException {
57
58
ListIterator <AbstractDelta <T >> it = getDeltas ().listIterator (deltas .size ());
58
59
while (it .hasPrevious ()) {
59
60
AbstractDelta <T > delta = it .previous ();
60
- delta .verifyAntApplyTo (result );
61
+ VerifyChunk valid = delta .verifyAntApplyTo (result );
62
+ if (valid != VerifyChunk .OK ) {
63
+
64
+ }
61
65
}
62
66
return result ;
63
67
}
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
+ }
64
80
65
81
/**
66
82
* 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
114
130
Patch <T > patch = new Patch <>(_changes .size ());
115
131
int startOriginal = 0 ;
116
132
int startRevised = 0 ;
117
-
133
+
118
134
List <Change > changes = _changes ;
119
-
135
+
120
136
if (includeEquals ) {
121
137
changes = new ArrayList <Change >(_changes );
122
138
Collections .sort (changes , comparing (d -> d .startOriginal ));
123
139
}
124
-
140
+
125
141
for (Change change : changes ) {
126
142
127
143
if (includeEquals && startOriginal < change .startOriginal ) {
0 commit comments