public class Diff
extends java.lang.Object
change
objects which form an
edit script. The objects compared are traditionally lines
of text from two files. Comparison options such as "ignore
whitespace" are implemented by modifying the equals
and hashcode
methods for the objects compared.
The basic algorithm is described in:
"An O(ND) Difference Algorithm and its Variations", Eugene Myers, Algorithmica Vol. 1 No. 2, 1986, p 251.
See https://github.com/aymannadeem/speedyscholar/blob/master/an-ond-difference-algorithm-and-its-variations.mdModifier and Type | Class and Description |
---|---|
static class |
Diff.change
The result of comparison is an "edit script": a chain of change objects.
|
class |
Diff.file_data
Data on one input file being compared.
|
Modifier and Type | Field and Description |
---|---|
boolean |
heuristic
When set to true, the comparison uses a heuristic to speed it up.
|
boolean |
no_discards
When set to true, the algorithm returns a guarranteed minimal
set of changes.
|
Constructor and Description |
---|
Diff(java.util.List a,
java.util.List b)
Prepare to find differences between two lists.
|
Diff(java.lang.Object[] a,
java.lang.Object[] b)
Prepare to find differences between two arrays.
|
Diff(java.lang.String a,
java.lang.String b)
Prepare to find differences between two arrays.
|
Modifier and Type | Method and Description |
---|---|
Diff.change |
diff_2()
Report the differences of two files.
|
Diff.change |
diff_2(boolean reverse)
Report the differences of two files.
|
Diff.file_data[] |
getFileData() |
static java.util.List<java.lang.String> |
getLines(java.io.File file)
Return a list of lines from a File.
|
static java.util.List<java.lang.String> |
getLines(java.lang.String s)
Return a list of lines from a String.
|
static java.lang.String[] |
singleChars(java.lang.String s)
Return an array of Strings of one character only from an input String.
|
public boolean heuristic
public boolean no_discards
public Diff(java.lang.String a, java.lang.String b)
equals
.
The original Object arrays are no longer needed for computing the differences. They will be needed again later
to print the results of the comparison as an edit script, if desired.a
- the first Stringb
- the second Stringpublic Diff(java.lang.Object[] a, java.lang.Object[] b)
equals
.
The original Object arrays are no longer needed for computing the differences. They will be needed again later
to print the results of the comparison as an edit script, if desired.a
- the first objectb
- the second objectpublic Diff(java.util.List a, java.util.List b)
a
- the first objectb
- the second objectpublic static final java.lang.String[] singleChars(java.lang.String s)
s
- the input stringpublic static java.util.List<java.lang.String> getLines(java.lang.String s)
s
- the Stringpublic static java.util.List<java.lang.String> getLines(java.io.File file)
file
- the Filepublic Diff.file_data[] getFileData()
public Diff.change diff_2()
public Diff.change diff_2(boolean reverse)
reverse
- if the difference is performed on reverseCopyright © 2016, 2017, 2018, 2019, 2023 Herve Girod. All Rights Reserved. Documentation and source under the MIT licence