/** * Find the differences between two texts. * Run a faster, slightly less optimal diff. * This method allows the 'checklines' of diffMain() 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> diffMain(String text1, String text2) { return diffMain(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> diffMain(String text1, String text2, boolean checklines) { // Set a deadline by which time the diff must be complete. long deadline; if (diffTimeout <= 0) { deadline = Long.MAX_VALUE; } else { deadline = System.currentTimeMillis() + (long) (diffTimeout * 1000); } return diffMain(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> diffBisectSplit(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 = diffMain(text1a, text2a, false, deadline); LinkedList<Diff> diffsb = diffMain(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> patchMake(String text1, String text2) { if (text1 == null || text2 == null) { throw new IllegalArgumentException("Null inputs. (patchMake)"); } // No diffs provided, compute our own. LinkedList<Diff> diffs = diffMain(text1, text2, true); if (diffs.size() > 2) { diff_cleanupSemantic(diffs); diffCleanupEfficiency(diffs); } return patchMake(text1, diffs); }
LinkedList<DiffMatchPatch.Diff> diffs = diffMain(text1, text2, false); if (text1.length() > this.matchMaxbits && diffLevenshtein(diffs) / (float) text1.length()
@Override public DiffMatchPatchEdit clientDiff(final Document<String> document, final ShadowDocument<String> shadowDocument) { final String shadowText = shadowDocument.document().content(); final LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diffMain(document.content(), shadowText); return DiffMatchPatchEdit.withChecksum(checksum(shadowText)).diffs(asAeroGearDiffs(diffs)).build(); }
@Override public DiffMatchPatchEdit serverDiff(final Document<String> document, final ShadowDocument<String> shadowDocument) { final String shadowText = shadowDocument.document().content(); final LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diffMain(shadowText, document.content()); return DiffMatchPatchEdit.withChecksum(checksum(shadowText)) .serverVersion(shadowDocument.serverVersion()) .clientVersion(shadowDocument.clientVersion()) .diffs(asAeroGearDiffs(diffs)) .build(); }