Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select the entry which has smaller dictonary order when merge #7708

Merged
merged 6 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added an option in preferences to allow for integers in field "edition" when running database in bibtex mode. [#4680](https://github.com/JabRef/jabref/issues/4680)
- We added the ability to use negation in export filter layouts. [#5138](https://github.com/JabRef/jabref/pull/5138)
- Focus on Name Area instead of 'OK' button whenever user presses 'Add subgroup'. [#6307](https://github.com/JabRef/jabref/issues/6307)
- We changed the behavior of merging that the entry which has "smaller" bibkey will be selected. [#7395](https://github.com/JabRef/jabref/issues/7395)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,24 @@ public void execute() {
BibEntry one = selectedEntries.get(0);
BibEntry two = selectedEntries.get(1);

MergeEntriesDialog dlg = new MergeEntriesDialog(one, two);
// Compare the citation key
BibEntry first = one;
BibEntry second = two;

Optional<String> keyOne = one.getCitationKey();
Optional<String> keyTwo = two.getCitationKey();
if (keyOne.isPresent() && keyTwo.isPresent() && keyOne.get().compareTo(keyTwo.get()) > 0) {
first = two;
second = one;
}
else {
if (keyTwo.isPresent()) {
first = two;
second = one;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

There is org.jabref.logic.bibtex.comparator.EntryComparator:

EntryComparator(false, true, InternalField.KEY_FIELD)

Thus:

Suggested change
// Compare the citation key
BibEntry first = one;
BibEntry second = two;
Optional<String> keyOne = one.getCitationKey();
Optional<String> keyTwo = two.getCitationKey();
if (keyOne.isPresent() && keyTwo.isPresent() && keyOne.get().compareTo(keyTwo.get()) > 0) {
first = two;
second = one;
}
else {
if (keyTwo.isPresent()) {
first = two;
second = one;
}
}
BibEntry first;
BibEntry second;
EntryComparator entryComparator = new EntryComparator(false, true, InternalField.KEY_FIELD);
if (entryComparator.compare(one, two) <= 0) {
first = one;
second = two;
} else {
first = two;
second = one;
}

Since software engineering is an engineering prinicple and engineering includes testing, please add test cases. Add them to the class org.jabref.logic.bibtex.comparator.EntryComparatorTest


MergeEntriesDialog dlg = new MergeEntriesDialog(first, second);
dlg.setTitle(Localization.lang("Merge entries"));
Optional<BibEntry> mergedEntry = dialogService.showCustomDialogAndWait(dlg);
if (mergedEntry.isPresent()) {
Expand Down