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

Fix DuplicationChecker and key generator #2151

Merged
merged 6 commits into from
Oct 11, 2016
Merged

Fix DuplicationChecker and key generator #2151

merged 6 commits into from
Oct 11, 2016

Conversation

chriba
Copy link
Contributor

@chriba chriba commented Oct 10, 2016

Fixes #2089.

The Duplication checker was faulty and didn't catch all the cite keys. There needed to be used a special method in the BasePanel which wasn't used at all.
I registered the DuplicationChecker with the Eventbus which now gets notified when an Entry changes, gets added, or removed.

This fixes the automatic Key generation which before had wrong information on what cite keys exist.

if (Globals.prefs.getBoolean(JabRefPreferences.AVOID_OVERWRITING_KEY)) {
// Remove the entry, because its key is already set:
if (Globals.prefs.getBoolean(JabRefPreferences.AVOID_OVERWRITING_KEY)) {
for (final Iterator<BibEntry> i = entries.iterator(); i.hasNext();) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename i to iterator.

Copy link
Contributor

@tschechlovdev tschechlovdev Oct 10, 2016

Choose a reason for hiding this comment

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

And why not using stream with filter? Or even better entries.removeIf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lambdas still doesn't come that easy to my mind.
I rewrote this and the part just beneath with lambdas.

private final Map<String, Integer> allKeys = new HashMap<>();


Copy link
Contributor

Choose a reason for hiding this comment

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

please delete empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always like a little visual separation between the members from the methods, and seen this in some other classes too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know that I got many comments for empty lines like this.
But I think in this case it's okay to leave it.

/**
* Checks if there is more than one occurrence of this key
*/
public boolean isDuplicateExisting(Optional<String> citeKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use optionals as params. They should only be used as return values. See #1577 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tschechlovdev tschechlovdev added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed stupro-ready-for-internal-review labels Oct 10, 2016
// that it's ok to overwrite keys:
break;
if (Globals.prefs.getBoolean(JabRefPreferences.AVOID_OVERWRITING_KEY)) {
entries.removeIf(BibEntry::hasCiteKey);
Copy link
Member

Choose a reason for hiding this comment

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

Please readd the comments from the old code if possible. Here, the comment is // Remove the entry, because its key is already set:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added some comments

@@ -457,7 +448,7 @@ public static void makeLabel(AbstractBibtexKeyPattern citeKeyPattern, BibDatabas
}

String moddedKey = key + getAddition(number);
occurrences = database.getNumberOfKeyOccurrences(moddedKey);
occurrences = database.getDuplicationChecker().getNumberOfKeyOccurrences(moddedKey);

if (Objects.equals(oldKey, moddedKey)) {
occurrences--;
Copy link
Member

Choose a reason for hiding this comment

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

Can this ever happen? - If yes, please construct a test case covering this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can only happen if the BibtexKeyPatternUtil#getAddition method is buggy.


@Subscribe
public void listen(EntryRemovedEvent entryRemovedEvent) {
removeKeyFromSet(entryRemovedEvent.getBibEntry().getCiteKeyOptional().orElse(null));
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure whether null should really be treated as real key. Why not excluding null from FieldChanged, EntryRemoved, and EntryAdded?

As a consequence, null always appears 0 times in the database.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the key is null removeKeyFromSet will return immediately.
now I use the ifPresent method of the optional.

@koppor
Copy link
Member

koppor commented Oct 11, 2016

Tested it manually: works. Besides the minor question: LGTM.

@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 11, 2016
@koppor koppor merged commit c1c8c76 into JabRef:master Oct 11, 2016
@chriba chriba deleted the fixAutogenerateCiteKeys branch October 11, 2016 15:52
Siedlerchr added a commit that referenced this pull request Oct 13, 2016
* upstream/master: (24 commits)
  hotfix NPE in the main table (#2158)
  Enhance side pane toggle (#1605)
  Added gray background text to authors field to assist newcomers (#2147)
  Rewrite google scholar fetcher to new infrastructure (#2101)
  Found entries will be shown when dropping a pdf with xmp meta data (#2150)
  Japanese translation (#2155)
  Add shortcuts to context menu (#2131)
  [WIP] Doi resolution ignore (#2154)
  Fix DuplicationChecker and key generator (#2151)
  just close popup on first ESC
  keep entry in sight
  Fix isSharedDatabaseAlreadyPresent check.
  don't change entry after search if editing an entry (#2129)
  Change download URL to downloads.jabref.org (#2145)
  fix switching edited textfield in the entry editor with TAB (#2138)
  Update me.champeau.gradle.jmh' version from 0.3.0 to 0.3.1
  Update install4j plugin from 6.1.2 to 6.1.3
  Remove gradle plugin com.github.youribonnaffe.gradle.format as it is deprecated and the config uses a non-existing file
  Update gradle from 3.0 to 3.1
  Fix changing the font size not working when importing preferences (#2069)
  ...

# Conflicts:
#	src/main/java/net/sf/jabref/gui/externalfiles/DroppedFileHandler.java
#	src/main/java/net/sf/jabref/gui/importer/fetcher/GoogleScholarFetcher.java
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autogenerate Keys Finds/Produces Incorrect Duplicate Keys
3 participants