From d2f5d677404497d0900f3ca01b9dbfe135bf6a70 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 26 Feb 2020 10:59:33 +0100 Subject: [PATCH 1/4] Try to normalize month --- .../jabref/logic/importer/fetcher/AstrophysicsDataSystem.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 3415597a690..9dff54b8b74 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -14,6 +14,7 @@ import org.jabref.logic.cleanup.MoveFieldCleanup; import org.jabref.logic.formatter.bibtexfields.ClearFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter; import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter; @@ -143,6 +144,7 @@ public void doPostCleanup(BibEntry entry) { new FieldFormatterCleanup(StandardField.ABSTRACT, new RemoveNewlinesFormatter()).cleanup(entry); new FieldFormatterCleanup(StandardField.TITLE, new RemoveBracesFormatter()).cleanup(entry); new FieldFormatterCleanup(StandardField.AUTHOR, new NormalizeNamesFormatter()).cleanup(entry); + new FieldFormatterCleanup(StandardField.MONTH, new NormalizeMonthFormatter()).cleanup(entry); // Remove ADS note new FieldFormatterCleanup(new UnknownField("adsnote"), new ClearFormatter()).cleanup(entry); @@ -249,7 +251,6 @@ public Optional performSearchById(String identifier) throws FetcherExc * bibcodes */ private List performSearchByIds(Collection identifiers) throws FetcherException { - List ids = identifiers.stream().filter(identifier -> !StringUtil.isBlank(identifier)).collect(Collectors.toList()); if (ids.isEmpty()) { return Collections.emptyList(); From 2f178b12a1ff552e98867b4026bd95b9a00f9ed1 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 29 Feb 2020 10:16:26 +0100 Subject: [PATCH 2/4] Use Collections.emptyList instead of new ArrayList --- .../java/org/jabref/model/cleanup/FieldFormatterCleanup.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java b/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java index 5965ed3fdb2..546025aa679 100644 --- a/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java +++ b/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java @@ -49,7 +49,7 @@ public List cleanup(BibEntry entry) { private List cleanupSingleField(Field fieldKey, BibEntry entry) { if (!entry.hasField(fieldKey)) { // Not set -> nothing to do - return new ArrayList<>(); + return Collections.emptyList(); } String oldValue = entry.getField(fieldKey).orElse(null); @@ -57,7 +57,7 @@ private List cleanupSingleField(Field fieldKey, BibEntry entry) { String newValue = formatter.format(oldValue); if (oldValue.equals(newValue)) { - return new ArrayList<>(); + return Collections.emptyList(); } else { if (newValue.isEmpty()) { entry.clearField(fieldKey); From d0f0d2261c109816bbde326ff44f0ef96348bacc Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 29 Feb 2020 10:17:56 +0100 Subject: [PATCH 3/4] Add comment on "toString()" (and format other comments --- .../java/org/jabref/model/entry/BibEntry.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index bfe7cadc8c8..d4c69cdfcdd 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -508,7 +508,7 @@ public void setField(Map fields) { /** * Set a field, and notify listeners about the change. * - * @param field The field to set + * @param field The field to set * @param value The value to set * @param eventSource Source the event is sent from */ @@ -543,7 +543,7 @@ public Optional setField(Field field, String value, EntriesEventSou /** * Set a field, and notify listeners about the change. * - * @param field The field to set. + * @param field The field to set. * @param value The value to set. */ public Optional setField(Field field, String value) { @@ -551,8 +551,7 @@ public Optional setField(Field field, String value) { } /** - * Remove the mapping for the field name, and notify listeners about - * the change. + * Remove the mapping for the field name, and notify listeners about the change. * * @param field The field to clear. */ @@ -588,9 +587,9 @@ public Optional clearField(Field field, EntriesEventSource eventSou * database argument is given, this method will try to look up missing fields in * entries linked by the "crossref" field, if any. * - * @param fields An array of field names to be checked. - * @param database The database in which to look up crossref'd entries, if any. This - * argument can be null, meaning that no attempt will be made to follow crossrefs. + * @param fields An array of field names to be checked. + * @param database The database in which to look up crossref'd entries, if any. This argument can be null, meaning + * that no attempt will be made to follow crossrefs. * @return true if all fields are set or could be resolved, false otherwise. */ public boolean allFieldsPresent(Collection fields, BibDatabase database) { @@ -610,9 +609,11 @@ public Object clone() { /** * This returns a canonical BibTeX serialization. Special characters such as "{" or "&" are NOT escaped, but written - * as is + * as is. In case the JabRef "hack" for distinguishing "field = value" and "field = {value}" (in .bib files) is + * used, it is output as "field = {#value#}", which may cause headaches in debugging. We nevertheless do it this way + * to a) enable debugging the internal representation and b) save time at this method. *

- * Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key + * Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key. */ @Override public String toString() { From b2d560b83a11d640847e5fe6c64333c16a6ee366 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 29 Feb 2020 10:18:15 +0100 Subject: [PATCH 4/4] Add addtional tests --- .../formatter/bibtexfields/NormalizeMonthFormatterTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java index 31c3f935989..32d196bcc2a 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java @@ -21,4 +21,9 @@ public void setUp() { public void formatExample() { assertEquals("#dec#", formatter.format(formatter.getExampleInput())); } + + @Test + public void plainAprilShouldBeApril() { + assertEquals("#apr#", formatter.format("#apr#")); + } }