-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Mark some methods as deprecated in BibEntry and BibDatabase #1913
Conversation
// If this field is not set, and the entry has a crossref, try to look up the | ||
// field in the referred entry: Do not do this for the bibtex key. | ||
if (!result.isPresent() && (database != null)) { | ||
Optional<String> crossrefKey = getField(FieldName.CROSSREF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use a flatmap for chaining optionals, it would only get evaluated if a value is present in all fields and addtionally you can add a filter condition for checking !isEmpty
http://www.nurkiewicz.com/2013/08/optional-in-java-8-cheat-sheet.html (scroll down to end to see the "bigger example")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed the code accordingly.
What is the reason behind separating the insert and the duplication check? |
Most of the callers of |
Thanks for the explaination. Now code LGTM 👍 |
Ok, this sounds reasonable and the code that I looked at (in BibEntry and BibDatabase, as you suggested) looks good. I am merging it in. |
As commented in the source, the deprecation of constants misses the target. By far. |
My bad for merging! The changes in methods still have some values, don't they? So, instead of reverting, how about just removing the deprecation marking for the constants again? @tobiasdiez What do you think? |
Yeah, it was mainly the `BibEntry`-constants I reacted on, the rest I have
not looked carefully at, but I guess those are fine. The idea from
@tobiasdiez to use get/set/clear is of course 100% correct, but in almost
all cases the constants are not used for that purpose and it is not easily
solved. Unless we want to add methods like `isBibtexKeyField(String
fieldName)` and `isEntryTypeField(String fieldName)` which would solve
maybe half of the issues. Then there is sorting and to some extent tables
left.
|
* Check integrity edition check * Conflict in Jabref_fr * Changed order Biblatex/Bibtex condition * Create own object * Rename variable * Extract checker to own file * Improved comment * French localization: Jabref_fr: empty strings translated + removal of unused header (#1911) * Remove teamscale findings in the database package (#1577) * Check integrity edition check * Changed order Biblatex/Bibtex condition * Create own object * Rename variable * Mark some methods as deprecated in BibEntry and BibDatabase (#1913) * Mark some methods as deprecated in BibEntry and BibDatabase * Rename getResolvedFieldOrAlias * Use flatmap * Fix location field not exported correctly to office 2007 xml (#1909) * Fix location field not exported to office 2007 xml * Add some test for exporting location and address field Address in xml field is now imported as location add some javadoc * Add possibility to remember password for shared databases. (#1846) * Add possibility to remember password. - Add checkbox to the open shared database dialog - Add SharedDatabasePreferences - Add password encrypting and decrypting methods - Update localization entries - Reorganize clearing methods for Preferences * Change prefs node and add class comment. * Relativate node path for password storage. * Fix LOGGER factory. * Improve password encryption using XOR. - Use username as one operand - Add new parameter to the constructor * Extract method. * Improve exception handling. * Improve password encryption and decryption. - Use CBC and padding - Hash the key before using - Simplify conversion * Fix modifier. Fix conflicts. * Extract checker to own file * Improved comment * Translation of shared (#1919) * Add missing entries in german localization * Resolved conflicts * Some more conflicts de sv * Expressions changed
Another comment: the fact that the duplication checker is not called when inserting the entry means that the keys do not add additional letters after it. Yes, the callers did more than often not check the return value but now one will have to perform two operations for properly inserting an entry into a database. Both insert it into the database and into the duplicationchecker. |
Not to mention the fact that the duplication checker will not find duplicates inserted the new way (as far as I can tell). |
Good practice when marking things as deprecated: make some simple changes of the deprecated function to the non-deprecated function. Here, it would be obvious that the key-tests failed, despite no actual need to check for any duplicates before inserting them. Also, it would be obvious that most of the constants were not used in a bad way etc. |
Good thing that you bring this back up! It seems it slipped under during this weeks devcall, but we should talk about it again during the next one (propably next week). EDIT: This PR easily slips under as github hides close/merged stuff. I'll take the link explicitly into the minutes for the next meeting |
I recenlty discoverd two problems: Second problem: I recently tried to replace getText with getResolvedField in a method and suddenly all kind of test failed....(Unfortunately I don't remember the PR). |
@@ -157,8 +151,14 @@ public static boolean isInternalField(String field) { | |||
* @return false if the insert was done without a duplicate warning | |||
* @throws KeyCollisionException thrown if the entry id ({@link BibEntry#getId()}) is already present in the database | |||
*/ | |||
public synchronized boolean insertEntry(BibEntry entry) throws KeyCollisionException { | |||
return insertEntry(entry, EntryEventSource.LOCAL); | |||
@Deprecated // use insertEntry and DuplicationChecker separately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the comment to @deprecated
javadoc
@@ -222,10 +220,11 @@ public int getNumberOfKeyOccurrences(String key) { | |||
* | |||
* @return true, if the entry contains the key, false if not | |||
*/ | |||
@Deprecated // use BibEntry.setCiteKey (and DuplicationChecker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deprecated
JavaDoc?
* Returns a text with references resolved according to an optionally given database. | ||
* | ||
* @param toResolve maybenull The text to resolve. | ||
* @param database maybenull The database to use for resolving the text. | ||
* @return The resolved text or the original text if either the text or the database are null | ||
*/ | ||
@Deprecated // use BibDatabase.resolveForStrings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deprecated
JavaDoc?
…1913)" This reverts commit a9eb978. # Conflicts: # src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java # src/main/java/net/sf/jabref/model/database/BibDatabase.java # src/main/java/net/sf/jabref/model/entry/BibEntry.java # src/test/java/net/sf/jabref/logic/search/DatabaseSearcherTest.java
I reverted it at #2023. Please comment, directly improve, or merge. |
…1913)" (#2023) This reverts commit a9eb978. # Conflicts: # src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java # src/main/java/net/sf/jabref/model/database/BibDatabase.java # src/main/java/net/sf/jabref/model/entry/BibEntry.java # src/test/java/net/sf/jabref/logic/search/DatabaseSearcherTest.java
…abRef#1913)" (JabRef#2023) This reverts commit a9eb978. # Conflicts: # src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java # src/main/java/net/sf/jabref/model/database/BibDatabase.java # src/main/java/net/sf/jabref/model/entry/BibEntry.java # src/test/java/net/sf/jabref/logic/search/DatabaseSearcherTest.java
Changes are only in BibEntry and BibDatabase (the rest are propagated renames / method signature changes).