Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diff implementation in Java [duplicate]

Tags:

java

diff

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!

like image 305
Olivier Grégoire Avatar asked Jun 09 '10 14:06

Olivier Grégoire


1 Answers

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

like image 119
KushalP Avatar answered Sep 18 '22 17:09

KushalP