Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add generateOriginalAndDiff method and test class#164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wumpz merged 4 commits intojava-diff-utils:masterfrom1506085843:master
Apr 27, 2023

Conversation

1506085843
Copy link
Contributor

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.

diff

Comment on lines 22 to 23
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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.

Comment on lines 37 to 38


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Remove extra lines.



//Insert the diff format to the original file
private static List<String> insertOrig(List<String> original, List<String> unifiedDiff) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Refactor the method to use more descriptive variable names. For example, instead of using "d", you can use "diff".

unifiedDiff.set(1, unifiedDiff.get(1));
unifiedDiff.add(2, "@@ -0,0 +0,0 @@");
}
List<String> original1 = original.stream().map(v -> " " + v).collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can use more meaningful name. For example, useoriginalWithPrefix instead oforiginal1.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can useunifiedDiff.isEmpty() instead ofunifiedDiff.size() == 0.



//Insert the diff format to the original file
private static List<String> insertOrig(List<String> original, List<String> unifiedDiff) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The method is very long, it could be broken into multiple small methods to increase readability of the code.

…nto short methods, changed ambiguous variable names to explicit variable names
@1506085843
Copy link
ContributorAuthor

Now, I have modified the related question you mentioned above

@wumpz
Copy link
Collaborator

Correct the building problems.

@1506085843
Copy link
ContributorAuthor

Build issues have been fixed.

@wumpzwumpz merged commit1664490 intojava-diff-utils:masterApr 27, 2023
@wumpz
Copy link
Collaborator

Thx for your contribution.

1506085843 added a commit to 1506085843/java-diff-utils that referenced this pull requestJun 16, 2023
When deleting the first line of comparison text and adding several lines of text, the first diff of the result returned by the generateOriginalAndDiff method is inserted incorrectly
wumpz pushed a commit that referenced this pull requestAug 13, 2023
* Add generateOriginalAndDiff method and test class* Add generateOriginalAndDiff method and test class.I split long code into short methods, changed ambiguous variable names to explicit variable names*fixes#164* fix build issues* fix issues about (#164),detail:When deleting the first line of comparison text and adding several lines of text, the first diff of the result returned by the generateOriginalAndDiff method is inserted incorrectly* add a test for#170---------Co-authored-by: xutao <xutao@apexsoft.com.cn>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mhamadlimhamadlimhamadli left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@1506085843@wumpz@mhamadli

[8]ページ先頭

©2009-2025 Movatter.jp