Class DiffMatchPatch
java.lang.Object
com.jsql.model.injection.strategy.blind.patch.DiffMatchPatch
Class containing the diff, match and patch methods.
Also contains the behaviour settings.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordInternal class for returning results from diff_linesToChars().static enumThe data structure representing a diff is a Linked list of Diff objects: {Diff(Operation.DELETE, "Hello"), Diff(Operation.INSERT, "Goodbye"), Diff(Operation.EQUAL, " world.")} -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortCost of an empty edit operation in terms of edit characters.static final floatNumber of seconds to map a diff before giving up (0 for infinity). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected LinkedList<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 voiddiffCharsToLines(List<Diff> diffs, List<String> lineArray) Rehydrate the text in a diff from a string of line hashes to real lines of text.voiddiffCleanupEfficiency(LinkedList<Diff> diffs) Reduce the number of edits by eliminating operationally trivial equalities.voiddiffCleanupMerge(LinkedList<Diff> diffs) Reorder and merge like edit sections.voiddiffCleanupSemantic(LinkedList<Diff> diffs) Reduce the number of edits by eliminating semantically trivial equalities.voiddiffCleanupSemanticLossless(List<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 intdiffCommonOverlap(String valueText1, String valueText2) Determine if the suffix of one string is the prefix of another.intdiffCommonPrefix(String text1, String text2) Determine the common prefix of two stringsintdiffCommonSuffix(String text1, String text2) Determine the common suffix of two stringsprotected String[]diffHalfMatch(String text1, String text2) Do the two texts share a substring which is at least half the length of the longer text?protected DiffMatchPatch.LinesToCharsResultdiffLinesToChars(String text1, String text2) Split two texts into a list of strings.Find the differences between two texts.
-
Field Details
-
DIFF_TIMEOUT
public static final float DIFF_TIMEOUTNumber of seconds to map a diff before giving up (0 for infinity).- See Also:
-
DIFF_EDIT_COST
public static final short DIFF_EDIT_COSTCost of an empty edit operation in terms of edit characters.- See Also:
-
-
Constructor Details
-
DiffMatchPatch
public DiffMatchPatch()
-
-
Method Details
-
diffMain
Find the differences between two texts.- Parameters:
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.- Returns:
- Linked List of Diff objects.
-
diffBisect
Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.- Parameters:
text1- Old string to be diffed.text2- New string to be diffed.deadline- Time at which to bail if not yet complete.- Returns:
- LinkedList of Diff objects.
-
diffLinesToChars
Split two texts into a list of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.- Parameters:
text1- First string.text2- Second string.- Returns:
- An object containing the encoded text1, the encoded text2 and the List of unique strings. The zeroth element of the List of unique strings is intentionally blank.
-
diffCharsToLines
Rehydrate the text in a diff from a string of line hashes to real lines of text.- Parameters:
diffs- LinkedList of Diff objects.lineArray- List of unique strings.
-
diffCommonPrefix
Determine the common prefix of two strings- Parameters:
text1- First string.text2- Second string.- Returns:
- The number of characters common to the start of each string.
-
diffCommonSuffix
Determine the common suffix of two strings- Parameters:
text1- First string.text2- Second string.- Returns:
- The number of characters common to the end of each string.
-
diffCommonOverlap
Determine if the suffix of one string is the prefix of another.- Parameters:
valueText1- First string.valueText2- Second string.- Returns:
- The number of characters common to the end of the first string and the start of the second string.
-
diffHalfMatch
Do the two texts share a substring which is at least half the length of the longer text? This speedup can produce non-minimal diffs.- Parameters:
text1- First string.text2- Second string.- Returns:
- Five element String array, containing the prefix of text1, the suffix of text1, the prefix of text2, the suffix of text2 and the common middle. Or null if there was no match.
-
diffCleanupSemantic
Reduce the number of edits by eliminating semantically trivial equalities.- Parameters:
diffs- LinkedList of Diff objects.
-
diffCleanupSemanticLossless
Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary. e.g: The cat came. -> The cat came.- Parameters:
diffs- LinkedList of Diff objects.
-
diffCleanupEfficiency
Reduce the number of edits by eliminating operationally trivial equalities.- Parameters:
diffs- LinkedList of Diff objects.
-
diffCleanupMerge
Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality.- Parameters:
diffs- LinkedList of Diff objects.
-