Skip to content

Commit a9eb978

Browse files
tobiasdiezlenhard
authored andcommitted
Mark some methods as deprecated in BibEntry and BibDatabase (JabRef#1913)
* Mark some methods as deprecated in BibEntry and BibDatabase * Rename getResolvedFieldOrAlias * Use flatmap
1 parent 357be5c commit a9eb978

33 files changed

+188
-184
lines changed

src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void init() throws Exception {
5858
entry.setField("keyword", "testkeyword");
5959
entry.setField("year", "1" + i);
6060
entry.setField("rnd", "2" + randomizer.nextInt());
61-
database.insertEntry(entry);
61+
database.insertEntryWithDuplicationCheck(entry);
6262
}
6363
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
6464
StringSaveSession saveSession = databaseWriter.savePartOfDatabase(

src/main/java/net/sf/jabref/collab/EntryAddChange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public EntryAddChange(BibEntry diskEntry) {
3131
@Override
3232
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
3333
diskEntry.setId(IdGenerator.next());
34-
panel.getDatabase().insertEntry(diskEntry);
35-
secondary.insertEntry(diskEntry);
34+
panel.getDatabase().insertEntryWithDuplicationCheck(diskEntry);
35+
secondary.insertEntryWithDuplicationCheck(diskEntry);
3636
undoEdit.addEdit(new UndoableInsertEntry(panel.getDatabase(), diskEntry, panel));
3737
return true;
3838
}

src/main/java/net/sf/jabref/external/DroppedFileHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo
291291

292292
aXmpEntriesInFile.setId(IdGenerator.next());
293293
edits.addEdit(new UndoableInsertEntry(panel.getDatabase(), aXmpEntriesInFile, panel));
294-
panel.getDatabase().insertEntry(aXmpEntriesInFile);
294+
panel.getDatabase().insertEntryWithDuplicationCheck(aXmpEntriesInFile);
295295
doLink(aXmpEntriesInFile, fileType, destFilename, true, edits);
296296

297297
}

src/main/java/net/sf/jabref/gui/BasePanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public void run() {
466466
bes = entry;
467467
// Store the old value:
468468
oldvals.put(bes, bes.getCiteKeyOptional().orElse(null));
469-
bibDatabaseContext.getDatabase().setCiteKeyForEntry(bes, null);
469+
bes.clearCiteKey();
470470
}
471471
}
472472

@@ -824,7 +824,7 @@ private void paste() {
824824
// independently of the copied
825825
// ones.
826826
be.setId(IdGenerator.next());
827-
bibDatabaseContext.getDatabase().insertEntry(be);
827+
bibDatabaseContext.getDatabase().insertEntryWithDuplicationCheck(be);
828828

829829
ce.addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this));
830830

@@ -1136,7 +1136,7 @@ public BibEntry newEntry(EntryType type) {
11361136
String id = IdGenerator.next();
11371137
final BibEntry be = new BibEntry(id, actualType.getName());
11381138
try {
1139-
bibDatabaseContext.getDatabase().insertEntry(be);
1139+
bibDatabaseContext.getDatabase().insertEntryWithDuplicationCheck(be);
11401140
// Set owner/timestamp if options are enabled:
11411141
List<BibEntry> list = new ArrayList<>();
11421142
list.add(be);
@@ -1290,7 +1290,7 @@ public void listen(EntryChangedEvent entryChangedEvent) {
12901290
public void insertEntry(final BibEntry bibEntry) {
12911291
if (bibEntry != null) {
12921292
try {
1293-
bibDatabaseContext.getDatabase().insertEntry(bibEntry);
1293+
bibDatabaseContext.getDatabase().insertEntryWithDuplicationCheck(bibEntry);
12941294
if (Globals.prefs.getBoolean(JabRefPreferences.USE_OWNER)) {
12951295
// Set owner field to default value
12961296
UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs.getUpdateFieldPreferences());

src/main/java/net/sf/jabref/gui/DuplicateSearch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void run() {
124124
// and adding merged entries:
125125
if (!toAdd.isEmpty()) {
126126
for (BibEntry entry : toAdd) {
127-
panel.getDatabase().insertEntry(entry);
127+
panel.getDatabase().insertEntryWithDuplicationCheck(entry);
128128
ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel));
129129
}
130130
panel.markBaseChanged();

src/main/java/net/sf/jabref/gui/importer/EntryFromFileCreatorManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public int addEntriesFromFiles(List<File> files,
147147
if (!database.containsEntryWithId(entry.get().getId())) {
148148
// Work around SIDE EFFECT of creator.createEntry. The EntryFromPDFCreator also creates the entry in the table
149149
// Therefore, we only insert the entry if it is not already present
150-
if (database.insertEntry(entry.get())) {
150+
if (database.insertEntryWithDuplicationCheck(entry.get())) {
151151
importGUIMessages.add("Problem importing " + f.getPath() + ": Insert into BibDatabase failed.");
152152
} else {
153153
count++;

src/main/java/net/sf/jabref/gui/importer/ImportInspectionDialog.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private void generateKeyForEntry(BibEntry entry) {
458458

459459
entry.setId(IdGenerator.next());
460460
// Add the entry to the database we are working with:
461-
database.insertEntry(entry);
461+
database.insertEntryWithDuplicationCheck(entry);
462462

463463
// Generate a unique key:
464464
BibtexKeyPatternUtil.makeLabel(localMetaData, database, entry,
@@ -501,7 +501,7 @@ private void generateKeys() {
501501
for (BibEntry entry : entries) {
502502

503503
entry.setId(IdGenerator.next());
504-
database.insertEntry(entry);
504+
database.insertEntryWithDuplicationCheck(entry);
505505

506506
BibtexKeyPatternUtil.makeLabel(localMetaData, database, entry,
507507
Globals.prefs.getBibtexKeyPatternPreferences());
@@ -735,7 +735,7 @@ private void addSelectedEntries(NamedCompound ce, final List<BibEntry> selected)
735735
}
736736

737737
entry.setId(IdGenerator.next());
738-
panel.getDatabase().insertEntry(entry);
738+
panel.getDatabase().insertEntryWithDuplicationCheck(entry);
739739
ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel));
740740

741741
}

src/main/java/net/sf/jabref/gui/importer/ImportMenuItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private ParserResult mergeImportResults(List<ImportFormatReader.UnknownFormatImp
206206

207207
// Merge entries:
208208
for (BibEntry entry : pr.getDatabase().getEntries()) {
209-
database.insertEntry(entry);
209+
database.insertEntryWithDuplicationCheck(entry);
210210
}
211211

212212
// Merge strings:
@@ -233,7 +233,7 @@ private ParserResult mergeImportResults(List<ImportFormatReader.UnknownFormatImp
233233
if (markEntries) {
234234
EntryMarker.markEntry(entry, EntryMarker.IMPORT_MARK_LEVEL, false, new NamedCompound(""));
235235
}
236-
database.insertEntry(entry);
236+
database.insertEntryWithDuplicationCheck(entry);
237237
}
238238
}
239239
}

src/main/java/net/sf/jabref/gui/importer/actions/AppendDatabaseAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private static void mergeFromBibtex(JabRefFrame frame, BasePanel panel, ParserRe
118118
be.setId(IdGenerator.next());
119119
UpdateField.setAutomaticFields(be, overwriteOwner, overwriteTimeStamp,
120120
Globals.prefs.getUpdateFieldPreferences());
121-
database.insertEntry(be);
121+
database.insertEntryWithDuplicationCheck(be);
122122
appendedEntries.add(be);
123123
originalEntries.add(originalEntry);
124124
ce.addEdit(new UndoableInsertEntry(database, be, panel));

src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Object getColumnValue(BibEntry entry) {
9494

9595
Optional<String> content = Optional.empty();
9696
for (String field : bibtexFields) {
97-
content = BibDatabase.getResolvedField(field, entry, database.orElse(null));
97+
content = entry.getResolvedFieldOrAlias(field, database.orElse(null));
9898
if (content.isPresent()) {
9999
isNameColumn = InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES);
100100
break;
@@ -127,7 +127,7 @@ public JLabel getHeaderLabel() {
127127
* The reasons for being different are (combinations may also happen):
128128
* - The entry has a crossref where the field content is obtained from
129129
* - The field has a string in it (which getColumnValue() resolves)
130-
* - There are some alias fields. For example, if the entry has a date field but no year field, getResolvedField()
130+
* - There are some alias fields. For example, if the entry has a date field but no year field, getResolvedFieldOrAlias()
131131
* will return the year value from the date field when queried for year
132132
*
133133
*
@@ -148,7 +148,7 @@ public boolean isResolved(BibEntry entry) {
148148
return false;
149149
} else {
150150
plainFieldContent = entry.getField(field);
151-
resolvedFieldContent = BibDatabase.getResolvedField(field, entry, database.orElse(null));
151+
resolvedFieldContent = entry.getResolvedFieldOrAlias(field, database.orElse(null));
152152
}
153153

154154
if (resolvedFieldContent.isPresent()) {

0 commit comments

Comments
 (0)