1717
1818import com .github .difflib .patch .ChangeDelta ;
1919import com .github .difflib .patch .Chunk ;
20- import com .github .difflib .patch .Delta ;
20+ import com .github .difflib .patch .AbstractDelta ;
2121import com .github .difflib .patch .Patch ;
2222import java .util .ArrayList ;
2323import java .util .List ;
@@ -146,21 +146,21 @@ public static List<String> generateUnifiedDiff(String originalFileName,
146146ret .add ("--- " +originalFileName );
147147ret .add ("+++ " +revisedFileName );
148148
149- List <Delta <String >>patchDeltas =new ArrayList <>(
149+ List <AbstractDelta <String >>patchDeltas =new ArrayList <>(
150150patch .getDeltas ());
151151
152152// code outside the if block also works for single-delta issues.
153- List <Delta <String >>deltas =new ArrayList <>();// current
153+ List <AbstractDelta <String >>deltas =new ArrayList <>();// current
154154// list
155155// of
156156// Delta's to
157157// process
158- Delta <String >delta =patchDeltas .get (0 );
158+ AbstractDelta <String >delta =patchDeltas .get (0 );
159159deltas .add (delta );// add the first Delta to the current set
160160// if there's more than 1 Delta, we may need to output them together
161161if (patchDeltas .size () >1 ) {
162162for (int i =1 ;i <patchDeltas .size ();i ++) {
163- int position =delta .getOriginal ().getPosition ();// store
163+ int position =delta .getSource ().getPosition ();// store
164164// the
165165// current
166166// position
@@ -170,9 +170,9 @@ public static List<String> generateUnifiedDiff(String originalFileName,
170170// Check if the next Delta is too close to the current
171171// position.
172172// And if it is, add it to the current set
173- Delta <String >nextDelta =patchDeltas .get (i );
174- if ((position +delta .getOriginal ().size () +contextSize ) >= (nextDelta
175- .getOriginal ().getPosition () -contextSize )) {
173+ AbstractDelta <String >nextDelta =patchDeltas .get (i );
174+ if ((position +delta .getSource ().size () +contextSize ) >= (nextDelta
175+ .getSource ().getPosition () -contextSize )) {
176176deltas .add (nextDelta );
177177 }else {
178178// if it isn't, output the current set,
@@ -207,65 +207,65 @@ public static List<String> generateUnifiedDiff(String originalFileName,
207207 * @author Bill James (tankerbay@gmail.com)
208208 */
209209private static List <String >processDeltas (List <String >origLines ,
210- List <Delta <String >>deltas ,int contextSize ) {
210+ List <AbstractDelta <String >>deltas ,int contextSize ) {
211211List <String >buffer =new ArrayList <>();
212212int origTotal =0 ;// counter for total lines output from Original
213213int revTotal =0 ;// counter for total lines output from Original
214214int line ;
215215
216- Delta <String >curDelta =deltas .get (0 );
216+ AbstractDelta <String >curDelta =deltas .get (0 );
217217
218218// NOTE: +1 to overcome the 0-offset Position
219- int origStart =curDelta .getOriginal ().getPosition () +1 -contextSize ;
219+ int origStart =curDelta .getSource ().getPosition () +1 -contextSize ;
220220if (origStart <1 ) {
221221origStart =1 ;
222222 }
223223
224- int revStart =curDelta .getRevised ().getPosition () +1 -contextSize ;
224+ int revStart =curDelta .getTarget ().getPosition () +1 -contextSize ;
225225if (revStart <1 ) {
226226revStart =1 ;
227227 }
228228
229229// find the start of the wrapper context code
230- int contextStart =curDelta .getOriginal ().getPosition () -contextSize ;
230+ int contextStart =curDelta .getSource ().getPosition () -contextSize ;
231231if (contextStart <0 ) {
232232contextStart =0 ;// clamp to the start of the file
233233 }
234234
235235// output the context before the first Delta
236- for (line =contextStart ;line <curDelta .getOriginal ().getPosition ();line ++) {//
236+ for (line =contextStart ;line <curDelta .getSource ().getPosition ();line ++) {//
237237buffer .add (" " +origLines .get (line ));
238238origTotal ++;
239239revTotal ++;
240240 }
241241
242242// output the first Delta
243243buffer .addAll (getDeltaText (curDelta ));
244- origTotal +=curDelta .getOriginal ().getLines ().size ();
245- revTotal +=curDelta .getRevised ().getLines ().size ();
244+ origTotal +=curDelta .getSource ().getLines ().size ();
245+ revTotal +=curDelta .getTarget ().getLines ().size ();
246246
247247int deltaIndex =1 ;
248248while (deltaIndex <deltas .size ()) {// for each of the other Deltas
249- Delta <String >nextDelta =deltas .get (deltaIndex );
250- int intermediateStart =curDelta .getOriginal ().getPosition ()
251- +curDelta .getOriginal ().getLines ().size ();
252- for (line =intermediateStart ;line <nextDelta .getOriginal ()
249+ AbstractDelta <String >nextDelta =deltas .get (deltaIndex );
250+ int intermediateStart =curDelta .getSource ().getPosition ()
251+ +curDelta .getSource ().getLines ().size ();
252+ for (line =intermediateStart ;line <nextDelta .getSource ()
253253 .getPosition ();line ++) {
254254// output the code between the last Delta and this one
255255buffer .add (" " +origLines .get (line ));
256256origTotal ++;
257257revTotal ++;
258258 }
259259buffer .addAll (getDeltaText (nextDelta ));// output the Delta
260- origTotal +=nextDelta .getOriginal ().getLines ().size ();
261- revTotal +=nextDelta .getRevised ().getLines ().size ();
260+ origTotal +=nextDelta .getSource ().getLines ().size ();
261+ revTotal +=nextDelta .getTarget ().getLines ().size ();
262262curDelta =nextDelta ;
263263deltaIndex ++;
264264 }
265265
266266// Now output the post-Delta context code, clamping the end of the file
267- contextStart =curDelta .getOriginal ().getPosition ()
268- +curDelta .getOriginal ().getLines ().size ();
267+ contextStart =curDelta .getSource ().getPosition ()
268+ +curDelta .getSource ().getLines ().size ();
269269for (line =contextStart ; (line < (contextStart +contextSize ))
270270 && (line <origLines .size ());line ++) {
271271buffer .add (" " +origLines .get (line ));
@@ -275,7 +275,7 @@ private static List<String> processDeltas(List<String> origLines,
275275
276276// Create and insert the block header, conforming to the Unified Diff
277277// standard
278- StringBuffer header =new StringBuffer ();
278+ StringBuilder header =new StringBuilder ();
279279header .append ("@@ -" );
280280header .append (origStart );
281281header .append ("," );
@@ -297,12 +297,12 @@ private static List<String> processDeltas(List<String> origLines,
297297 * @return list of String lines of code.
298298 * @author Bill James (tankerbay@gmail.com)
299299 */
300- private static List <String >getDeltaText (Delta <String >delta ) {
300+ private static List <String >getDeltaText (AbstractDelta <String >delta ) {
301301List <String >buffer =new ArrayList <>();
302- for (String line :delta .getOriginal ().getLines ()) {
302+ for (String line :delta .getSource ().getLines ()) {
303303buffer .add ("-" +line );
304304 }
305- for (String line :delta .getRevised ().getLines ()) {
305+ for (String line :delta .getTarget ().getLines ()) {
306306buffer .add ("+" +line );
307307 }
308308return buffer ;