11

I'm looking for a diff implementation in Java. I've seen that Python has its own SequenceMatcher (with difflib), which is exactly what I need... in Java.

Is there any portage? Or is there any other class/library that performs the same in Java?

If not, where can I find the source code of that difflib (if free as in speech) to make my own implementation of SequenceMatcher in Java ?

Unfortunately, Apache Commons Lang doesn't help me much.

Thanks!

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137

2 Answers2

17

This library seems to be what you're after: google-diff-match-patch.

It has the following main features:

  1. Diff: Compare two blocks of plain text and efficiently return a list of differences.
  2. Match: Given a search string, find its best fuzzy match in a block of plain text. Weighted for both accuracy and location.
  3. Patch: Apply a list of patches onto plain text. Use best-effort to apply patch even when the underlying text doesn't match.

In case you want an alternative, you could also try this: java-diff-utils

KushalP
  • 10,976
  • 6
  • 34
  • 27
0

Hi You can run a MR job which can use https://code.google.com/p/google-diff-match-patch/ to do the required job. I dont feel there are any tools out of the box to do your job.

amith
  • 399
  • 1
  • 2
  • 11