Skip to content

Commit d9a8088

Browse files
authored
Add month normalization to AstroPhysicsFetcher (#6022)
1 parent 9c0fa85 commit d9a8088

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.jabref.logic.cleanup.MoveFieldCleanup;
1616
import org.jabref.logic.formatter.bibtexfields.ClearFormatter;
17+
import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter;
1718
import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
1819
import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter;
1920
import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter;
@@ -143,6 +144,7 @@ public void doPostCleanup(BibEntry entry) {
143144
new FieldFormatterCleanup(StandardField.ABSTRACT, new RemoveNewlinesFormatter()).cleanup(entry);
144145
new FieldFormatterCleanup(StandardField.TITLE, new RemoveBracesFormatter()).cleanup(entry);
145146
new FieldFormatterCleanup(StandardField.AUTHOR, new NormalizeNamesFormatter()).cleanup(entry);
147+
new FieldFormatterCleanup(StandardField.MONTH, new NormalizeMonthFormatter()).cleanup(entry);
146148

147149
// Remove ADS note
148150
new FieldFormatterCleanup(new UnknownField("adsnote"), new ClearFormatter()).cleanup(entry);
@@ -249,7 +251,6 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
249251
* bibcodes
250252
*/
251253
private List<BibEntry> performSearchByIds(Collection<String> identifiers) throws FetcherException {
252-
253254
List<String> ids = identifiers.stream().filter(identifier -> !StringUtil.isBlank(identifier)).collect(Collectors.toList());
254255
if (ids.isEmpty()) {
255256
return Collections.emptyList();

src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public List<FieldChange> cleanup(BibEntry entry) {
4949
private List<FieldChange> cleanupSingleField(Field fieldKey, BibEntry entry) {
5050
if (!entry.hasField(fieldKey)) {
5151
// Not set -> nothing to do
52-
return new ArrayList<>();
52+
return Collections.emptyList();
5353
}
5454
String oldValue = entry.getField(fieldKey).orElse(null);
5555

5656
// Run formatter
5757
String newValue = formatter.format(oldValue);
5858

5959
if (oldValue.equals(newValue)) {
60-
return new ArrayList<>();
60+
return Collections.emptyList();
6161
} else {
6262
if (newValue.isEmpty()) {
6363
entry.clearField(fieldKey);

src/main/java/org/jabref/model/entry/BibEntry.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public void setField(Map<Field, String> fields) {
508508
/**
509509
* Set a field, and notify listeners about the change.
510510
*
511-
* @param field The field to set
511+
* @param field The field to set
512512
* @param value The value to set
513513
* @param eventSource Source the event is sent from
514514
*/
@@ -543,16 +543,15 @@ public Optional<FieldChange> setField(Field field, String value, EntriesEventSou
543543
/**
544544
* Set a field, and notify listeners about the change.
545545
*
546-
* @param field The field to set.
546+
* @param field The field to set.
547547
* @param value The value to set.
548548
*/
549549
public Optional<FieldChange> setField(Field field, String value) {
550550
return setField(field, value, EntriesEventSource.LOCAL);
551551
}
552552

553553
/**
554-
* Remove the mapping for the field name, and notify listeners about
555-
* the change.
554+
* Remove the mapping for the field name, and notify listeners about the change.
556555
*
557556
* @param field The field to clear.
558557
*/
@@ -588,9 +587,9 @@ public Optional<FieldChange> clearField(Field field, EntriesEventSource eventSou
588587
* database argument is given, this method will try to look up missing fields in
589588
* entries linked by the "crossref" field, if any.
590589
*
591-
* @param fields An array of field names to be checked.
592-
* @param database The database in which to look up crossref'd entries, if any. This
593-
* argument can be null, meaning that no attempt will be made to follow crossrefs.
590+
* @param fields An array of field names to be checked.
591+
* @param database The database in which to look up crossref'd entries, if any. This argument can be null, meaning
592+
* that no attempt will be made to follow crossrefs.
594593
* @return true if all fields are set or could be resolved, false otherwise.
595594
*/
596595
public boolean allFieldsPresent(Collection<OrFields> fields, BibDatabase database) {
@@ -610,9 +609,11 @@ public Object clone() {
610609

611610
/**
612611
* This returns a canonical BibTeX serialization. Special characters such as "{" or "&" are NOT escaped, but written
613-
* as is
612+
* as is. In case the JabRef "hack" for distinguishing "field = value" and "field = {value}" (in .bib files) is
613+
* used, it is output as "field = {#value#}", which may cause headaches in debugging. We nevertheless do it this way
614+
* to a) enable debugging the internal representation and b) save time at this method.
614615
* <p>
615-
* Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key
616+
* Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key.
616617
*/
617618
@Override
618619
public String toString() {

src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ public void setUp() {
2121
public void formatExample() {
2222
assertEquals("#dec#", formatter.format(formatter.getExampleInput()));
2323
}
24+
25+
@Test
26+
public void plainAprilShouldBeApril() {
27+
assertEquals("#apr#", formatter.format("#apr#"));
28+
}
2429
}

0 commit comments

Comments
 (0)