| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import java.util.*; |
There was a problem hiding this comment.
It is not recommended to use wildcard imports, because they can make code less readable, and potentially import unnecessary modules that can slow down performance.
Sorry, something went wrong.
|
|
||
|
|
There was a problem hiding this comment.
Remove extra lines.
Sorry, something went wrong.
|
|
||
|
|
||
| //Insert the diff format to the original file | ||
| private static List<String> insertOrig(List<String> original, List<String> unifiedDiff) { |
There was a problem hiding this comment.
Refactor the method to use more descriptive variable names. For example, instead of using "d", you can use "diff".
Sorry, something went wrong.
| unifiedDiff.set(1, unifiedDiff.get(1)); | ||
| unifiedDiff.add(2, "@@ -0,0 +0,0 @@"); | ||
| } | ||
| List<String> original1 = original.stream().map(v -> " " + v).collect(Collectors.toList()); |
There was a problem hiding this comment.
You can use more meaningful name. For example, use originalWithPrefix instead of original1.
Sorry, something went wrong.
| revisedFileName = revisedFileName == null ? "revised" : revisedFileName; | ||
| Patch<String> patch = com.github.difflib.DiffUtils.diff(original, revised); | ||
| List<String> unifiedDiff = generateUnifiedDiff(originalFileName, revisedFileName, original, patch, 0); | ||
| if (unifiedDiff.size() == 0) { |
There was a problem hiding this comment.
You can use unifiedDiff.isEmpty() instead of unifiedDiff.size() == 0.
Sorry, something went wrong.
|
|
||
|
|
||
| //Insert the diff format to the original file | ||
| private static List<String> insertOrig(List<String> original, List<String> unifiedDiff) { |
There was a problem hiding this comment.
The method is very long, it could be broken into multiple small methods to increase readability of the code.
Sorry, something went wrong.
|
Now, I have modified the related question you mentioned above |
Sorry, something went wrong.
|
Correct the building problems. |
Sorry, something went wrong.
|
Build issues have been fixed. |
Sorry, something went wrong.
|
Thx for your contribution. |
Sorry, something went wrong.
The generateOriginalAndDiff method is added to compare the original file with the reference file, get the diff, and insert the diff into the corresponding location of the original file.
You can see all the differences and unmodified places from the original file.
In addition, it is very easy and useful for making side-by-side comparison display applications,
For example, if you use something like diff2html( https://github.com/rtfpessoa/diff2html#usage )
Such a tool displays your differences on the html page. You only need to insert the return value of the method into your js code, and you can get a beautiful html comparison page.