@Test public void testDiff() { String text1 = "I am the vXXery model of a carttoon inidual"; String text2 = "I a m the very Zodel of a caraatoon individu al"; final String[] diffLines = DiffUtil.diffLines(text1, text2, true); assertThat(diffLines, equalTo(new String[]{ "I am the vXXery model of a cart toon in idual", " -- ^ ^^ +++ ", " Z aa div " })); }
public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) { final diff_match_patch dmp = new diff_match_patch(); final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2); if (CollectionUtils.isEmpty(diffs)) { return null; } else { if (ignoreWhiteSpace) { final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists.newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() { @Override public boolean apply(diff_match_patch.Diff input) { if (input.operation.equals(diff_match_patch.Operation.EQUAL)) return false; else if (StringUtils.isBlank(input.text)) return false; return true; } })); if (filteredDiffs.isEmpty()) return null; } dmp.diff_cleanupSemantic(diffs); final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace); if (ignoreWhiteSpace) { if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2])) return null; } return diffLines; } }
DiffUtil { public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) { final diff_match_patch dmp = new diff_match_patch(); final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2); if (CollectionUtils.isEmpty(diffs)) { return null; } else { if (ignoreWhiteSpace) { final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists.newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() { @Override public boolean apply(diff_match_patch.Diff input) { if (input.operation.equals(diff_match_patch.Operation.EQUAL)) return false; else if (StringUtils.isBlank(input.text)) return false; return true; } })); if (filteredDiffs.isEmpty()) return null; } dmp.diff_cleanupSemantic(diffs); final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace); if (ignoreWhiteSpace) { if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2])) return null; } return diffLines; } } }
DiffUtil { public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) { final diff_match_patch dmp = new diff_match_patch(); final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2); if (CollectionUtils.isEmpty(diffs)) { return null; } else { if (ignoreWhiteSpace) { final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists.newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() { @Override public boolean apply(diff_match_patch.Diff input) { if (input.operation.equals(diff_match_patch.Operation.EQUAL)) return false; else if (StringUtils.isBlank(input.text)) return false; return true; } })); if (filteredDiffs.isEmpty()) return null; } dmp.diff_cleanupSemantic(diffs); final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace); if (ignoreWhiteSpace) { if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2])) return null; } return diffLines; } }  }
DiffUtil { public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) { final diff_match_patch dmp = new diff_match_patch(); final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2); if (CollectionUtils.isEmpty(diffs)) { return null; } else { if (ignoreWhiteSpace) { final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists.newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() { @Override public boolean apply(diff_match_patch.Diff input) { if (input.operation.equals(diff_match_patch.Operation.EQUAL)) return false; else if (StringUtils.isBlank(input.text)) return false; return true; } })); if (filteredDiffs.isEmpty()) return null; } dmp.diff_cleanupSemantic(diffs); final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace); if (ignoreWhiteSpace) { if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2])) return null; } return diffLines; } }  static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace); }
DiffUtil { public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) { final diff_match_patch dmp = new diff_match_patch(); final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2); if (CollectionUtils.isEmpty(diffs)) { return null; } else { if (ignoreWhiteSpace) { final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists.newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() { @Override public boolean apply(diff_match_patch.Diff input) { if (input.operation.equals(diff_match_patch.Operation.EQUAL)) return false; else if (StringUtils.isBlank(input.text)) return false; return true; } })); if (filteredDiffs.isEmpty()) return null; } dmp.diff_cleanupSemantic(diffs); final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace); if (ignoreWhiteSpace) { if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2])) return null; } return diffLines; } }  static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace);  }