public class DiffMatchPatch extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DiffMatchPatch.Builder |
static class |
DiffMatchPatch.Diff
Class representing one diff operation.
|
protected static class |
DiffMatchPatch.LinesToCharsResult
Internal class for returning results from diffLinesToChars().
|
static class |
DiffMatchPatch.Operation
The data structure representing a diff is a Linked list of Diff objects:
{Diff(Operation.DELETE, "Hello"), Diff(Operation.INSERT, "Goodbye"),
Diff(Operation.EQUAL, " world.")}
|
static class |
DiffMatchPatch.Patch
Class representing one patch operation.
|
Modifier and Type | Method and Description |
---|---|
static DiffMatchPatch.Builder |
builder() |
static String |
checksum(String content) |
void |
diff_cleanupSemantic(LinkedList<DiffMatchPatch.Diff> diffs)
Reduce the number of edits by eliminating semantically trivial equalities.
|
static DiffMatchPatch.Diff |
diff(DiffMatchPatch.Operation operation,
String text) |
protected LinkedList<DiffMatchPatch.Diff> |
diffBisect(String text1,
String text2,
long deadline)
Find the 'middle snake' of a diff, split the problem in two
and return the recursively constructed diff.
|
protected void |
diffCharsToLines(LinkedList<DiffMatchPatch.Diff> diffs,
List<String> lineArray)
Rehydrate the text in a diff from a string of line hashes to real lines of
text.
|
void |
diffCleanupEfficiency(LinkedList<DiffMatchPatch.Diff> diffs)
Reduce the number of edits by eliminating operationally trivial equalities.
|
void |
diffCleanupMerge(LinkedList<DiffMatchPatch.Diff> diffs)
Reorder and merge like edit sections.
|
void |
diffCleanupSemanticLossLess(LinkedList<DiffMatchPatch.Diff> diffs)
Look for single edits surrounded on both sides by equalities
which can be shifted sideways to align the edit to a word boundary.
|
protected int |
diffCommonOverlap(String text1,
String text2)
Determine if the suffix of one string is the prefix of another.
|
int |
diffCommonPrefix(String text1,
String text2)
Determine the common prefix of two strings
|
int |
diffCommonSuffix(String text1,
String text2)
Determine the common suffix of two strings
|
short |
diffEditCost() |
LinkedList<DiffMatchPatch.Diff> |
diffFromDelta(String text1,
String delta)
Given the original text1, and an encoded string which describes the
operations required to transform text1 into text2, compute the full diff.
|
protected String[] |
diffHalfMatch(String text1,
String text2)
Do the two texts share a substring which is at least half the length of
the longer text?
|
int |
diffLevenshtein(LinkedList<DiffMatchPatch.Diff> diffs)
Compute the Levenshtein matchDistance; the number of inserted, deleted or
substituted characters.
|
protected DiffMatchPatch.LinesToCharsResult |
diffLinesToChars(String text1,
String text2)
Split two texts into a list of strings.
|
LinkedList<DiffMatchPatch.Diff> |
diffMain(String text1,
String text2)
Find the differences between two texts.
|
LinkedList<DiffMatchPatch.Diff> |
diffMain(String text1,
String text2,
boolean checklines)
Find the differences between two texts.
|
String |
diffPretyyHtml(LinkedList<DiffMatchPatch.Diff> diffs)
Convert a Diff list into a pretty HTML report.
|
String |
diffText1(LinkedList<DiffMatchPatch.Diff> diffs)
Compute and return the source text (all equalities and deletions).
|
String |
diffText2(LinkedList<DiffMatchPatch.Diff> diffs)
Compute and return the destination text (all equalities and insertions).
|
float |
diffTimeout() |
String |
diffToDelta(LinkedList<DiffMatchPatch.Diff> diffs)
Crush the diff into an encoded string which describes the operations
required to transform text1 into text2.
|
int |
diffXIndex(LinkedList<DiffMatchPatch.Diff> diffs,
int loc)
loc is a location in text1, compute and return the equivalent location in
text2.
|
protected Map<Character,Integer> |
matchAlpabet(String pattern)
Initialise the alphabet for the Bitap algorithm.
|
protected int |
matchBitmap(String text,
String pattern,
int loc)
Locate the best instance of 'pattern' in 'text' near 'loc' using the
Bitap algorithm.
|
int |
matchDistance() |
int |
matchMain(String text,
String pattern,
int loc)
Locate the best instance of 'pattern' in 'text' near 'loc'.
|
float |
matchThreshold() |
LinkedList<DiffMatchPatch.Patch> |
patch_deepCopy(LinkedList<DiffMatchPatch.Patch> patches)
Given an array of patches, return another array that is identical.
|
protected void |
patchAddContext(DiffMatchPatch.Patch patch,
String text)
Increase the context until it is unique,
but don't let the pattern expand beyond matchMaxbits.
|
String |
patchAddPadding(LinkedList<DiffMatchPatch.Patch> patches)
Add some padding on text start and end so that edges can match something.
|
Object[] |
patchApply(LinkedList<DiffMatchPatch.Patch> patches,
String text)
Merge a set of patches onto the text.
|
float |
patchDeleteThreshold() |
List<DiffMatchPatch.Patch> |
patchFromText(String textline)
Parse a textual representation of patches and return a List of Patch
objects.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(LinkedList<DiffMatchPatch.Diff> diffs)
Compute a list of patches to turn text1 into text2.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(String text1,
LinkedList<DiffMatchPatch.Diff> diffs)
Compute a list of patches to turn text1 into text2.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(String text1,
String text2)
Compute a list of patches to turn text1 into text2.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(String text1,
String text2,
LinkedList<DiffMatchPatch.Diff> diffs)
Deprecated.
|
short |
patchMargin() |
short |
patchMaxbits() |
void |
patchSplitMax(LinkedList<DiffMatchPatch.Patch> patches)
Look through the patches and break up any which are longer than the
maximum limit of the match algorithm.
|
String |
patchToText(List<DiffMatchPatch.Patch> patches)
Take a list of patches and return a textual representation.
|
public float diffTimeout()
public short diffEditCost()
public float matchThreshold()
public int matchDistance()
public float patchDeleteThreshold()
public short patchMargin()
public short patchMaxbits()
public static DiffMatchPatch.Builder builder()
public static DiffMatchPatch.Diff diff(DiffMatchPatch.Operation operation, String text)
public LinkedList<DiffMatchPatch.Diff> diffMain(String text1, String text2)
text1
- Old string to be diffed.text2
- New string to be diffed.public LinkedList<DiffMatchPatch.Diff> diffMain(String text1, String text2, boolean checklines)
text1
- Old string to be diffed.text2
- New string to be diffed.checklines
- Speedup flag. If false, then don't run a
line-level diff first to identify the changed areas.
If true, then run a faster slightly less optimal diff.protected LinkedList<DiffMatchPatch.Diff> diffBisect(String text1, String text2, long deadline)
text1
- Old string to be diffed.text2
- New string to be diffed.deadline
- Time at which to bail if not yet complete.protected DiffMatchPatch.LinesToCharsResult diffLinesToChars(String text1, String text2)
text1
- First string.text2
- Second string.protected void diffCharsToLines(LinkedList<DiffMatchPatch.Diff> diffs, List<String> lineArray)
diffs
- LinkedList of Diff objects.lineArray
- List of unique strings.public int diffCommonPrefix(String text1, String text2)
text1
- First string.text2
- Second string.public int diffCommonSuffix(String text1, String text2)
text1
- First string.text2
- Second string.protected int diffCommonOverlap(String text1, String text2)
text1
- First string.text2
- Second string.protected String[] diffHalfMatch(String text1, String text2)
text1
- First string.text2
- Second string.public void diff_cleanupSemantic(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public void diffCleanupSemanticLossLess(LinkedList<DiffMatchPatch.Diff> diffs)
The c<ins>at c</ins>ame. -> The <ins>cat </ins>came
.diffs
- LinkedList of Diff objects.public void diffCleanupEfficiency(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public void diffCleanupMerge(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public int diffXIndex(LinkedList<DiffMatchPatch.Diff> diffs, int loc)
"The cat" vs "The big cat", 1->1, 5->8
diffs
- LinkedList of Diff objects.loc
- Location within text1.public String diffPretyyHtml(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public String diffText1(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public String diffText2(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public int diffLevenshtein(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- LinkedList of Diff objects.public String diffToDelta(LinkedList<DiffMatchPatch.Diff> diffs)
=3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'.
Operations are tab-separated. Inserted text is escaped using %xx notation.diffs
- Array of Diff objects.public LinkedList<DiffMatchPatch.Diff> diffFromDelta(String text1, String delta) throws IllegalArgumentException
text1
- Source string for the diff.delta
- Delta text.IllegalArgumentException
- If invalid input.public int matchMain(String text, String pattern, int loc)
text
- The text to search.pattern
- The pattern to search for.loc
- The location to search around.protected int matchBitmap(String text, String pattern, int loc)
text
- The text to search.pattern
- The pattern to search for.loc
- The location to search around.protected Map<Character,Integer> matchAlpabet(String pattern)
pattern
- The text to encode.protected void patchAddContext(DiffMatchPatch.Patch patch, String text)
patch
- The patch to grow.text
- Source text.public LinkedList<DiffMatchPatch.Patch> patchMake(String text1, String text2)
text1
- Old text.text2
- New text.public LinkedList<DiffMatchPatch.Patch> patchMake(LinkedList<DiffMatchPatch.Diff> diffs)
diffs
- Array of Diff objects for text1 to text2.public LinkedList<DiffMatchPatch.Patch> patchMake(String text1, String text2, LinkedList<DiffMatchPatch.Diff> diffs)
patchMake(java.lang.String, java.util.LinkedList)
.text1
- Old texttext2
- Ignored.diffs
- Array of Diff objects for text1 to text2.public LinkedList<DiffMatchPatch.Patch> patchMake(String text1, LinkedList<DiffMatchPatch.Diff> diffs)
text1
- Old text.diffs
- Array of Diff objects for text1 to text2.public LinkedList<DiffMatchPatch.Patch> patch_deepCopy(LinkedList<DiffMatchPatch.Patch> patches)
patches
- Array of Patch objects.public Object[] patchApply(LinkedList<DiffMatchPatch.Patch> patches, String text)
patches
- Array of Patch objectstext
- Old text.public String patchAddPadding(LinkedList<DiffMatchPatch.Patch> patches)
patches
- Array of Patch objects.public void patchSplitMax(LinkedList<DiffMatchPatch.Patch> patches)
patches
- LinkedList of Patch objects.public String patchToText(List<DiffMatchPatch.Patch> patches)
patches
- List of Patch objects.public List<DiffMatchPatch.Patch> patchFromText(String textline) throws IllegalArgumentException
textline
- Text representation of patches.IllegalArgumentException
- If invalid input.Copyright © 2015 JBoss by Red Hat. All Rights Reserved.