|
1 | 1 | #java-diff-utils |
2 | | -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. |
| 2 | + |
| 3 | +##Status |
| 4 | + |
| 5 | +[](https://travis-ci.org/java-diff-utils/java-diff-utils) |
| 6 | +[](https://www.codacy.com/app/wumpz/java-diff-utils?utm_source=github.com&utm_medium=referral&utm_content=java-diff-utils/java-diff-utils&utm_campaign=Badge_Grade) |
| 7 | +[](http://maven-badges.herokuapp.com/maven-central/io.github.java-diff-utils/java-diff-utils) |
| 8 | + |
| 9 | +##Intro |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +**This is originally a fork of java-diff-utils from Google Code Archive.** |
| 16 | + |
| 17 | +##API |
| 18 | + |
| 19 | +Javadocs of the actual release version:[JavaDocs java-diff-utils](https://java-diff-utils.github.io/java-diff-utils/4.7/docs/api/) |
| 20 | + |
| 21 | +##Examples |
| 22 | + |
| 23 | +Look[here](https://github.com/wumpz/java-diff-utils/wiki) to find more helpful informations and examples. |
| 24 | + |
| 25 | +These two outputs are generated using this java-diff-utils. The source code can also be found at the*Examples* page: |
| 26 | + |
| 27 | +**Producing a one liner including all difference information.** |
| 28 | + |
| 29 | +This is a test~senctence~**for diffutils**. |
| 30 | + |
| 31 | +**Producing a side by side view of computed differences.** |
| 32 | + |
| 33 | +|original|new| |
| 34 | +|--------|---| |
| 35 | +|This is a test~senctence~.|This is a test**for diffutils**.| |
| 36 | +|This is the second line.|This is the second line.| |
| 37 | +|~And here is the finish.~|| |
| 38 | + |
| 39 | +##Main Features |
| 40 | + |
| 41 | +* computing the difference between two texts. |
| 42 | +* 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 |
| 43 | +* patch and unpatch the text with the given patch |
| 44 | +* parsing the unified diff format |
| 45 | +* producing human-readable differences |
| 46 | +* inline difference construction |
| 47 | +* Algorithms: |
| 48 | +* Myer |
| 49 | +* HistogramDiff using JGit Library |
| 50 | + |
| 51 | +###Algorithms |
| 52 | + |
| 53 | +* Myer's diff |
| 54 | +* HistogramDiff |
| 55 | + |
| 56 | +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. |
| 57 | + |
| 58 | +##Source Code conventions |
| 59 | + |
| 60 | +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. |
| 61 | + |
| 62 | +```java |
| 63 | +publicstatic<T>Patch<T> diff(List<T> original,List<T> revised, |
| 64 | +BiPredicate<T,T> equalizer) throwsDiffException { |
| 65 | +if (equalizer!=null) { |
| 66 | +returnDiffUtils.diff(original, revised, |
| 67 | +newMyersDiff<>(equalizer)); |
| 68 | + } |
| 69 | +returnDiffUtils.diff(original, revised,newMyersDiff<>()); |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +This is a valid piece of source code: |
| 74 | + |
| 75 | +* blocks without braces are not allowed |
| 76 | +* after control statements (if, while, for) a whitespace is expected |
| 77 | +* the opening brace should be in the same line as the control statement |
| 78 | + |
| 79 | +###To Install |
| 80 | + |
| 81 | +Just add the code below to your maven dependencies: |
| 82 | + |
| 83 | +```xml |
| 84 | +<dependency> |
| 85 | + <groupId>io.github.java-diff-utils</groupId> |
| 86 | + <artifactId>java-diff-utils</artifactId> |
| 87 | + <version>4.5</version> |
| 88 | +</dependency> |
| 89 | +``` |
| 90 | + |
| 91 | +or using gradle: |
| 92 | + |
| 93 | +```groovy |
| 94 | +// https://mvnrepository.com/artifact/io.github.java-diff-utils/java-diff-utils |
| 95 | +implementation "io.github.java-diff-utils:java-diff-utils:4.5" |
| 96 | +``` |