Remove teamscale findings in the database package#1577
Conversation
| } | ||
|
|
||
| /** | ||
| * Creates a KeyCollisionException with a given message and a given cause. |
There was a problem hiding this comment.
I don't think, it necessary to document trivial cases. Maybe, this teamscale finding should be ignored?
There was a problem hiding this comment.
Ok I removed the unnecessary comments.
982c239 to
72fae1a
Compare
| // note: there is a good reason why we should not use a hashset but use hashmap instead | ||
| //======================================================== | ||
| public void removeKeyFromSet(String key) { | ||
| protected void removeKeyFromSet(String key) { |
There was a problem hiding this comment.
Still not consistent with addKeyToSet
There was a problem hiding this comment.
But then I have to set addKeyToSet protected, or public, although it can be declared private. Shouldn't it have the lowest possible visibility level?
|
|
||
| private final EventBus eventBus = new EventBus(); | ||
|
|
||
|
|
There was a problem hiding this comment.
Bitte keine obsoelten Leerzeilen
| /** | ||
| * | ||
| * @param key | ||
| * @return list of entries that contains the given key |
There was a problem hiding this comment.
Please rework comment. "Collects entries having the specified BibTeX key and returns these entries as list. The order of the entries is the order they appear in the database"
6d9ac2e to
a287147
Compare
| * | ||
| * This class handles the instantiations of {@link BibDatabase}. | ||
| * | ||
| */ |
There was a problem hiding this comment.
Please remove the empty lines in the comment
| import net.sf.jabref.model.entry.EntryType; | ||
|
|
||
| /** | ||
| * In this class the detection of the {@link BibDatabaseMode} is handled. |
There was a problem hiding this comment.
Either remove this comment or expand it by explaining, what the intention of the mode is etc. What is the idea of the detection etc.
…chechlovdev/jabref into TeamscaleFindingsModelDatabasePackage # Conflicts: # src/main/java/net/sf/jabref/model/database/BibDatabase.java # src/main/java/net/sf/jabref/model/database/DuplicationChecker.java
…ModelDatabasePackage
| entry.setCiteKey(key); | ||
| } | ||
| return duplicationChecker.checkForDuplicateKeyAndAdd(oldKey, key); | ||
| return duplicationChecker.checkForDuplicateKeyAndAdd(entry.getCiteKeyOptional(), Optional.ofNullable(key)); |
There was a problem hiding this comment.
entry.getCiteKeyOptional() will not contain the old key now. Both arguments will be identical so will break the function of the call.
There was a problem hiding this comment.
Thanks a lot! I've searched at the wrong place for the failure ....
…ModelDatabasePackage # Conflicts: # src/main/java/net/sf/jabref/model/database/BibDatabase.java
| * | ||
| * @return true, if there is a duplicate key, else false | ||
| */ | ||
| public boolean checkForDuplicateKeyAndAdd(Optional<String> oldKey, Optional<String> newKey) { |
There was a problem hiding this comment.
I don't like Optionals as parameters here.
There was a problem hiding this comment.
If I remember correctly, the caller may pass null for both oldKey and newKey. As JabRef moves away from null towards Optional, we thought, it would be a good idea to use Optional here, too.
There was a problem hiding this comment.
Personnaly I think Optional is only a good thing for return types. I also posted an article some time ago.
There was a problem hiding this comment.
Independent of Optional or not, wouldn't it be possible to write the code like:
boolean duplicate = false;
if (!oldKey.equals(newKey)) { // If keys are not the same
if (!oldKey.isPresent()) { // No old key
duplicate = addKeyToSet(newKey.get());
} else {
removeKeyFromSet(oldKey.get()); // Get rid of old key
if (newKey.isPresent()) { // Add new key if any
duplicate = addKeyToSet(newKey.get());
}
}
}
if (duplicate) {
...
}(Replace with corresponding non-optional calls (Objects.equals() for the first call).
There was a problem hiding this comment.
@stefan-kolb Do you have a deep link for the article? I checked https://github.com/JabRef/jabref/wiki/Code-Howtos, which points to https://github.com/cxxr/better-java#avoid-nulls, which uses Optional also in the parameters.
There was a problem hiding this comment.
Not the exacr one but what about these: https://dzone.com/articles/use-of-optional-is-optional, https://dzone.com/articles/java-8-optional-how-use-it
There was a problem hiding this comment.
Related discussion:
http://stackoverflow.com/questions/31922866/why-should-java-8s-optional-not-be-used-in-arguments
2016-08-26 8:25 GMT+02:00 Stefan Kolb notifications@github.com:
In src/main/java/net/sf/jabref/model/database/DuplicationChecker.java
#1577 (comment):
- //############################################
- // if the newkey already exists and is not the same as oldkey it will give a warning
- // else it will add the newkey to the to set and remove the oldkey
- public boolean checkForDuplicateKeyAndAdd(String oldKey, String newKey) {
// LOGGER.debug(" checkForDuplicateKeyAndAdd [oldKey = " + oldKey + "] [newKey = " + newKey + "]");- /**
\* Usage:\* <br>\* isDuplicate=checkForDuplicateKeyAndAdd( null, b.getKey() , issueDuplicateWarning);*\* If the newkey already exists and is not the same as oldkey it will give a warning\* else it will add the newkey to the to set and remove the oldkey*\* @return true, if there is a duplicate key, else false*/- public boolean checkForDuplicateKeyAndAdd(Optional oldKey, Optional newKey) {
Not the exacr one but what about these: https://dzone.com/articles/
use-of-optional-is-optional, https://dzone.com/articles/
java-8-optional-how-use-it—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
https://github.com/JabRef/jabref/pull/1577/files/f9d6a1943a7bc023d8042f02c3c3922c38f34a66#r76369435,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AATi5Fj7w1jmaRe-PdgqNDMDsD1MeDS2ks5qjobDgaJpZM4JKeSe
.
|
Just two small changes and I'm OK with it 👍 |
|
LGTM 👍 |
* master: Remove teamscale findings in the database package (JabRef#1577) French localization: Jabref_fr: empty strings translated + removal of unused header (JabRef#1911)
* 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
Remove the teamscale finding in the database package, that is in the model package. This means refactoring of methods, that are too long, adding comments to public method/classes and used streams in some situations for better readability (and reducing code).