/** * 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. * @param text1 Old string to be diffed. * @param text2 New string to be diffed. * @return Linked List of Diff objects. */ public LinkedList<Diff> diff_main(String text1, String text2) { return diff_main(text1, text2, true); }
/** * Find the differences between two texts. * @param text1 Old string to be diffed. * @param text2 New string to be diffed. * @param 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. * @return Linked List of Diff objects. */ public LinkedList<Diff> diff_main(String text1, String text2, boolean checklines) { // Set a deadline by which time the diff must be complete. long deadline; if (Diff_Timeout <= 0) { deadline = Long.MAX_VALUE; } else { deadline = System.currentTimeMillis() + (long) (Diff_Timeout * 1000); } return diff_main(text1, text2, checklines, deadline); }
/** * Given the location of the 'middle snake', split the diff in two parts * and recurse. * @param text1 Old string to be diffed. * @param text2 New string to be diffed. * @param x Index of split point in text1. * @param y Index of split point in text2. * @param deadline Time at which to bail if not yet complete. * @return LinkedList of Diff objects. */ private LinkedList<Diff> diff_bisectSplit(String text1, String text2, int x, int y, long deadline) { String text1a = text1.substring(0, x); String text2a = text2.substring(0, y); String text1b = text1.substring(x); String text2b = text2.substring(y); // Compute both diffs serially. LinkedList<Diff> diffs = diff_main(text1a, text2a, false, deadline); LinkedList<Diff> diffsb = diff_main(text1b, text2b, false, deadline); diffs.addAll(diffsb); return diffs; }
/** * Compute a list of patches to turn text1 into text2. * A set of diffs will be computed. * @param text1 Old text. * @param text2 New text. * @return LinkedList of Patch objects. */ public LinkedList<Patch> patch_make(String text1, String text2) { if (text1 == null || text2 == null) { throw new IllegalArgumentException("Null inputs. (patch_make)"); } // No diffs provided, compute our own. LinkedList<Diff> diffs = diff_main(text1, text2, true); if (diffs.size() > 2) { diff_cleanupSemantic(diffs); diff_cleanupEfficiency(diffs); } return patch_make(text1, diffs); }
protected LinkedList<DiffMatchPatch.Diff> getDiffs(String first, String second) { LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diff_main(cleanupValue(first), cleanupValue(second)); diffMatchPatch.diff_cleanupSemantic(diffs); return diffs; }
LinkedList<Diff> diffs = diff_main(text1, text2, false); if (text1.length() > this.Match_MaxBits && diff_levenshtein(diffs) / (float) text1.length()