Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork201
Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.
License
java-diff-utils/java-diff-utils
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Diff Utils library is an OpenSource library for performing the comparison operations between texts: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.
Main reason to build this library was the lack of easy-to-use libraries with all the usual stuff you need while working with diff files. Originally it was inspired by JRCS library and it's nice design of diff module.
This is originally a fork of java-diff-utils from Google Code Archive.
The gpg singing key in [KEYS] is used for this projects artifacts.
Javadocs of the actual release version:JavaDocs java-diff-utils
Lookhere to find more helpful informations and examples.
These two outputs are generated using this java-diff-utils. The source code can also be found at theExamples page:
Producing a one liner including all difference information.
//create a configured DiffRowGeneratorDiffRowGeneratorgenerator =DiffRowGenerator.create() .showInlineDiffs(true) .mergeOriginalRevised(true) .inlineDiffByWord(true) .oldTag(f ->"~")//introduce markdown style for strikethrough .newTag(f ->"**")//introduce markdown style for bold .build();//compute the differences for two test texts.List<DiffRow>rows =generator.generateDiffRows(Arrays.asList("This is a test senctence."),Arrays.asList("This is a test for diffutils."));System.out.println(rows.get(0).getOldLine());
This is a testsenctencefor diffutils.
Producing a side by side view of computed differences.
DiffRowGeneratorgenerator =DiffRowGenerator.create() .showInlineDiffs(true) .inlineDiffByWord(true) .oldTag(f ->"~") .newTag(f ->"**") .build();List<DiffRow>rows =generator.generateDiffRows(Arrays.asList("This is a test senctence.","This is the second line.","And here is the finish."),Arrays.asList("This is a test for diffutils.","This is the second line."));System.out.println("|original|new|");System.out.println("|--------|---|");for (DiffRowrow :rows) {System.out.println("|" +row.getOldLine() +"|" +row.getNewLine() +"|");}
original | new |
---|---|
This is a test | This is a testfor diffutils. |
This is the second line. | This is the second line. |
- computing the difference between two texts.
- capable to hand more than plain ascii. Arrays or List of any type that implements hashCode() and equals() correctly can be subject to differencing using this library
- patch and unpatch the text with the given patch
- parsing the unified diff format
- producing human-readable differences
- inline difference construction
- Algorithms:
- Myers Standard Algorithm
- Myers with linear space improvement
- HistogramDiff using JGit Library
- Myer's diff
- HistogramDiff
But it can easily replaced by any other which is better for handing your texts. I have plan to add implementation of some in future.
Recently a checkstyle process was integrated into the build process. java-diff-utils follows the sun java format convention. There are no TABs allowed. Use spaces.
publicstatic <T>Patch<T>diff(List<T>original,List<T>revised,BiPredicate<T,T>equalizer)throwsDiffException {if (equalizer !=null) {returnDiffUtils.diff(original,revised,newMyersDiff<>(equalizer)); }returnDiffUtils.diff(original,revised,newMyersDiff<>());}
This is a valid piece of source code:
- blocks without braces are not allowed
- after control statements (if, while, for) a whitespace is expected
- the opening brace should be in the same line as the control statement
Just add the code below to your maven dependencies:
<dependency> <groupId>io.github.java-diff-utils</groupId> <artifactId>java-diff-utils</artifactId> <version>4.15</version></dependency>
or using gradle:
// https://mvnrepository.com/artifact/io.github.java-diff-utils/java-diff-utilsimplementation"io.github.java-diff-utils:java-diff-utils:4.12"
About
Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.