Class DiffMatchPatch

java.lang.Object
com.jsql.model.injection.strategy.blind.patch.DiffMatchPatch

public class DiffMatchPatch extends Object
Class containing the diff, match and patch methods. Also contains the behaviour settings.
  • Field Details

    • DIFF_TIMEOUT

      public static final float DIFF_TIMEOUT
      Number of seconds to map a diff before giving up (0 for infinity).
      See Also:
    • DIFF_EDIT_COST

      public static final short DIFF_EDIT_COST
      Cost of an empty edit operation in terms of edit characters.
      See Also:
  • Constructor Details

    • DiffMatchPatch

      public DiffMatchPatch()
  • Method Details

    • diffMain

      public LinkedList<Diff> diffMain(String text1, String text2, boolean checklines)
      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

      protected 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. 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

      protected DiffMatchPatch.LinesToCharsResult diffLinesToChars(String text1, String text2)
      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

      protected void diffCharsToLines(List<Diff> diffs, List<String> lineArray)
      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

      public int diffCommonPrefix(String text1, String text2)
      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

      public int diffCommonSuffix(String text1, String text2)
      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

      protected int diffCommonOverlap(String valueText1, String valueText2)
      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

      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? 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

      public void diffCleanupSemantic(LinkedList<Diff> diffs)
      Reduce the number of edits by eliminating semantically trivial equalities.
      Parameters:
      diffs - LinkedList of Diff objects.
    • diffCleanupSemanticLossless

      public void diffCleanupSemanticLossless(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. e.g: The cat came. -> The cat came.
      Parameters:
      diffs - LinkedList of Diff objects.
    • diffCleanupEfficiency

      public void diffCleanupEfficiency(LinkedList<Diff> diffs)
      Reduce the number of edits by eliminating operationally trivial equalities.
      Parameters:
      diffs - LinkedList of Diff objects.
    • diffCleanupMerge

      public void diffCleanupMerge(LinkedList<Diff> diffs)
      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.