diff src/goodjava/util/LineDiff.java @ 1809:90187946d1a4

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 12 May 2024 17:15:33 -0600
parents 69623c62aa34
children
line wrap: on
line diff
--- a/src/goodjava/util/LineDiff.java	Sun May 12 15:58:30 2024 -0600
+++ b/src/goodjava/util/LineDiff.java	Sun May 12 17:15:33 2024 -0600
@@ -13,13 +13,15 @@
 
 	public static class Diff {
 		public final char operation;
-		public final int line;
 		public final String text;
+		public final int lineOld;
+		public final int lineNew;
 
-		private Diff(char operation,String[] lines,int i) {
+		private Diff(char operation,String line,int iOld,int iNew) {
 			this.operation = operation;
-			this.line = i+1;
-			this.text = lines[i];
+			this.text = line;
+			this.lineOld = iOld + 1;
+			this.lineNew = iNew + 1;
 		}
 	}
 
@@ -67,18 +69,22 @@
 				iOld++;
 				iNew++;
 			} else if (opt[iOld+1][iNew] >= opt[iOld][iNew+1]) {
-				diffs.add( new Diff( DELETE, oldLines, iOld++ ) );
+				diffs.add( new Diff( DELETE, oldLines[iOld], iOld, iNew ) );
+				iOld++;
 			} else {
- 				diffs.add( new Diff( INSERT, newLines, iNew++ ) );
+ 				diffs.add( new Diff( INSERT, newLines[iNew], iOld, iNew ) );
+				iNew++;
 			}
 		}
 
 		// dump out one remainder of one string if the other is exhausted
 		while( iOld < nOld ) {
-			diffs.add( new Diff( DELETE, oldLines, iOld++ ) );
+			diffs.add( new Diff( DELETE, oldLines[iOld], iOld, iNew ) );
+			iOld++;
 		}
 		while( iNew < nNew ) {
-			diffs.add( new Diff( INSERT, newLines, iNew++ ) );
+			diffs.add( new Diff( INSERT, newLines[iNew], iOld, iNew ) );
+			iNew++;
 		}
 
 		return diffs;