18
18
import difflib .myers .Equalizer ;
19
19
import difflib .myers .MyersDiff ;
20
20
21
+ import java .io .File ;
22
+ import java .io .IOException ;
21
23
import java .util .ArrayList ;
22
24
import java .util .List ;
23
25
import java .util .regex .Matcher ;
24
26
import java .util .regex .Pattern ;
25
27
28
+ import javax .annotation .Nonnull ;
29
+ import javax .annotation .Nullable ;
30
+
31
+ import com .google .common .base .Charsets ;
32
+ import com .google .common .io .Files ;
33
+
26
34
/**
27
35
* Implements the difference and patching engine
28
36
*
@@ -36,6 +44,21 @@ public class DiffUtils {
36
44
private static Pattern unifiedDiffChunkRe = Pattern
37
45
.compile ("^@@\\ s+-(?:(\\ d+)(?:,(\\ d+))?)\\ s+\\ +(?:(\\ d+)(?:,(\\ d+))?)\\ s+@@$" );
38
46
47
+ @ Nonnull
48
+ public Patch <String > diff (@ Nonnull File original , @ Nonnull File revised ) throws IOException {
49
+ return diff (Files .readLines (original , Charsets .UTF_8 ), Files .readLines (revised , Charsets .UTF_8 ));
50
+ }
51
+
52
+ @ Nonnull
53
+ public Patch <String > diff (@ Nonnull File original , @ Nonnull File revised , @ Nonnull DiffAlgorithm <String > algorithm ) throws IOException {
54
+ return diff (Files .readLines (original , Charsets .UTF_8 ), Files .readLines (revised , Charsets .UTF_8 ), algorithm );
55
+ }
56
+
57
+ @ Nonnull
58
+ public Patch <String > diff (@ Nonnull File original , @ Nonnull File revised , @ Nullable Equalizer <String > equalizer ) throws IOException {
59
+ return diff (Files .readLines (original , Charsets .UTF_8 ), Files .readLines (revised , Charsets .UTF_8 ), equalizer );
60
+ }
61
+
39
62
/**
40
63
* Computes the difference between the original and revised list of elements
41
64
* with default diff algorithm
@@ -47,6 +70,7 @@ public class DiffUtils {
47
70
* @return The patch describing the difference between the original and
48
71
* revised sequences. Never {@code null}.
49
72
*/
73
+ @ Nonnull
50
74
public static <T > Patch <T > diff (List <T > original , List <T > revised ) {
51
75
return DiffUtils .diff (original , revised , new MyersDiff <T >());
52
76
}
@@ -67,6 +91,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised) {
67
91
* @return The patch describing the difference between the original and
68
92
* revised sequences. Never {@code null}.
69
93
*/
94
+ @ Nonnull
70
95
public static <T > Patch <T > diff (List <T > original , List <T > revised ,
71
96
Equalizer <T > equalizer ) {
72
97
if (equalizer != null ) {
@@ -89,6 +114,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
89
114
* @return The patch describing the difference between the original and
90
115
* revised sequences. Never {@code null}.
91
116
*/
117
+ @ Nonnull
92
118
public static <T > Patch <T > diff (List <T > original , List <T > revised ,
93
119
DiffAlgorithm <T > algorithm ) {
94
120
if (original == null ) {
@@ -114,6 +140,7 @@ public static <T> Patch<T> diff(List<T> original, List<T> revised,
114
140
* @throws PatchFailedException
115
141
* if can't apply patch
116
142
*/
143
+ @ Nonnull
117
144
public static <T > List <T > patch (List <T > original , Patch <T > patch )
118
145
throws PatchFailedException {
119
146
return patch .applyTo (original );
0 commit comments