Skip to content
Closed
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the tab showing the fulltext search results would appear blank after switching library. [#13241](https://github.com/JabRef/jabref/issues/13241)
- We fixed an issue where the groups were still displayed after closing all libraries. [#13382](https://github.com/JabRef/jabref/issues/13382)
- Enhanced field selection logic in the Merge Entries dialog when fetching from DOI to prefer valid years and entry types. [#12549](https://github.com/JabRef/jabref/issues/12549)
- We fixed an issue where the year was empty on a bibliographic DOI data lookup. [#13673](https://github.com/JabRef/jabref/issues/13673)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public ComparisonResult compare(String leftValue, String rightValue) {
Optional<Integer> leftYear = extractYear(leftValue);
Optional<Integer> rightYear = extractYear(rightValue);

if (leftYear.isEmpty() || rightYear.isEmpty()) {
return checkEmptyValues(leftYear, rightYear);
}

boolean leftYearInRange = (leftYear.get() >= 1800) && (leftYear.get() <= Year.now().getValue() + 2);

if (leftYearInRange) {
Expand Down Expand Up @@ -59,4 +63,21 @@ private Optional<Integer> extractYear(String value) {
}
return Optional.empty();
}

/**
* Prevents the years from being empty, so the following logic has non empty values
*
* @param leftValue year from the library (or candidate)
* @param rightValue year from the fetcher (or existing record)
* @return ComparisonResult depending on which value is empty: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED
*/
private ComparisonResult checkEmptyValues(Optional<Integer> leftValue, Optional<Integer> rightValue) {
if (leftValue.isEmpty() && rightValue.isEmpty()) {
return ComparisonResult.UNDETERMINED;
} else if (leftValue.isEmpty()) {
return ComparisonResult.RIGHT_BETTER;
} else {
return ComparisonResult.LEFT_BETTER;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jabref.logic.bibtex.comparator;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class YearFieldValuePlausibilityComparatorTest {

private final YearFieldValuePlausibilityComparator comparator = new YearFieldValuePlausibilityComparator();
@Test
void compareEmptyValuesTest() {
String emptyString = "";
String validYearString = "1999";

ComparisonResult leftRight = ComparisonResult.LEFT_BETTER;
Copy link
Member

Choose a reason for hiding this comment

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

Please remove, the enum names are descriptive enough.

ComparisonResult rightRight = ComparisonResult.RIGHT_BETTER;
ComparisonResult undetermined = ComparisonResult.UNDETERMINED;

assertEquals(rightRight, comparator.compare(emptyString, validYearString));
assertEquals(leftRight, comparator.compare(validYearString, emptyString));
assertEquals(undetermined, comparator.compare(emptyString, emptyString));
}
}
Loading