Package com.logicaldoc.comparison.basic
Class DiffMatch
java.lang.Object
com.logicaldoc.comparison.basic.DiffMatch
Class containing the diff, match and patch methods. Also contains the
behaviour settings.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class representing one diff operation.static enum
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.")} which means: delete "Hello", add "Goodbye" and keep " world."static class
Class representing one patch operation. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
diffCommonPrefix
(String text1, String text2) Determine the common prefix of two stringsint
diffCommonSuffix
(String text1, String text2) Determine the common suffix of two stringsdiffFromDelta
(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.Find the differences between two texts.Find the differences between two texts.diffPrettyHtml
(List<DiffMatch.Diff> diffs) Convert a Diff list into a pretty HTML report.int
Locate the best instance of 'pattern' in 'text' near 'loc'.patchFromText
(String textline) Parse a textual representation of patches and return a List of Patch objects.Compute a list of patches to turn text1 into text2.patchToText
(List<DiffMatch.Patch> patches) Take a list of patches and return a textual representation.
-
Constructor Details
-
DiffMatch
public DiffMatch()
-
-
Method Details
-
diffMain
Find the differences between two texts. Run a faster, slightly less optimal diff. This method allows the 'checklines' of diff_main() to be optional. Most of the time checklines is wanted, so default to true.- Parameters:
text1
- Old string to be diffed.text2
- New string to be diffed.- Returns:
- Linked List of Diff objects.
-
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.
-
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.
-
diffPrettyHtml
Convert a Diff list into a pretty HTML report.- Parameters:
diffs
- LinkedList of Diff objects.- Returns:
- HTML representation.
-
diffFromDelta
public List<DiffMatch.Diff> diffFromDelta(String text1, String delta) throws IllegalArgumentException, UnsupportedEncodingException Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.- Parameters:
text1
- Source string for the diff.delta
- Delta text.- Returns:
- Array of Diff objects or null if invalid.
- Throws:
IllegalArgumentException
- If invalid input.UnsupportedEncodingException
- The system does not support UTF-8
-
matchMain
Locate the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if no match found.- Parameters:
text
- The text to search.pattern
- The pattern to search for.loc
- The location to search around.- Returns:
- Best match index or -1.
-
patchMake
Compute a list of patches to turn text1 into text2. A set of diffs will be computed.- Parameters:
text1
- Old text.text2
- New text.- Returns:
- LinkedList of Patch objects.
-
patchToText
Take a list of patches and return a textual representation.- Parameters:
patches
- List of Patch objects.- Returns:
- Text representation of patches.
-
patchFromText
public List<DiffMatch.Patch> patchFromText(String textline) throws IllegalArgumentException, UnsupportedEncodingException Parse a textual representation of patches and return a List of Patch objects.- Parameters:
textline
- Text representation of patches.- Returns:
- List of Patch objects.
- Throws:
IllegalArgumentException
- If invalid input.UnsupportedEncodingException
- The system does not support UTF-8
-