Mercurial Hosting > luan
comparison src/goodjava/util/LineDiff.java @ 1808:69623c62aa34
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 May 2024 15:58:30 -0600 |
parents | ffa28e2155bb |
children | 90187946d1a4 |
comparison
equal
deleted
inserted
replaced
1807:ffa28e2155bb | 1808:69623c62aa34 |
---|---|
14 public static class Diff { | 14 public static class Diff { |
15 public final char operation; | 15 public final char operation; |
16 public final int line; | 16 public final int line; |
17 public final String text; | 17 public final String text; |
18 | 18 |
19 private Diff(char operation,int line,String text) { | 19 private Diff(char operation,String[] lines,int i) { |
20 this.operation = operation; | 20 this.operation = operation; |
21 this.line = line; | 21 this.line = i+1; |
22 this.text = text; | 22 this.text = lines[i]; |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 public static String[] stringToLines(String s) { | 26 public static String[] stringToLines(String s) { |
27 List<String> list = new ArrayList<String>(); | 27 List<String> list = new ArrayList<String>(); |
65 while (iOld < nOld && iNew < nNew) { | 65 while (iOld < nOld && iNew < nNew) { |
66 if (oldLines[iOld].equals(newLines[iNew])) { | 66 if (oldLines[iOld].equals(newLines[iNew])) { |
67 iOld++; | 67 iOld++; |
68 iNew++; | 68 iNew++; |
69 } else if (opt[iOld+1][iNew] >= opt[iOld][iNew+1]) { | 69 } else if (opt[iOld+1][iNew] >= opt[iOld][iNew+1]) { |
70 diffs.add( new Diff( DELETE, iOld+1, oldLines[iOld] ) ); | 70 diffs.add( new Diff( DELETE, oldLines, iOld++ ) ); |
71 iOld++; | |
72 } else { | 71 } else { |
73 diffs.add( new Diff( INSERT, iOld+1, newLines[iNew] ) ); | 72 diffs.add( new Diff( INSERT, newLines, iNew++ ) ); |
74 iNew++; | |
75 } | 73 } |
76 } | 74 } |
77 | 75 |
78 // dump out one remainder of one string if the other is exhausted | 76 // dump out one remainder of one string if the other is exhausted |
79 while( iOld < nOld ) { | 77 while( iOld < nOld ) { |
80 diffs.add( new Diff( DELETE, iOld+1, oldLines[iOld] ) ); | 78 diffs.add( new Diff( DELETE, oldLines, iOld++ ) ); |
81 iOld++; | |
82 } | 79 } |
83 while( iNew < nNew ) { | 80 while( iNew < nNew ) { |
84 diffs.add( new Diff( INSERT, nOld+1, newLines[iNew] ) ); | 81 diffs.add( new Diff( INSERT, newLines, iNew++ ) ); |
85 iNew++; | |
86 } | 82 } |
87 | 83 |
88 return diffs; | 84 return diffs; |
89 } | 85 } |
90 } | 86 } |