Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Apr 7, 2024
1 parent ce430fa commit 7adb334
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ private void extractReferences(Iterator<Path> fileListIterator, ParserResult res
}

StringJoiner cites = new StringJoiner(",");
int count = 0;
// required because of "orElseGet"
var ref = new Object() {
int count = 0;
};
for (BibEntry importedEntry : result.getDatabase().getEntries()) {
count++;
ref.count++;
Optional<String> citationKey = importedEntry.getCitationKey();
if (citationKey.isPresent()) {
cites.add(citationKey.get());
} else {
cites.add(citationKey.orElseGet(() -> {
String sourceCitationKey = currentEntry.getCitationKey().orElse("unknown");
String newCitationKey;
// Could happen if no author and no year is present
Expand All @@ -187,11 +188,11 @@ private void extractReferences(Iterator<Path> fileListIterator, ParserResult res
if (matcher.hasMatch()) {
newCitationKey = sourceCitationKey + "-" + matcher.group(1);
} else {
newCitationKey = sourceCitationKey + "-" + count;
newCitationKey = sourceCitationKey + "-" + ref.count;
}
importedEntry.setCitationKey(newCitationKey);
cites.add(newCitationKey);
}
return newCitationKey;
}));
}
currentEntry.setField(StandardField.CITES, cites.toString());
}
Expand Down

0 comments on commit 7adb334

Please sign in to comment.