From 4e0ff503c80a7feb65edf3ff2caf1920642fe69a Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 27 Aug 2016 12:24:28 +0200 Subject: [PATCH] Fixed some minor things and removed the final BibEntry.getField() (#1870) --- .../jabref/shared/DBMSSynchronizerTest.java | 6 +- .../jabref/cli/CrossrefFetcherEvaluator.java | 11 +- .../net/sf/jabref/collab/EntryChange.java | 18 ++- .../sf/jabref/external/AttachFileAction.java | 4 +- .../net/sf/jabref/external/AutoSetLinks.java | 2 +- .../jabref/external/DroppedFileHandler.java | 2 +- .../jabref/external/FindFullTextAction.java | 4 +- .../jabref/external/SynchronizeFileField.java | 2 +- .../TransferableFileLinkSelection.java | 2 +- .../sf/jabref/external/WriteXMPAction.java | 4 +- .../external/WriteXMPEntryEditorAction.java | 4 +- .../java/net/sf/jabref/gui/BasePanel.java | 16 +- .../java/net/sf/jabref/gui/EntryMarker.java | 16 +- .../jabref/gui/FindUnlinkedFilesDialog.java | 2 - .../java/net/sf/jabref/gui/JabRefFrame.java | 6 +- .../sf/jabref/gui/ReplaceStringDialog.java | 2 +- .../gui/actions/MassSetFieldAction.java | 6 +- .../sf/jabref/gui/desktop/JabRefDesktop.java | 2 +- .../jabref/gui/entryeditor/EntryEditor.java | 6 +- .../gui/entryeditor/EntryEditorTab.java | 4 +- .../gui/importer/EntryFromFileCreator.java | 4 +- .../gui/importer/ImportInspectionDialog.java | 24 +-- .../importer/fetcher/ACMPortalFetcher.java | 4 +- .../importer/fetcher/DiVAtoBibTeXFetcher.java | 4 +- .../fetcher/GoogleScholarFetcher.java | 2 +- .../importer/fetcher/IEEEXploreFetcher.java | 20 +-- .../importer/fetcher/ISBNtoBibTeXFetcher.java | 4 +- .../gui/importer/fetcher/OAI2Fetcher.java | 2 +- .../gui/journals/UndoableAbbreviator.java | 2 +- .../gui/journals/UndoableUnabbreviator.java | 2 +- .../jabref/gui/maintable/MainTableColumn.java | 2 +- .../maintable/MainTableSelectionListener.java | 8 +- .../maintable/SpecialMainTableColumns.java | 10 +- .../sf/jabref/gui/menus/FileHistoryMenu.java | 13 +- .../sf/jabref/gui/menus/RightClickMenu.java | 4 +- .../gui/mergeentries/FetchAndMergeEntry.java | 2 +- .../jabref/gui/mergeentries/MergeEntries.java | 12 +- .../mergeentries/MergeFetchedEntryDialog.java | 6 +- .../sf/jabref/gui/openoffice/OOBibBase.java | 4 +- .../gui/plaintextimport/TextInputDialog.java | 2 +- .../net/sf/jabref/gui/preftabs/FileTab.java | 2 - .../gui/search/SearchResultsDialog.java | 14 +- .../gui/util/comparator/IconComparator.java | 4 +- .../comparator/RankingFieldComparator.java | 4 +- .../net/sf/jabref/logic/TypedBibEntry.java | 4 +- .../autocompleter/DefaultAutoCompleter.java | 2 +- .../EntireFieldAutoCompleter.java | 2 +- .../autocompleter/NameFieldAutoCompleter.java | 2 +- .../sf/jabref/logic/auxparser/AuxParser.java | 2 +- .../jabref/logic/bibtex/BibEntryWriter.java | 2 +- .../bibtex/comparator/EntryComparator.java | 4 +- .../BibtexKeyPatternUtil.java | 36 ++--- src/main/java/net/sf/jabref/logic/bst/VM.java | 4 +- .../jabref/logic/cleanup/BiblatexCleanup.java | 10 +- .../sf/jabref/logic/cleanup/DoiCleanup.java | 8 +- .../logic/cleanup/FieldFormatterCleanup.java | 2 +- .../logic/cleanup/FileLinksCleanup.java | 2 +- .../sf/jabref/logic/cleanup/ISSNCleanup.java | 2 +- .../cleanup/UpgradePdfPsToFileCleanup.java | 4 +- .../jabref/logic/exporter/OOCalcDatabase.java | 2 +- .../sf/jabref/logic/groups/GroupsUtil.java | 6 +- .../sf/jabref/logic/groups/KeywordGroup.java | 10 +- .../logic/importer/FulltextFetchers.java | 2 +- .../sf/jabref/logic/importer/fetcher/ACS.java | 2 +- .../jabref/logic/importer/fetcher/ArXiv.java | 4 +- .../logic/importer/fetcher/CrossRef.java | 8 +- .../logic/importer/fetcher/DOItoBibTeX.java | 2 +- .../logic/importer/fetcher/DoiResolution.java | 2 +- .../logic/importer/fetcher/GoogleScholar.java | 2 +- .../jabref/logic/importer/fetcher/IEEE.java | 4 +- .../logic/importer/fetcher/ScienceDirect.java | 2 +- .../logic/importer/fetcher/SpringerLink.java | 2 +- .../importer/fileformat/BibtexParser.java | 2 +- .../importer/fileformat/CopacImporter.java | 2 +- .../importer/fileformat/FreeCiteImporter.java | 2 +- .../fileformat/PdfContentImporter.java | 4 +- .../logic/importer/util/JSONEntryParser.java | 2 +- .../logic/importer/util/OAI2Handler.java | 2 +- .../jabref/logic/integrity/ISBNChecker.java | 2 +- .../jabref/logic/integrity/ISSNChecker.java | 2 +- .../logic/integrity/IntegrityCheck.java | 22 +-- .../net/sf/jabref/logic/mods/MODSEntry.java | 52 +++---- .../sf/jabref/logic/msbib/MSBibConverter.java | 42 +++--- .../sf/jabref/logic/openoffice/OOUtil.java | 2 +- .../search/rules/GrammarBasedSearchRule.java | 2 +- .../search/rules/RegexBasedSearchRule.java | 2 +- .../net/sf/jabref/logic/util/UpdateField.java | 2 +- .../logic/util/io/DatabaseFileLookup.java | 2 +- .../net/sf/jabref/logic/util/io/FileUtil.java | 2 +- .../java/net/sf/jabref/logic/xmp/XMPUtil.java | 4 - .../net/sf/jabref/model/DuplicateCheck.java | 8 +- .../sf/jabref/model/database/BibDatabase.java | 2 +- .../model/database/KeyChangeListener.java | 2 +- .../net/sf/jabref/model/entry/BibEntry.java | 36 ++--- .../net/sf/jabref/model/entry/EntryUtil.java | 2 +- .../net/sf/jabref/shared/DBMSProcessor.java | 4 +- .../sf/jabref/shared/DBMSSynchronizer.java | 2 +- .../specialfields/SpecialFieldsUtils.java | 4 +- .../EntryFromFileCreatorManagerTest.java | 2 +- .../gui/importer/EntryFromPDFCreatorTest.java | 4 +- .../ConvertLegacyExplicitGroupsTest.java | 4 +- .../fetcher/OAI2HandlerFetcherTest.java | 44 +++--- .../logic/bibtex/BibEntryWriterTest.java | 2 +- .../logic/cleanup/CleanupWorkerTest.java | 42 +++--- .../jabref/logic/cleanup/ISSNCleanupTest.java | 6 +- .../logic/cleanup/MoveFilesCleanupTest.java | 4 +- .../logic/cleanup/RenamePdfCleanupTest.java | 8 +- .../exporter/FieldFormatterCleanupsTest.java | 20 +-- .../logic/importer/OpenDatabaseTest.java | 6 +- .../logic/importer/fetcher/ArXivTest.java | 2 +- .../logic/importer/fetcher/GVKParserTest.java | 10 +- .../fileformat/BibtexImporterTest.java | 52 +++---- .../importer/fileformat/BibtexParserTest.java | 138 +++++++++--------- .../fileformat/EndnoteImporterTest.java | 68 ++++----- .../importer/fileformat/IsiImporterTest.java | 126 ++++++++-------- .../fileformat/MedlinePlainImporterTest.java | 18 +-- .../importer/fileformat/OvidImporterTest.java | 62 ++++---- .../fileformat/PdfXmpImporterTest.java | 8 +- .../importer/util/JSONEntryParserTest.java | 24 +-- .../sf/jabref/logic/util/UpdateFieldTest.java | 6 +- .../jabref/logic/xmp/XMPSchemaBibtexTest.java | 2 +- .../net/sf/jabref/logic/xmp/XMPUtilTest.java | 40 ++--- .../model/database/KeyChangeListenerTest.java | 20 +-- .../sf/jabref/model/entry/BibEntryTest.java | 2 +- .../sf/jabref/model/entry/BibEntryTests.java | 6 +- .../specialfields/SpecialFieldsUtilsTest.java | 10 +- 126 files changed, 672 insertions(+), 682 deletions(-) diff --git a/src/databaseTest/java/net/sf/jabref/shared/DBMSSynchronizerTest.java b/src/databaseTest/java/net/sf/jabref/shared/DBMSSynchronizerTest.java index 6e8f8d41ea8..a5d744160c4 100644 --- a/src/databaseTest/java/net/sf/jabref/shared/DBMSSynchronizerTest.java +++ b/src/databaseTest/java/net/sf/jabref/shared/DBMSSynchronizerTest.java @@ -90,8 +90,8 @@ public void testFieldChangedEventListener() { List actualEntries = dbmsProcessor.getSharedEntries(); Assert.assertEquals(1, actualEntries.size()); - Assert.assertEquals(expectedEntry.getFieldOptional("author"), actualEntries.get(0).getFieldOptional("author")); - Assert.assertEquals("The nano processor1", actualEntries.get(0).getFieldOptional("title").get()); + Assert.assertEquals(expectedEntry.getField("author"), actualEntries.get(0).getField("author")); + Assert.assertEquals("The nano processor1", actualEntries.get(0).getField("title").get()); } @@ -191,7 +191,7 @@ public void testApplyMetaData() { dbmsSynchronizer.applyMetaData(); - Assert.assertEquals("wirthlin, michael j1", bibEntry.getFieldOptional("author").get()); + Assert.assertEquals("wirthlin, michael j1", bibEntry.getField("author").get()); } diff --git a/src/main/java/net/sf/jabref/cli/CrossrefFetcherEvaluator.java b/src/main/java/net/sf/jabref/cli/CrossrefFetcherEvaluator.java index 3a9bd24e736..37de1b72ec7 100644 --- a/src/main/java/net/sf/jabref/cli/CrossrefFetcherEvaluator.java +++ b/src/main/java/net/sf/jabref/cli/CrossrefFetcherEvaluator.java @@ -27,19 +27,20 @@ public class CrossrefFetcherEvaluator { public static void main(String[] args) throws IOException, InterruptedException { Globals.prefs = JabRefPreferences.getInstance(); try (FileReader reader = new FileReader(args[0])) { - BibtexParser parser = new BibtexParser(new FileReader(args[0]), Globals.prefs.getImportFormatPreferences()); + BibtexParser parser = new BibtexParser(reader, Globals.prefs.getImportFormatPreferences()); ParserResult result = parser.parse(); BibDatabase db = result.getDatabase(); - int total = db.getEntryCount(); + List entries = db.getEntries(); AtomicInteger dois = new AtomicInteger(); AtomicInteger doiFound = new AtomicInteger(); AtomicInteger doiNew = new AtomicInteger(); AtomicInteger doiIdentical = new AtomicInteger(); - List entries = db.getEntries(); - CountDownLatch countDownLatch = new CountDownLatch(entries.size()); + int total = entries.size(); + + CountDownLatch countDownLatch = new CountDownLatch(total); ExecutorService executorService = Executors.newFixedThreadPool(5); @@ -48,7 +49,7 @@ public static void main(String[] args) throws IOException, InterruptedException @Override public void run() { - Optional origDOI = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional origDOI = entry.getField(FieldName.DOI).flatMap(DOI::build); if (origDOI.isPresent()) { dois.incrementAndGet(); Optional crossrefDOI = CrossRef.findDOI(entry); diff --git a/src/main/java/net/sf/jabref/collab/EntryChange.java b/src/main/java/net/sf/jabref/collab/EntryChange.java index 0bddca794b9..17e2998c8fb 100644 --- a/src/main/java/net/sf/jabref/collab/EntryChange.java +++ b/src/main/java/net/sf/jabref/collab/EntryChange.java @@ -51,19 +51,21 @@ public EntryChange(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskEntry) { allFields.addAll(diskEntry.getFieldNames()); for (String field : allFields) { - String mem = memEntry.getField(field); - String tmp = tmpEntry.getField(field); - String disk = diskEntry.getField(field); + Optional mem = memEntry.getField(field); + Optional tmp = tmpEntry.getField(field); + Optional disk = diskEntry.getField(field); - if ((tmp != null) && (disk != null)) { + if ((tmp.isPresent()) && (disk.isPresent())) { if (!tmp.equals(disk)) { // Modified externally. - add(new FieldChange(field, memEntry, tmpEntry, mem, tmp, disk)); + add(new FieldChange(field, memEntry, tmpEntry, mem.orElse(null), tmp.get(), disk.get())); } - } else if (((tmp == null) && (disk != null) && !disk.isEmpty()) || ((disk == null) && (tmp != null) && !tmp.isEmpty() - && (mem != null) && !mem.isEmpty())) { + } else if (((!tmp.isPresent()) && (disk.isPresent()) && !disk.get().isEmpty()) + || ((!disk.isPresent()) && (tmp.isPresent()) && !tmp.get().isEmpty() + && (mem.isPresent()) && !mem.get().isEmpty())) { // Added externally. - add(new FieldChange(field, memEntry, tmpEntry, mem, tmp, disk)); + add(new FieldChange(field, memEntry, tmpEntry, mem.orElse(null), tmp.orElse(null), + disk.orElse(null))); } } } diff --git a/src/main/java/net/sf/jabref/external/AttachFileAction.java b/src/main/java/net/sf/jabref/external/AttachFileAction.java index 8429df58221..80af0232530 100644 --- a/src/main/java/net/sf/jabref/external/AttachFileAction.java +++ b/src/main/java/net/sf/jabref/external/AttachFileAction.java @@ -39,12 +39,12 @@ public void action() { editor.setVisible(true, true); if (editor.okPressed()) { FileListTableModel model = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(model::setContent); + entry.getField(FieldName.FILE).ifPresent(model::setContent); model.addEntry(model.getRowCount(), flEntry); String newVal = model.getStringRepresentation(); UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, - entry.getFieldOptional(FieldName.FILE).orElse(null), newVal); + entry.getField(FieldName.FILE).orElse(null), newVal); entry.setField(FieldName.FILE, newVal); panel.getUndoManager().addEdit(ce); panel.markBaseChanged(); diff --git a/src/main/java/net/sf/jabref/external/AutoSetLinks.java b/src/main/java/net/sf/jabref/external/AutoSetLinks.java index c603e30635a..ea2d542326f 100644 --- a/src/main/java/net/sf/jabref/external/AutoSetLinks.java +++ b/src/main/java/net/sf/jabref/external/AutoSetLinks.java @@ -116,7 +116,7 @@ public void run() { // Iterate over the entries: for (Entry> entryFilePair : result.entrySet()) { FileListTableModel tableModel; - Optional oldVal = entryFilePair.getKey().getFieldOptional(FieldName.FILE); + Optional oldVal = entryFilePair.getKey().getField(FieldName.FILE); if (singleTableModel == null) { tableModel = new FileListTableModel(); oldVal.ifPresent(tableModel::setContent); diff --git a/src/main/java/net/sf/jabref/external/DroppedFileHandler.java b/src/main/java/net/sf/jabref/external/DroppedFileHandler.java index 0270002bd6b..ac5799715d0 100644 --- a/src/main/java/net/sf/jabref/external/DroppedFileHandler.java +++ b/src/main/java/net/sf/jabref/external/DroppedFileHandler.java @@ -388,7 +388,7 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy private void doLink(BibEntry entry, ExternalFileType fileType, String filename, boolean avoidDuplicate, NamedCompound edits) { - Optional oldValue = entry.getFieldOptional(FieldName.FILE); + Optional oldValue = entry.getField(FieldName.FILE); FileListTableModel tm = new FileListTableModel(); oldValue.ifPresent(tm::setContent); diff --git a/src/main/java/net/sf/jabref/external/FindFullTextAction.java b/src/main/java/net/sf/jabref/external/FindFullTextAction.java index dd51e90269f..32321abbd01 100644 --- a/src/main/java/net/sf/jabref/external/FindFullTextAction.java +++ b/src/main/java/net/sf/jabref/external/FindFullTextAction.java @@ -69,11 +69,11 @@ public void update() { try { def.download(result.get(), file -> { FileListTableModel tm = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent); + entry.getField(FieldName.FILE).ifPresent(tm::setContent); tm.addEntry(tm.getRowCount(), file); String newValue = tm.getStringRepresentation(); UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE, - entry.getFieldOptional(FieldName.FILE).orElse(null), newValue); + entry.getField(FieldName.FILE).orElse(null), newValue); entry.setField(FieldName.FILE, newValue); basePanel.getUndoManager().addEdit(edit); basePanel.markBaseChanged(); diff --git a/src/main/java/net/sf/jabref/external/SynchronizeFileField.java b/src/main/java/net/sf/jabref/external/SynchronizeFileField.java index 3d038fecaf7..aa6a7dd6a25 100644 --- a/src/main/java/net/sf/jabref/external/SynchronizeFileField.java +++ b/src/main/java/net/sf/jabref/external/SynchronizeFileField.java @@ -130,7 +130,7 @@ public void run() { boolean removeAllBroken = false; mainLoop: for (BibEntry aSel : sel) { panel.frame().setProgressBarValue(progress++); - final Optional old = aSel.getFieldOptional(FieldName.FILE); + final Optional old = aSel.getField(FieldName.FILE); // Check if a extension is set: if (old.isPresent() && !(old.get().isEmpty())) { FileListTableModel tableModel = new FileListTableModel(); diff --git a/src/main/java/net/sf/jabref/external/TransferableFileLinkSelection.java b/src/main/java/net/sf/jabref/external/TransferableFileLinkSelection.java index 1e461be5d63..a107765be3a 100644 --- a/src/main/java/net/sf/jabref/external/TransferableFileLinkSelection.java +++ b/src/main/java/net/sf/jabref/external/TransferableFileLinkSelection.java @@ -30,7 +30,7 @@ public class TransferableFileLinkSelection implements Transferable { public TransferableFileLinkSelection(BasePanel panel, List selection) { FileListTableModel tm = new FileListTableModel(); - selection.get(0).getFieldOptional(FieldName.FILE).ifPresent(tm::setContent); + selection.get(0).getField(FieldName.FILE).ifPresent(tm::setContent); if (tm.getRowCount() > 0) { // Find the default directory for this field type, if any: List dirs = panel.getBibDatabaseContext() diff --git a/src/main/java/net/sf/jabref/external/WriteXMPAction.java b/src/main/java/net/sf/jabref/external/WriteXMPAction.java index 7420c45a479..c28ba7cb8c0 100644 --- a/src/main/java/net/sf/jabref/external/WriteXMPAction.java +++ b/src/main/java/net/sf/jabref/external/WriteXMPAction.java @@ -120,7 +120,7 @@ public void run() { List files = new ArrayList<>(); // First check the (legacy) "pdf" field: - entry.getFieldOptional(FieldName.PDF) + entry.getField(FieldName.PDF) .ifPresent( pdf -> FileUtil .expandFilename(pdf, @@ -132,7 +132,7 @@ public void run() { .getFileDirectory(Globals.prefs.getFileDirectoryPreferences()); if (entry.hasField(FieldName.FILE)) { FileListTableModel tm = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent); + entry.getField(FieldName.FILE).ifPresent(tm::setContent); for (int j = 0; j < tm.getRowCount(); j++) { FileListEntry flEntry = tm.getEntry(j); if ((flEntry.type.isPresent()) && "pdf".equalsIgnoreCase(flEntry.type.get().getName())) { diff --git a/src/main/java/net/sf/jabref/external/WriteXMPEntryEditorAction.java b/src/main/java/net/sf/jabref/external/WriteXMPEntryEditorAction.java index ec22a36a630..82e4fa47fb5 100644 --- a/src/main/java/net/sf/jabref/external/WriteXMPEntryEditorAction.java +++ b/src/main/java/net/sf/jabref/external/WriteXMPEntryEditorAction.java @@ -54,7 +54,7 @@ public void actionPerformed(ActionEvent actionEvent) { List files = new ArrayList<>(); // First check the (legacy) "pdf" field: - entry.getFieldOptional(FieldName.PDF) + entry.getField(FieldName.PDF) .ifPresent(pdf -> FileUtil.expandFilename(pdf, panel.getBibDatabaseContext() .getFileDirectory(FieldName.PDF, Globals.prefs.getFileDirectoryPreferences())) .ifPresent(files::add)); @@ -63,7 +63,7 @@ public void actionPerformed(ActionEvent actionEvent) { List dirs = panel.getBibDatabaseContext().getFileDirectory(Globals.prefs.getFileDirectoryPreferences()); if (entry.hasField(FieldName.FILE)) { FileListTableModel tm = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent); + entry.getField(FieldName.FILE).ifPresent(tm::setContent); for (int j = 0; j < tm.getRowCount(); j++) { FileListEntry flEntry = tm.getEntry(j); if ((flEntry.type.isPresent()) && "pdf".equalsIgnoreCase(flEntry.type.get().getName())) { diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 8aefb54b0c8..82a638eca71 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -960,14 +960,14 @@ private void openExternalFile() { new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen(); return; } - FileListTableModel tableModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tableModel::setContent); - if (tableModel.getRowCount() == 0) { - // content in bibtex field is not readable + FileListTableModel fileListTableModel = new FileListTableModel(); + entry.getField(FieldName.FILE).ifPresent(fileListTableModel::setContent); + if (fileListTableModel.getRowCount() == 0) { + // content in BibTeX field is not readable new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen(); return; } - FileListEntry flEntry = tableModel.getEntry(0); + FileListEntry flEntry = fileListTableModel.getEntry(0); ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), entry, "", flEntry.link, flEntry.type.get().getIcon(), bibDatabaseContext, flEntry.type); item.openLink(); @@ -2010,9 +2010,9 @@ public void action() { final List bes = mainTable.getSelectedEntries(); if (bes.size() == 1) { String field = FieldName.DOI; - Optional link = bes.get(0).getFieldOptional(FieldName.DOI); + Optional link = bes.get(0).getField(FieldName.DOI); if (bes.get(0).hasField(FieldName.URL)) { - link = bes.get(0).getFieldOptional(FieldName.URL); + link = bes.get(0).getField(FieldName.URL); field = FieldName.URL; } if (link.isPresent()) { @@ -2027,7 +2027,7 @@ public void action() { // Look for web links in the "file" field as a fallback: FileListEntry entry = null; FileListTableModel tm = new FileListTableModel(); - bes.get(0).getFieldOptional(FieldName.FILE).ifPresent(tm::setContent); + bes.get(0).getField(FieldName.FILE).ifPresent(tm::setContent); for (int i = 0; i < tm.getRowCount(); i++) { FileListEntry flEntry = tm.getEntry(i); if (FieldName.URL.equalsIgnoreCase(flEntry.type.get().getName()) diff --git a/src/main/java/net/sf/jabref/gui/EntryMarker.java b/src/main/java/net/sf/jabref/gui/EntryMarker.java index 3c55b5aad15..b2f28a7a72a 100644 --- a/src/main/java/net/sf/jabref/gui/EntryMarker.java +++ b/src/main/java/net/sf/jabref/gui/EntryMarker.java @@ -29,7 +29,7 @@ public static void markEntry(BibEntry be, int markIncrement, boolean increment, int prevMarkLevel; String newValue = null; if (be.hasField(FieldName.MARKED_INTERNAL)) { - String markerString = be.getFieldOptional(FieldName.MARKED_INTERNAL).get(); + String markerString = be.getField(FieldName.MARKED_INTERNAL).get(); int index = markerString.indexOf(Globals.prefs.getWrappedUsername()); if (index >= 0) { // Already marked 1 for this user. @@ -57,7 +57,7 @@ public static void markEntry(BibEntry be, int markIncrement, boolean increment, } ce.addEdit(new UndoableFieldChange(be, FieldName.MARKED_INTERNAL, - be.getFieldOptional(FieldName.MARKED_INTERNAL).orElse(null), newValue)); + be.getField(FieldName.MARKED_INTERNAL).orElse(null), newValue)); be.setField(FieldName.MARKED_INTERNAL, newValue); } @@ -66,7 +66,7 @@ public static void markEntry(BibEntry be, int markIncrement, boolean increment, */ public static void unmarkEntry(BibEntry be, boolean onlyMaxLevel, BibDatabase database, NamedCompound ce) { if (be.hasField(FieldName.MARKED_INTERNAL)) { - String markerString = be.getFieldOptional(FieldName.MARKED_INTERNAL).get(); + String markerString = be.getField(FieldName.MARKED_INTERNAL).get(); if ("0".equals(markerString)) { if (!onlyMaxLevel) { unmarkOldStyle(be, database, ce); @@ -121,7 +121,7 @@ public static void unmarkEntry(BibEntry be, boolean onlyMaxLevel, BibDatabase da } String newVal = sb.length() > 0 ? sb.toString() : null;*/ ce.addEdit(new UndoableFieldChange(be, FieldName.MARKED_INTERNAL, - be.getFieldOptional(FieldName.MARKED_INTERNAL).get(), newValue)); + be.getField(FieldName.MARKED_INTERNAL).get(), newValue)); if (newValue == null) { be.clearField(FieldName.MARKED_INTERNAL); } else { @@ -144,7 +144,7 @@ public static void unmarkEntry(BibEntry be, boolean onlyMaxLevel, BibDatabase da private static void unmarkOldStyle(BibEntry be, BibDatabase database, NamedCompound ce) { Set owners = new TreeSet<>(); for (BibEntry entry : database.getEntries()) { - entry.getFieldOptional(FieldName.OWNER).ifPresent(owners::add); + entry.getField(FieldName.OWNER).ifPresent(owners::add); } owners.remove(Globals.prefs.get(JabRefPreferences.DEFAULT_OWNER)); StringBuilder sb = new StringBuilder(); @@ -156,11 +156,11 @@ private static void unmarkOldStyle(BibEntry be, BibDatabase database, NamedCompo String newVal = sb.toString(); if (newVal.isEmpty()) { ce.addEdit(new UndoableFieldChange(be, FieldName.MARKED_INTERNAL, - be.getFieldOptional(FieldName.MARKED_INTERNAL).orElse(null), null)); + be.getField(FieldName.MARKED_INTERNAL).orElse(null), null)); be.clearField(FieldName.MARKED_INTERNAL); } else { ce.addEdit(new UndoableFieldChange(be, FieldName.MARKED_INTERNAL, - be.getFieldOptional(FieldName.MARKED_INTERNAL).orElse(null), newVal)); + be.getField(FieldName.MARKED_INTERNAL).orElse(null), newVal)); be.setField(FieldName.MARKED_INTERNAL, newVal); } } @@ -169,7 +169,7 @@ public static int isMarked(BibEntry be) { if (!be.hasField(FieldName.MARKED_INTERNAL)) { return 0; } - String s = be.getFieldOptional(FieldName.MARKED_INTERNAL).get(); + String s = be.getField(FieldName.MARKED_INTERNAL).get(); if ("0".equals(s)) { return 1; } diff --git a/src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java b/src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java index 092473a20c5..2a7c8fe011f 100644 --- a/src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java +++ b/src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java @@ -43,7 +43,6 @@ import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; -import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; @@ -151,7 +150,6 @@ public class FindUnlinkedFilesDialog extends JDialog { private JComboBox comboBoxEntryTypeSelection; private JProgressBar progressBarSearching; private JProgressBar progressBarImporting; - private JFileChooser fileChooser; private MouseListener treeMouseListener; private Action actionSelectAll; diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index 77a22f2252d..95675220276 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -570,9 +570,9 @@ private JPopupMenu tabPopupMenu() { popupMenu.addSeparator(); - JMenuItem databaseProperties = new JMenuItem(Localization.lang("Database properties")); - databaseProperties.addActionListener(this.databaseProperties); - popupMenu.add(databaseProperties); + JMenuItem databasePropertiesMenu = new JMenuItem(Localization.lang("Database properties")); + databasePropertiesMenu.addActionListener(this.databaseProperties); + popupMenu.add(databasePropertiesMenu); JMenuItem bibtexKeyPatternBtn = new JMenuItem(Localization.lang("BibTeX key patterns")); bibtexKeyPatternBtn.addActionListener(bibtexKeyPattern); diff --git a/src/main/java/net/sf/jabref/gui/ReplaceStringDialog.java b/src/main/java/net/sf/jabref/gui/ReplaceStringDialog.java index f1a670d1f45..94ca5c080f1 100644 --- a/src/main/java/net/sf/jabref/gui/ReplaceStringDialog.java +++ b/src/main/java/net/sf/jabref/gui/ReplaceStringDialog.java @@ -207,7 +207,7 @@ private int replaceField(BibEntry be, String fieldname, NamedCompound ce) { if (!be.hasField(fieldname)) { return 0; } - String txt = be.getFieldOptional(fieldname).get(); + String txt = be.getField(fieldname).get(); StringBuilder sb = new StringBuilder(); int ind; int piv = 0; diff --git a/src/main/java/net/sf/jabref/gui/actions/MassSetFieldAction.java b/src/main/java/net/sf/jabref/gui/actions/MassSetFieldAction.java index 9cf35483fdf..f708d940d77 100644 --- a/src/main/java/net/sf/jabref/gui/actions/MassSetFieldAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/MassSetFieldAction.java @@ -261,7 +261,7 @@ private static UndoableEdit massSetField(Collection entries, String fi NamedCompound ce = new NamedCompound(Localization.lang("Set field")); for (BibEntry entry : entries) { - Optional oldVal = entry.getFieldOptional(field); + Optional oldVal = entry.getField(field); // If we are not allowed to overwrite values, check if there is a // nonempty // value already for this entry: @@ -293,14 +293,14 @@ private static UndoableEdit massRenameField(Collection entries, String boolean overwriteValues) { NamedCompound ce = new NamedCompound(Localization.lang("Rename field")); for (BibEntry entry : entries) { - Optional valToMove = entry.getFieldOptional(field); + Optional valToMove = entry.getField(field); // If there is no value, do nothing: if ((!valToMove.isPresent()) || valToMove.get().isEmpty()) { continue; } // If we are not allowed to overwrite values, check if there is a // non-empty value already for this entry for the new field: - Optional valInNewField = entry.getFieldOptional(newField); + Optional valInNewField = entry.getField(newField); if (!overwriteValues && (valInNewField.isPresent()) && !valInNewField.get().isEmpty()) { continue; } diff --git a/src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java index 9e9b2efb50f..c939ee2af14 100644 --- a/src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java @@ -215,7 +215,7 @@ public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, // User wants to change the type of this link. // First get a model of all file links for this entry: FileListTableModel tModel = new FileListTableModel(); - Optional oldValue = entry.getFieldOptional(FieldName.FILE); + Optional oldValue = entry.getField(FieldName.FILE); oldValue.ifPresent(tModel::setContent); FileListEntry flEntry = null; // Then find which one we are looking at: diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index f0a5d0bc939..efabcfbdc0c 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -807,7 +807,7 @@ private boolean storeSource() { // Then set all fields that have been set by the user. for (Entry field : newEntry.getFieldMap().entrySet()) { String fieldName = field.getKey(); - String oldValue = entry.getFieldOptional(fieldName).orElse(null); + String oldValue = entry.getField(fieldName).orElse(null); String newValue = field.getValue(); if (!Objects.equals(oldValue, newValue)) { // Test if the field is legally set. @@ -1159,7 +1159,7 @@ public void actionPerformed(ActionEvent event) { set = entry.hasField(fieldEditor.getFieldName()); } else { set = !((entry.hasField(fieldEditor.getFieldName())) - && toSet.equals(entry.getFieldOptional(fieldEditor.getFieldName()).orElse(null))); + && toSet.equals(entry.getField(fieldEditor.getFieldName()).orElse(null))); } if (set) { @@ -1174,7 +1174,7 @@ public void actionPerformed(ActionEvent event) { .format(toSet, fieldEditor.getFieldName()); } - String oldValue = entry.getFieldOptional(fieldEditor.getFieldName()).orElse(null); + String oldValue = entry.getField(fieldEditor.getFieldName()).orElse(null); if (toSet == null) { entry.clearField(fieldEditor.getFieldName()); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java index 9b3a611615a..ed99b3405a4 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java @@ -214,7 +214,7 @@ private boolean isFieldModified(FieldEditor fieldEditor) { if (text.isEmpty()) { return getEntry().hasField(fieldEditor.getFieldName()); } else { - return !Optional.of(text).equals(getEntry().getFieldOptional(fieldEditor.getFieldName())); + return !Optional.of(text).equals(getEntry().getField(fieldEditor.getFieldName())); } } @@ -277,7 +277,7 @@ public void setEntry(BibEntry entry) { try { updating = true; for (FieldEditor editor : editors.values()) { - String toSet = entry.getFieldOptional(editor.getFieldName()).orElse(""); + String toSet = entry.getField(editor.getFieldName()).orElse(""); if (!toSet.equals(editor.getText())) { editor.setText(toSet); } diff --git a/src/main/java/net/sf/jabref/gui/importer/EntryFromFileCreator.java b/src/main/java/net/sf/jabref/gui/importer/EntryFromFileCreator.java index 1fbeb8b1576..7db1e02323a 100644 --- a/src/main/java/net/sf/jabref/gui/importer/EntryFromFileCreator.java +++ b/src/main/java/net/sf/jabref/gui/importer/EntryFromFileCreator.java @@ -156,7 +156,7 @@ protected void appendToField(BibEntry entry, String field, String value) { if ((value == null) || value.isEmpty()) { return; } - Optional oVal = entry.getFieldOptional(field); + Optional oVal = entry.getField(field); if (oVal.isPresent()) { // TODO: find Jabref constant for delimter if (!oVal.get().contains(value)) { @@ -177,7 +177,7 @@ protected void addEntrysToEntry(BibEntry entry, List entrys) { protected void addEntryDataToEntry(BibEntry entry, BibEntry e) { for (String field : e.getFieldNames()) { - e.getFieldOptional(field).ifPresent(fieldContent -> appendToField(entry, field, fieldContent)); + e.getField(field).ifPresent(fieldContent -> appendToField(entry, field, fieldContent)); } } diff --git a/src/main/java/net/sf/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/net/sf/jabref/gui/importer/ImportInspectionDialog.java index ffdf3107cea..1f77cd09de5 100644 --- a/src/main/java/net/sf/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/net/sf/jabref/gui/importer/ImportInspectionDialog.java @@ -911,7 +911,7 @@ public void mouseClicked(MouseEvent e) { if (col == FILE_COL) { if (entry.hasField(FieldName.FILE)) { FileListTableModel tableModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tableModel::setContent); + entry.getField(FieldName.FILE).ifPresent(tableModel::setContent); if (tableModel.getRowCount() == 0) { return; } @@ -966,7 +966,7 @@ private void showFileFieldMenu(MouseEvent e) { JPopupMenu menu = new JPopupMenu(); int count = 0; FileListTableModel fileList = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(fileList::setContent); + entry.getField(FieldName.FILE).ifPresent(fileList::setContent); // If there are one or more links, open the first one: for (int i = 0; i < fileList.getRowCount(); i++) { FileListEntry flEntry = fileList.getEntry(i); @@ -995,7 +995,7 @@ private void openExternalLink(String fieldName, MouseEvent e) { final int row = glTable.rowAtPoint(e.getPoint()); BibEntry entry = sortedList.get(row); - entry.getFieldOptional(fieldName).ifPresent(link -> { + entry.getField(fieldName).ifPresent(link -> { try { JabRefDesktop.openExternalViewer(panel.getBibDatabaseContext(), link, fieldName); } catch (IOException ex) { @@ -1133,7 +1133,7 @@ public void actionPerformed(ActionEvent event) { } BibEntry entry = selectionModel.getSelected().get(0); String result = JOptionPane.showInputDialog(ImportInspectionDialog.this, Localization.lang("Enter URL"), - entry.getFieldOptional(FieldName.URL).orElse("")); + entry.getField(FieldName.URL).orElse("")); entries.getReadWriteLock().writeLock().lock(); try { if (result != null) { @@ -1188,7 +1188,7 @@ public void actionPerformed(ActionEvent actionEvent) { public void downloadComplete(FileListEntry file) { ImportInspectionDialog.this.toFront(); // Hack FileListTableModel localModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(localModel::setContent); + entry.getField(FieldName.FILE).ifPresent(localModel::setContent); localModel.addEntry(localModel.getRowCount(), file); entries.getReadWriteLock().writeLock().lock(); try { @@ -1224,7 +1224,7 @@ public void actionPerformed(ActionEvent actionEvent) { } } final FileListTableModel localModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(localModel::setContent); + entry.getField(FieldName.FILE).ifPresent(localModel::setContent); // We have a static utility method for searching for all relevant // links: JDialog diag = new JDialog(ImportInspectionDialog.this, true); @@ -1266,7 +1266,7 @@ public void actionPerformed(ActionEvent actionEvent) { editor.setVisible(true, true); if (editor.okPressed()) { FileListTableModel localModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(localModel::setContent); + entry.getField(FieldName.FILE).ifPresent(localModel::setContent); localModel.addEntry(localModel.getRowCount(), flEntry); entries.getReadWriteLock().writeLock().lock(); try { @@ -1282,7 +1282,7 @@ public void actionPerformed(ActionEvent actionEvent) { public void downloadComplete(FileListEntry file) { ImportInspectionDialog.this.toFront(); // Hack FileListTableModel localModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(localModel::setContent); + entry.getField(FieldName.FILE).ifPresent(localModel::setContent); localModel.addEntry(localModel.getRowCount(), file); entries.getReadWriteLock().writeLock().lock(); try { @@ -1429,7 +1429,7 @@ public Object getColumnValue(BibEntry entry, int i) { case FILE_COL: if (entry.hasField(FieldName.FILE)) { FileListTableModel model = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(model::setContent); + entry.getField(FieldName.FILE).ifPresent(model::setContent); fileLabel.setToolTipText(model.getToolTipHTMLRepresentation()); if ((model.getRowCount() > 0) && model.getEntry(0).type.isPresent()) { fileLabel.setIcon(model.getEntry(0).type.get().getIcon()); @@ -1440,7 +1440,7 @@ public Object getColumnValue(BibEntry entry, int i) { } case URL_COL: if (entry.hasField(FieldName.URL)) { - urlLabel.setToolTipText(entry.getFieldOptional(FieldName.URL).orElse("")); + urlLabel.setToolTipText(entry.getField(FieldName.URL).orElse("")); return urlLabel; } else { return null; @@ -1451,9 +1451,9 @@ public Object getColumnValue(BibEntry entry, int i) { } else { String field = INSPECTION_FIELDS.get(i - PAD); if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES)) { - return entry.getFieldOptional(field).map(AuthorList::fixAuthorNatbib).orElse(""); + return entry.getField(field).map(AuthorList::fixAuthorNatbib).orElse(""); } else { - return entry.getFieldOptional(field).orElse(null); + return entry.getField(field).orElse(null); } } } diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/ACMPortalFetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/ACMPortalFetcher.java index ffb8cbba8c9..9eec63449b9 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/ACMPortalFetcher.java @@ -181,7 +181,7 @@ public void getEntries(Map selection, ImportInspector inspector if (selentry.getValue()) { downloadEntryBibTeX(selentry.getKey(), fetchAbstract).ifPresent(entry -> { // Convert from HTML and optionally add curly brackets around key words to keep the case - entry.getFieldOptional(FieldName.TITLE).ifPresent(title -> { + entry.getField(FieldName.TITLE).ifPresent(title -> { title = title.replace("\\&", "&").replace("\\#", "#"); title = convertHTMLChars(title); @@ -197,7 +197,7 @@ public void getEntries(Map selection, ImportInspector inspector entry.setField(FieldName.TITLE, title); }); - entry.getFieldOptional(FieldName.ABSTRACT) + entry.getField(FieldName.ABSTRACT) .ifPresent(abstr -> entry.setField(FieldName.ABSTRACT, convertHTMLChars(abstr))); inspector.addEntry(entry); }); diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/DiVAtoBibTeXFetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/DiVAtoBibTeXFetcher.java index 84738a2562a..e0ce759db76 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/DiVAtoBibTeXFetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/DiVAtoBibTeXFetcher.java @@ -84,7 +84,7 @@ public boolean processQuery(String query, ImportInspector inspector, OutputPrint Globals.prefs.getImportFormatPreferences()); if (entry.isPresent()) { // Optionally add curly brackets around key words to keep the case - entry.get().getFieldOptional(FieldName.TITLE).ifPresent(title -> { + entry.get().getField(FieldName.TITLE).ifPresent(title -> { // Unit formatting if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) { title = unitsToLatexFormatter.format(title); @@ -97,7 +97,7 @@ public boolean processQuery(String query, ImportInspector inspector, OutputPrint entry.get().setField(FieldName.TITLE, title); }); - entry.get().getFieldOptional(FieldName.INSTITUTION).ifPresent( + entry.get().getField(FieldName.INSTITUTION).ifPresent( institution -> entry.get().setField(FieldName.INSTITUTION, new UnicodeToLatexFormatter().format(institution))); // Do not use the provided key diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/GoogleScholarFetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/GoogleScholarFetcher.java index 3ab5980c535..8b290eb0372 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/GoogleScholarFetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/GoogleScholarFetcher.java @@ -262,7 +262,7 @@ private BibEntry downloadEntry(String link) throws IOException { // Clean up some remaining HTML code from Elsevier(?) papers // Search for: Poincare algebra // to see an example - entry.getFieldOptional(FieldName.TITLE).ifPresent(title -> { + entry.getField(FieldName.TITLE).ifPresent(title -> { String newtitle = title.replaceAll("<.?i>([^<]*)", "$1"); if (!newtitle.equals(title)) { entry.setField(FieldName.TITLE, newtitle); diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/IEEEXploreFetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/IEEEXploreFetcher.java index 8261dd732f0..5bfd300c60c 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/IEEEXploreFetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/IEEEXploreFetcher.java @@ -255,7 +255,7 @@ private BibEntry cleanup(BibEntry entry) { } // clean up title - entry.getFieldOptional(FieldName.TITLE).ifPresent(title -> { + entry.getField(FieldName.TITLE).ifPresent(title -> { // USe the alt-text and replace image links title = title.replaceAll("[ ]?img src=[^ ]+ alt=\"([^\"]+)\">[ ]?", "\\$$1\\$"); // Try to sort out most of the /spl / conversions @@ -287,7 +287,7 @@ private BibEntry cleanup(BibEntry entry) { }); // clean up author - entry.getFieldOptional(FieldName.AUTHOR).ifPresent(author -> { + entry.getField(FieldName.AUTHOR).ifPresent(author -> { author = author.replaceAll("\\s+", " "); //reorder the "Jr." "Sr." etc to the correct ordering @@ -306,7 +306,7 @@ private BibEntry cleanup(BibEntry entry) { }); // clean up month - entry.getFieldOptional(FieldName.MONTH).filter(month -> !month.isEmpty()).ifPresent(month -> { + entry.getField(FieldName.MONTH).filter(month -> !month.isEmpty()).ifPresent(month -> { month = month.replace(".", ""); month = month.toLowerCase(); @@ -339,7 +339,7 @@ private BibEntry cleanup(BibEntry entry) { }); // clean up pages - entry.getFieldOptional(FieldName.PAGES).ifPresent(pages -> { + entry.getField(FieldName.PAGES).ifPresent(pages -> { String[] pageNumbers = pages.split("-"); if (pageNumbers.length == 2) { if (pageNumbers[0].equals(pageNumbers[1])) {// single page @@ -360,7 +360,7 @@ private BibEntry cleanup(BibEntry entry) { sourceField = FieldName.BOOKTITLE; } if (entry.hasField(sourceField)) { - String fullName = entry.getFieldOptional(sourceField).get(); + String fullName = entry.getField(sourceField).get(); if ("article".equals(type)) { int ind = fullName.indexOf(": Accepted for future publication"); if (ind > 0) { @@ -375,7 +375,7 @@ private BibEntry cleanup(BibEntry entry) { if (parts.length == 3) { fullName += parts[2]; } - entry.getFieldOptional(FieldName.NOTE).filter(note -> "Early Access".equals(note)).ifPresent(note -> { + entry.getField(FieldName.NOTE).filter(note -> "Early Access".equals(note)).ifPresent(note -> { entry.setField(FieldName.YEAR, "to be published"); entry.clearField(FieldName.MONTH); entry.clearField(FieldName.PAGES); @@ -453,7 +453,7 @@ private BibEntry cleanup(BibEntry entry) { fullName = fullName.trim(); fullName = fullName.replaceAll("^[tT]he ", "").replaceAll("^\\d{4} ", "").replaceAll("[,.]$", ""); - Optional year = entry.getFieldOptional(FieldName.YEAR); + Optional year = entry.getField(FieldName.YEAR); if (year.isPresent()) { fullName = fullName.replaceAll(", " + year.get() + "\\.?", ""); } @@ -467,7 +467,7 @@ private BibEntry cleanup(BibEntry entry) { } // clean up abstract - entry.getFieldOptional(FieldName.ABSTRACT).ifPresent(abstr -> { + entry.getField(FieldName.ABSTRACT).ifPresent(abstr -> { // Try to sort out most of the /spl / conversions // Deal with this specific nested type first abstr = abstr.replaceAll("/sub /spl infin//", "\\$_\\\\infty\\$"); @@ -486,11 +486,11 @@ private BibEntry cleanup(BibEntry entry) { }); // Clean up url - entry.getFieldOptional(FieldName.URL) + entry.getField(FieldName.URL) .ifPresent(url -> entry.setField(FieldName.URL, "http://ieeexplore.ieee.org" + url.replace("tp=&", ""))); // Replace ; as keyword separator - entry.getFieldOptional(FieldName.KEYWORDS).ifPresent(keys -> entry.setField(FieldName.KEYWORDS, + entry.getField(FieldName.KEYWORDS).ifPresent(keys -> entry.setField(FieldName.KEYWORDS, keys.replace(";", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)))); return entry; } diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/ISBNtoBibTeXFetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/ISBNtoBibTeXFetcher.java index 9feb0fbc9c2..f2e194cd13e 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/ISBNtoBibTeXFetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/ISBNtoBibTeXFetcher.java @@ -91,11 +91,11 @@ public Optional getEntryFromISBN(String query, OutputPrinter status) { Globals.prefs.getImportFormatPreferences()); bibEntry.ifPresent(entry -> { // Remove the added " Seiten" from the "pagetotal" field - entry.getFieldOptional(FieldName.PAGETOTAL) + entry.getField(FieldName.PAGETOTAL) .ifPresent(pagetotal -> entry.setField(FieldName.PAGETOTAL, pagetotal.replace(" Seiten", ""))); // Optionally add curly brackets around key words to keep the case - entry.getFieldOptional(FieldName.TITLE).ifPresent(title -> { + entry.getField(FieldName.TITLE).ifPresent(title -> { // Unit formatting if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) { title = unitsToLatexFormatter.format(title); diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/OAI2Fetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/OAI2Fetcher.java index fe7d1f73eea..f59479de516 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/OAI2Fetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/OAI2Fetcher.java @@ -183,7 +183,7 @@ public BibEntry importOai2Entry(String key) { /* Correct line breaks and spacing */ for (String name : be.getFieldNames()) { - be.getFieldOptional(name) + be.getField(name) .ifPresent(content -> be.setField(name, OAI2Handler.correctLineBreaks(content))); } diff --git a/src/main/java/net/sf/jabref/gui/journals/UndoableAbbreviator.java b/src/main/java/net/sf/jabref/gui/journals/UndoableAbbreviator.java index 29956e913da..72dba5a7696 100644 --- a/src/main/java/net/sf/jabref/gui/journals/UndoableAbbreviator.java +++ b/src/main/java/net/sf/jabref/gui/journals/UndoableAbbreviator.java @@ -32,7 +32,7 @@ public boolean abbreviate(BibDatabase database, BibEntry entry, String fieldName if (!entry.hasField(fieldName)) { return false; } - String text = entry.getFieldOptional(fieldName).get(); + String text = entry.getField(fieldName).get(); String origText = text; if (database != null) { text = database.resolveForStrings(text); diff --git a/src/main/java/net/sf/jabref/gui/journals/UndoableUnabbreviator.java b/src/main/java/net/sf/jabref/gui/journals/UndoableUnabbreviator.java index f3f675a5dfb..100a5c3e229 100644 --- a/src/main/java/net/sf/jabref/gui/journals/UndoableUnabbreviator.java +++ b/src/main/java/net/sf/jabref/gui/journals/UndoableUnabbreviator.java @@ -29,7 +29,7 @@ public boolean unabbreviate(BibDatabase database, BibEntry entry, String fieldNa if (!entry.hasField(fieldName)) { return false; } - String text = entry.getFieldOptional(fieldName).get(); + String text = entry.getField(fieldName).get(); String origText = text; if (database != null) { text = database.resolveForStrings(text); diff --git a/src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java b/src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java index eceb4f594c6..03f20746684 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java +++ b/src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java @@ -147,7 +147,7 @@ public boolean isResolved(BibEntry entry) { || BibEntry.KEY_FIELD.equals(field)) { return false; } else { - plainFieldContent = entry.getFieldOptional(field); + plainFieldContent = entry.getField(field); resolvedFieldContent = BibDatabase.getResolvedField(field, entry, database.orElse(null)); } diff --git a/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java b/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java index 5c3e9235895..5c3d11ca341 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java +++ b/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java @@ -270,7 +270,7 @@ public void mouseClicked(MouseEvent e) { for (String fieldName : fieldNames) { // Check if field is present, if not skip this field if (entry.hasField(fieldName)) { - String link = entry.getFieldOptional(fieldName).get(); + String link = entry.getField(fieldName).get(); // See if this is a simple file link field, or if it is a file-list // field that can specify a list of links: @@ -315,7 +315,7 @@ public void mouseClicked(MouseEvent e) { } }); } else if (modelColumn.getBibtexFields().contains(FieldName.CROSSREF)) { // Clicking on crossref column - tableRows.get(row).getFieldOptional(FieldName.CROSSREF) + tableRows.get(row).getField(FieldName.CROSSREF) .ifPresent(crossref -> panel.getDatabase().getEntryByKey(crossref).ifPresent(entry -> panel.highlightEntry(entry))); } } @@ -381,7 +381,7 @@ private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn colum if (FieldName.FILE.equals(field)) { // We use a FileListTableModel to parse the field content: FileListTableModel fileList = new FileListTableModel(); - entry.getFieldOptional(field).ifPresent(fileList::setContent); + entry.getField(field).ifPresent(fileList::setContent); for (int i = 0; i < fileList.getRowCount(); i++) { FileListEntry flEntry = fileList.getEntry(i); if (column.isFileFilter() @@ -402,7 +402,7 @@ private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn colum // full pop should be shown as left click already shows short popup showDefaultPopup = true; } else { - Optional content = entry.getFieldOptional(field); + Optional content = entry.getField(field); if (content.isPresent()) { Icon icon; JLabel iconLabel = GUIGlobals.getTableIcon(field); diff --git a/src/main/java/net/sf/jabref/gui/maintable/SpecialMainTableColumns.java b/src/main/java/net/sf/jabref/gui/maintable/SpecialMainTableColumns.java index f56921a6a29..ca05d5ecba6 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/SpecialMainTableColumns.java +++ b/src/main/java/net/sf/jabref/gui/maintable/SpecialMainTableColumns.java @@ -42,7 +42,7 @@ public String getDisplayName() { @Override public Object getColumnValue(BibEntry entry) { - return entry.getFieldOptional(SpecialFields.FIELDNAME_RANKING) + return entry.getField(SpecialFields.FIELDNAME_RANKING) .flatMap(Rank.getInstance()::parse).map(rank -> rank.createLabel()).orElse(null); } }; @@ -54,7 +54,7 @@ public Object getColumnValue(BibEntry entry) { @Override public Object getColumnValue(BibEntry entry) { - return entry.getFieldOptional(SpecialFields.FIELDNAME_PRIORITY) + return entry.getField(SpecialFields.FIELDNAME_PRIORITY) .flatMap(Priority.getInstance()::parse).map(prio -> prio.createLabel()).orElse(null); } }; @@ -66,7 +66,7 @@ public Object getColumnValue(BibEntry entry) { @Override public Object getColumnValue(BibEntry entry) { - return entry.getFieldOptional(SpecialFields.FIELDNAME_READ) + return entry.getField(SpecialFields.FIELDNAME_READ) .flatMap(ReadStatus.getInstance()::parse).map(status -> status.createLabel()).orElse(null); } }; @@ -91,7 +91,7 @@ public Object getColumnValue(BibEntry entry) { public Object getColumnValue(BibEntry entry) { // We use a FileListTableModel to parse the field content: FileListTableModel fileList = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(fileList::setContent); + entry.getField(FieldName.FILE).ifPresent(fileList::setContent); if (fileList.getRowCount() > 1) { return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); } else if (fileList.getRowCount() == 1) { @@ -170,7 +170,7 @@ public Object getColumnValue(BibEntry entry) { boolean iconFound = false; JLabel iconLabel = null; FileListTableModel fileList = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(fileList::setContent); + entry.getField(FieldName.FILE).ifPresent(fileList::setContent); for (int i = 0; i < fileList.getRowCount(); i++) { if ((fileList.getEntry(i).type.isPresent()) && externalFileTypeName.equalsIgnoreCase(fileList.getEntry(i).type.get().getName())) { diff --git a/src/main/java/net/sf/jabref/gui/menus/FileHistoryMenu.java b/src/main/java/net/sf/jabref/gui/menus/FileHistoryMenu.java index ef21c190cfa..6202e7a2f95 100644 --- a/src/main/java/net/sf/jabref/gui/menus/FileHistoryMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/FileHistoryMenu.java @@ -8,7 +8,6 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import net.sf.jabref.Globals; import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.logic.l10n.Localization; @@ -19,6 +18,7 @@ public class FileHistoryMenu extends JMenu implements ActionListener { private final FileHistory history; private final JabRefFrame frame; + private final JabRefPreferences prefs; public FileHistoryMenu(JabRefPreferences prefs, JabRefFrame frame) { @@ -33,11 +33,12 @@ public FileHistoryMenu(JabRefPreferences prefs, JabRefFrame frame) { } this.frame = frame; - history = Globals.prefs.getFileHistory(); - if (history.size() > 0) { - setItems(); - } else { + this.prefs = prefs; + history = prefs.getFileHistory(); + if (history.isEmpty()) { setEnabled(false); + } else { + setItems(); } } @@ -74,7 +75,7 @@ private void addItem(String filename, int num) { public void storeHistory() { - Globals.prefs.storeFileHistory(history); + prefs.storeFileHistory(history); } @Override diff --git a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java index 172feb080ff..14fdad1e21f 100644 --- a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java @@ -95,7 +95,7 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { add(markSpecific); add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); } else if (be != null) { - Optional marked = be.getFieldOptional(FieldName.MARKED_INTERNAL); + Optional marked = be.getField(FieldName.MARKED_INTERNAL); // We have to check for "" too as the marked field may be empty if ((!marked.isPresent()) || marked.get().isEmpty()) { add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); @@ -271,7 +271,7 @@ private Icon getFileIconForSelectedEntry() { if (panel.getMainTable().getSelectedRowCount() == 1) { BibEntry entry = panel.getMainTable().getSelected().get(0); if(entry.hasField(FieldName.FILE)) { - JLabel label = FileListTableModel.getFirstLabel(entry.getFieldOptional(FieldName.FILE).get()); + JLabel label = FileListTableModel.getFirstLabel(entry.getField(FieldName.FILE).get()); if (label != null) { return label.getIcon(); } diff --git a/src/main/java/net/sf/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/net/sf/jabref/gui/mergeentries/FetchAndMergeEntry.java index e579e80e2fc..ebaba23b473 100644 --- a/src/main/java/net/sf/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/net/sf/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -45,7 +45,7 @@ public FetchAndMergeEntry(BibEntry entry, BasePanel panel, String field) { public FetchAndMergeEntry(BibEntry entry, BasePanel panel, List fields) { for (String field : fields) { - Optional fieldContent = entry.getFieldOptional(field); + Optional fieldContent = entry.getField(field); // Get better looking name for status messages String type = FieldName.getDisplayName(field); diff --git a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java index 0c8dc2ff0fd..c4d078addcd 100644 --- a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java @@ -213,8 +213,8 @@ private int setupFieldRows(JPanel mergePanel) { for (String field : allFields) { JLabel label = boldFontLabel(new SentenceCaseFormatter().format(field)); mergePanel.add(label, CELL_CONSTRAINTS.xy(1, (2 * row) - 1, "left, top")); - Optional leftString = leftEntry.getFieldOptional(field); - Optional rightString = rightEntry.getFieldOptional(field); + Optional leftString = leftEntry.getField(field); + Optional rightString = rightEntry.getField(field); if (leftString.equals(rightString)) { identicalFields.add(field); } else { @@ -359,8 +359,8 @@ private void setupFields() { private void updateTextPanes(Collection fields) { int oldScrollPaneValue = scrollPane.getVerticalScrollBar().getValue(); for (String field : fields) { - String leftString = leftEntry.getFieldOptional(field).orElse(""); - String rightString = rightEntry.getFieldOptional(field).orElse(""); + String leftString = leftEntry.getField(field).orElse(""); + String rightString = rightEntry.getField(field).orElse(""); switch (diffMode.getSelectedIndex()) { case 0: // Plain text break; @@ -427,9 +427,9 @@ private void updateAll() { // Check the potentially different fields for (String field : differentFields) { if (radioButtons.get(field).get(0).isSelected()) { - mergedEntry.setField(field, leftEntry.getFieldOptional(field).get()); // Will only happen if field exists + mergedEntry.setField(field, leftEntry.getField(field).get()); // Will only happen if field exists } else if (radioButtons.get(field).get(2).isSelected()) { - mergedEntry.setField(field, rightEntry.getFieldOptional(field).get()); // Will only happen if field exists + mergedEntry.setField(field, rightEntry.getField(field).get()); // Will only happen if field exists } else { mergedEntry.clearField(field); } diff --git a/src/main/java/net/sf/jabref/gui/mergeentries/MergeFetchedEntryDialog.java b/src/main/java/net/sf/jabref/gui/mergeentries/MergeFetchedEntryDialog.java index 24cd4f1ce1d..df5d5114c12 100644 --- a/src/main/java/net/sf/jabref/gui/mergeentries/MergeFetchedEntryDialog.java +++ b/src/main/java/net/sf/jabref/gui/mergeentries/MergeFetchedEntryDialog.java @@ -123,8 +123,8 @@ private void buttonPressed(String button) { // fields for (String field : jointFields) { - Optional originalString = originalEntry.getFieldOptional(field); - Optional mergedString = mergedEntry.getFieldOptional(field); + Optional originalString = originalEntry.getField(field); + Optional mergedString = mergedEntry.getField(field); if (!originalString.isPresent() || !originalString.equals(mergedString)) { originalEntry.setField(field, mergedString.get()); // mergedString always present ce.addEdit(new UndoableFieldChange(originalEntry, field, originalString.orElse(null), @@ -136,7 +136,7 @@ private void buttonPressed(String button) { // Remove fields which are not in the merged entry, unless they are internal fields for (String field : originalFields) { if (!jointFields.contains(field) && !InternalBibtexFields.isInternalField(field)) { - Optional originalString = originalEntry.getFieldOptional(field); + Optional originalString = originalEntry.getField(field); originalEntry.clearField(field); ce.addEdit(new UndoableFieldChange(originalEntry, field, originalString.get(), null)); // originalString always present edited = true; diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java b/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java index f55260189e7..15673681aea 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java @@ -469,7 +469,7 @@ private List refreshCiteMarkersInternal(List databases, OOB // Rebuild the list of cited keys according to the sort order: cited.clear(); for (BibEntry entry : entries.keySet()) { - cited.add(entry.getCiteKey()); + cited.add(entry.getCiteKeyOptional().orElse(null)); } names = Arrays.asList(xReferenceMarks.getElementNames()); } else { @@ -1368,7 +1368,7 @@ public BibDatabase generateDatabase(List databases) // Insert a copy of the entry resultDatabase.insertEntry(clonedEntry); // Check if the cloned entry has a crossref field - clonedEntry.getFieldOptional(FieldName.CROSSREF).ifPresent(crossref -> { + clonedEntry.getField(FieldName.CROSSREF).ifPresent(crossref -> { // If the crossref entry is not already in the database if (!resultDatabase.getEntryByKey(crossref).isPresent()) { // Add it if it is in the current database diff --git a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java index e63d4f4e571..5bd5b702abe 100644 --- a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java @@ -421,7 +421,7 @@ private void insertTextForTag(boolean overrideField) { markedTextStore.appendPosition(fieldName, selectionStart, selectionEnd); // get old text from BibTeX tag - Optional old = entry.getFieldOptional(fieldName); + Optional old = entry.getField(fieldName); // merge old and selected text if (old.isPresent()) { diff --git a/src/main/java/net/sf/jabref/gui/preftabs/FileTab.java b/src/main/java/net/sf/jabref/gui/preftabs/FileTab.java index 09aaf5fd4ca..6f761101d3a 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/FileTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/FileTab.java @@ -265,10 +265,8 @@ public void storeSettings() { prefs.putInt(JabRefPreferences.AUTO_SAVE_INTERVAL, (Integer) autoSaveInterval.getValue()); doNotResolveStringsFor.setText(prefs.get(JabRefPreferences.DO_NOT_RESOLVE_STRINGS_FOR)); - boolean updateSpecialFields = false; if (!nonWrappableFields.getText().trim().equals(prefs.get(JabRefPreferences.NON_WRAPPABLE_FIELDS))) { prefs.put(JabRefPreferences.NON_WRAPPABLE_FIELDS, nonWrappableFields.getText()); - updateSpecialFields = true; } // See if we should start or stop the auto save manager: diff --git a/src/main/java/net/sf/jabref/gui/search/SearchResultsDialog.java b/src/main/java/net/sf/jabref/gui/search/SearchResultsDialog.java index e0bae6ed4c1..e99c92d6eed 100644 --- a/src/main/java/net/sf/jabref/gui/search/SearchResultsDialog.java +++ b/src/main/java/net/sf/jabref/gui/search/SearchResultsDialog.java @@ -337,7 +337,7 @@ public void mouseClicked(MouseEvent e) { case FILE_COL: if (entry.hasField(FieldName.FILE)) { FileListTableModel tableModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tableModel::setContent); + entry.getField(FieldName.FILE).ifPresent(tableModel::setContent); if (tableModel.getRowCount() == 0) { return; } @@ -347,7 +347,7 @@ public void mouseClicked(MouseEvent e) { } break; case URL_COL: - entry.getFieldOptional(FieldName.URL).ifPresent(link -> { try { + entry.getField(FieldName.URL).ifPresent(link -> { try { JabRefDesktop.openExternalViewer(p.getBibDatabaseContext(), link, FieldName.URL); } catch (IOException ex) { LOGGER.warn("Could not open viewer", ex); @@ -377,7 +377,7 @@ public void processPopupTrigger(MouseEvent e) { if (col == FILE_COL) { // We use a FileListTableModel to parse the field content: FileListTableModel fileList = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(fileList::setContent); + entry.getField(FieldName.FILE).ifPresent(fileList::setContent); // If there are one or more links, open the first one: for (int i = 0; i < fileList.getRowCount(); i++) { FileListEntry flEntry = fileList.getEntry(i); @@ -447,7 +447,7 @@ public Object getColumnValue(BibEntry entry, int column) { case FILE_COL: if (entry.hasField(FieldName.FILE)) { FileListTableModel tmpModel = new FileListTableModel(); - entry.getFieldOptional(FieldName.FILE).ifPresent(tmpModel::setContent); + entry.getField(FieldName.FILE).ifPresent(tmpModel::setContent); fileLabel.setToolTipText(tmpModel.getToolTipHTMLRepresentation()); if (tmpModel.getRowCount() > 0) { if (tmpModel.getEntry(0).type.isPresent()) { @@ -462,7 +462,7 @@ public Object getColumnValue(BibEntry entry, int column) { } case URL_COL: if (entry.hasField(FieldName.URL)) { - urlLabel.setToolTipText(entry.getFieldOptional(FieldName.URL).get()); + urlLabel.setToolTipText(entry.getField(FieldName.URL).get()); return urlLabel; } else { return null; @@ -477,10 +477,10 @@ public Object getColumnValue(BibEntry entry, int column) { // For name fields, tap into a MainTableFormat instance and use // the same name formatting as is used in the entry table: if (frame.getCurrentBasePanel() != null) { - return MainTableNameFormatter.formatName(entry.getFieldOptional(field).orElse(null)); + return MainTableNameFormatter.formatName(entry.getField(field).orElse(null)); } } - return entry.getFieldOptional(field).orElse(null); + return entry.getField(field).orElse(null); } } diff --git a/src/main/java/net/sf/jabref/gui/util/comparator/IconComparator.java b/src/main/java/net/sf/jabref/gui/util/comparator/IconComparator.java index 06dd099a39c..dee5930270a 100644 --- a/src/main/java/net/sf/jabref/gui/util/comparator/IconComparator.java +++ b/src/main/java/net/sf/jabref/gui/util/comparator/IconComparator.java @@ -22,8 +22,8 @@ public IconComparator(List fields) { public int compare(BibEntry e1, BibEntry e2) { for (String field : fields) { - Optional val1 = e1.getFieldOptional(field); - Optional val2 = e2.getFieldOptional(field); + Optional val1 = e1.getField(field); + Optional val2 = e2.getField(field); if (val1.isPresent()) { if (val2.isPresent()) { // val1 is not null AND val2 is not null diff --git a/src/main/java/net/sf/jabref/gui/util/comparator/RankingFieldComparator.java b/src/main/java/net/sf/jabref/gui/util/comparator/RankingFieldComparator.java index b006d5c7b96..b11e4f7fdc9 100644 --- a/src/main/java/net/sf/jabref/gui/util/comparator/RankingFieldComparator.java +++ b/src/main/java/net/sf/jabref/gui/util/comparator/RankingFieldComparator.java @@ -17,8 +17,8 @@ public class RankingFieldComparator implements Comparator { @Override public int compare(BibEntry e1, BibEntry e2) { - Optional val1 = e1.getFieldOptional(SpecialFields.FIELDNAME_RANKING); - Optional val2 = e2.getFieldOptional(SpecialFields.FIELDNAME_RANKING); + Optional val1 = e1.getField(SpecialFields.FIELDNAME_RANKING); + Optional val2 = e2.getField(SpecialFields.FIELDNAME_RANKING); if (val1.isPresent()) { if (val2.isPresent()) { // val1 is not null AND val2 is not null diff --git a/src/main/java/net/sf/jabref/logic/TypedBibEntry.java b/src/main/java/net/sf/jabref/logic/TypedBibEntry.java index c0cc3fa039a..adf5bf3b863 100644 --- a/src/main/java/net/sf/jabref/logic/TypedBibEntry.java +++ b/src/main/java/net/sf/jabref/logic/TypedBibEntry.java @@ -69,7 +69,7 @@ public String getTypeForDisplay() { */ public List getFiles() { //Extract the path - Optional oldValue = entry.getFieldOptional(FieldName.FILE); + Optional oldValue = entry.getField(FieldName.FILE); if (!oldValue.isPresent()) { return new ArrayList<>(); } @@ -79,7 +79,7 @@ public List getFiles() { public Optional setFiles(List files) { - Optional oldValue = entry.getFieldOptional(FieldName.FILE); + Optional oldValue = entry.getField(FieldName.FILE); String newValue = FileField.getStringRepresentation(files); if(oldValue.isPresent() && oldValue.get().equals(newValue)) { diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/DefaultAutoCompleter.java b/src/main/java/net/sf/jabref/logic/autocompleter/DefaultAutoCompleter.java index b8a950e058a..e0a577c3d3f 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/DefaultAutoCompleter.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/DefaultAutoCompleter.java @@ -41,7 +41,7 @@ public void addBibtexEntry(BibEntry entry) { return; } - entry.getFieldOptional(fieldName).ifPresent(fieldValue -> { + entry.getField(fieldName).ifPresent(fieldValue -> { StringTokenizer tok = new StringTokenizer(fieldValue, SEPARATING_CHARS); while (tok.hasMoreTokens()) { addItemToIndex(tok.nextToken()); diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/EntireFieldAutoCompleter.java b/src/main/java/net/sf/jabref/logic/autocompleter/EntireFieldAutoCompleter.java index 3a71c0d50f2..602dd6d77f9 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/EntireFieldAutoCompleter.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/EntireFieldAutoCompleter.java @@ -38,6 +38,6 @@ public void addBibtexEntry(BibEntry entry) { return; } - entry.getFieldOptional(fieldName).ifPresent(fieldValue -> addItemToIndex(fieldValue.trim())); + entry.getField(fieldName).ifPresent(fieldValue -> addItemToIndex(fieldValue.trim())); } } diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/NameFieldAutoCompleter.java b/src/main/java/net/sf/jabref/logic/autocompleter/NameFieldAutoCompleter.java index d80ee7a59df..e9fe1a25163 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/NameFieldAutoCompleter.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/NameFieldAutoCompleter.java @@ -76,7 +76,7 @@ public void addBibtexEntry(BibEntry entry) { return; } for (String fieldName : fieldNames) { - entry.getFieldOptional(fieldName).ifPresent(fieldValue -> { + entry.getField(fieldName).ifPresent(fieldValue -> { AuthorList authorList = AuthorList.parse(fieldValue); for (Author author : authorList.getAuthors()) { handleAuthor(author); diff --git a/src/main/java/net/sf/jabref/logic/auxparser/AuxParser.java b/src/main/java/net/sf/jabref/logic/auxparser/AuxParser.java index 7844b4d9875..1c53412fb54 100644 --- a/src/main/java/net/sf/jabref/logic/auxparser/AuxParser.java +++ b/src/main/java/net/sf/jabref/logic/auxparser/AuxParser.java @@ -149,7 +149,7 @@ private void resolveTags(AuxParserResult result) { * Resolves and adds CrossRef entries */ private void resolveCrossReferences(BibEntry entry, AuxParserResult result) { - entry.getFieldOptional(FieldName.CROSSREF).ifPresent(crossref -> { + entry.getField(FieldName.CROSSREF).ifPresent(crossref -> { if (!result.getUniqueKeys().contains(crossref)) { Optional refEntry = masterDatabase.getEntryByKey(crossref); diff --git a/src/main/java/net/sf/jabref/logic/bibtex/BibEntryWriter.java b/src/main/java/net/sf/jabref/logic/bibtex/BibEntryWriter.java index 79054805619..0421cc33bd0 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/BibEntryWriter.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/BibEntryWriter.java @@ -143,7 +143,7 @@ private void writeKeyField(BibEntry entry, Writer out) throws IOException { * @throws IOException In case of an IO error */ private void writeField(BibEntry entry, Writer out, String name, int indentation) throws IOException { - Optional field = entry.getFieldOptional(name); + Optional field = entry.getField(name); // only write field if is is not empty // field.ifPresent does not work as an IOException may be thrown if (field.isPresent() && !field.get().trim().isEmpty()) { diff --git a/src/main/java/net/sf/jabref/logic/bibtex/comparator/EntryComparator.java b/src/main/java/net/sf/jabref/logic/bibtex/comparator/EntryComparator.java index e8f85ad178d..65b31ba7d14 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/comparator/EntryComparator.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/comparator/EntryComparator.java @@ -48,8 +48,8 @@ public int compare(BibEntry e1, BibEntry e2) { return 0; } - Object f1 = e1.getField(sortField); - Object f2 = e2.getField(sortField); + Object f1 = e1.getField(sortField).orElse(null); + Object f2 = e2.getField(sortField).orElse(null); if (binary) { // We just separate on set and unset fields: diff --git a/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java index 39a34e1d454..15d3a1a7032 100644 --- a/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java +++ b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java @@ -551,7 +551,7 @@ public static String makeLabel(BibEntry entry, String value) { * form "pureauth..." which does not do this fallback * substitution of editor. */ - String authString = entry.getFieldOptional(FieldName.AUTHOR) + String authString = entry.getField(FieldName.AUTHOR) .map(authorString -> normalize(database.resolveForStrings(authorString))).orElse(""); if (val.startsWith("pure")) { @@ -561,7 +561,7 @@ public static String makeLabel(BibEntry entry, String value) { } if (authString.isEmpty()) { - authString = entry.getFieldOptional(FieldName.EDITOR) + authString = entry.getField(FieldName.EDITOR) .map(authorString -> normalize(database.resolveForStrings(authorString))).orElse(""); } @@ -631,39 +631,39 @@ else if ("authorLast".equals(val)) { // Gather all markers starting with "ed" here, so we // don't have to check all the time. if ("edtr".equals(val)) { - return firstAuthor(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + return firstAuthor(entry.getField(FieldName.EDITOR).orElse("")); } else if ("edtrForeIni".equals(val)) { - return firstAuthorForenameInitials(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + return firstAuthorForenameInitials(entry.getField(FieldName.EDITOR).orElse("")); } else if ("editors".equals(val)) { - return allAuthors(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + return allAuthors(entry.getField(FieldName.EDITOR).orElse("")); // Last author's last name } else if ("editorLast".equals(val)) { - return lastAuthor(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + return lastAuthor(entry.getField(FieldName.EDITOR).orElse("")); } else if ("editorLastForeIni".equals(val)) { - return lastAuthorForenameInitials(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + return lastAuthorForenameInitials(entry.getField(FieldName.EDITOR).orElse("")); } else if ("editorIni".equals(val)) { - return oneAuthorPlusIni(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + return oneAuthorPlusIni(entry.getField(FieldName.EDITOR).orElse("")); } else if (val.matches("edtrIni[\\d]+")) { int num = Integer.parseInt(val.substring(7)); - String s = authIniN(entry.getFieldOptional(FieldName.EDITOR).orElse(""), num); + String s = authIniN(entry.getField(FieldName.EDITOR).orElse(""), num); return s == null ? "" : s; } else if (val.matches("edtr[\\d]+_[\\d]+")) { String[] nums = val.substring(4).split("_"); - String s = authNofMth(entry.getFieldOptional(FieldName.EDITOR).orElse(""), + String s = authNofMth(entry.getField(FieldName.EDITOR).orElse(""), Integer.parseInt(nums[0]), Integer.parseInt(nums[1]) - 1); return s == null ? "" : s; } else if ("edtr.edtr.ea".equals(val)) { - String s = authAuthEa(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + String s = authAuthEa(entry.getField(FieldName.EDITOR).orElse("")); return s == null ? "" : s; } else if ("edtrshort".equals(val)) { - String s = authshort(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + String s = authshort(entry.getField(FieldName.EDITOR).orElse("")); return s == null ? "" : s; } // authN. First N chars of the first author's last // name. else if (val.matches("edtr\\d+")) { - String fa = firstAuthor(entry.getFieldOptional(FieldName.EDITOR).orElse("")); + String fa = firstAuthor(entry.getField(FieldName.EDITOR).orElse("")); if (fa == null) { return ""; } @@ -678,17 +678,17 @@ else if (val.matches("edtr\\d+")) { return getField(entry, val); } } else if ("firstpage".equals(val)) { - return firstPage(entry.getFieldOptional(FieldName.PAGES).orElse("")); + return firstPage(entry.getField(FieldName.PAGES).orElse("")); } else if ("lastpage".equals(val)) { - return lastPage(entry.getFieldOptional(FieldName.PAGES).orElse("")); + return lastPage(entry.getField(FieldName.PAGES).orElse("")); } else if ("shorttitle".equals(val)) { - return getTitleWords(3, entry.getFieldOptional(FieldName.TITLE).orElse("")); + return getTitleWords(3, entry.getField(FieldName.TITLE).orElse("")); } else if ("shorttitleINI".equals(val)) { return keepLettersAndDigitsOnly( - applyModifiers(getTitleWordsWithSpaces(3, entry.getFieldOptional(FieldName.TITLE).orElse("")), + applyModifiers(getTitleWordsWithSpaces(3, entry.getField(FieldName.TITLE).orElse("")), new String[] {"abbr"}, 0)); } else if ("veryshorttitle".equals(val)) { - return getTitleWords(1, entry.getFieldOptional(FieldName.TITLE).orElse("")); + return getTitleWords(1, entry.getField(FieldName.TITLE).orElse("")); } else if ("shortyear".equals(val)) { String ss = entry.getFieldOrAlias(FieldName.YEAR).orElse(""); if (ss.isEmpty()) { diff --git a/src/main/java/net/sf/jabref/logic/bst/VM.java b/src/main/java/net/sf/jabref/logic/bst/VM.java index c5b9b5bf0a9..0d31021dd46 100644 --- a/src/main/java/net/sf/jabref/logic/bst/VM.java +++ b/src/main/java/net/sf/jabref/logic/bst/VM.java @@ -298,7 +298,7 @@ private VM(CommonTree tree) { if (context == null) { throw new VMException("Must have an entry to cite$"); } - stack.push(context.getBibtexEntry().getCiteKey()); + stack.push(context.getBibtexEntry().getCiteKeyOptional().orElse(null)); }); /** @@ -915,7 +915,7 @@ private void read() { for (BstEntry e : entries) { for (Map.Entry mEntry : e.getFields().entrySet()) { - String fieldValue = e.getBibtexEntry().getField(mEntry.getKey()); + String fieldValue = e.getBibtexEntry().getField(mEntry.getKey()).orElse(null); mEntry.setValue(fieldValue); } diff --git a/src/main/java/net/sf/jabref/logic/cleanup/BiblatexCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/BiblatexCleanup.java index 4b7e05eeb02..19d0bd9e06d 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/BiblatexCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/BiblatexCleanup.java @@ -21,8 +21,8 @@ public List cleanup(BibEntry entry) { for (Map.Entry alias : EntryConverter.FIELD_ALIASES_TEX_TO_LTX.entrySet()) { String oldFieldName = alias.getKey(); String newFieldName = alias.getValue(); - entry.getFieldOptional(oldFieldName).ifPresent(oldValue -> { - if (!oldValue.isEmpty() && (!entry.getFieldOptional(newFieldName).isPresent())) { + entry.getField(oldFieldName).ifPresent(oldValue -> { + if (!oldValue.isEmpty() && (!entry.getField(newFieldName).isPresent())) { // There is content in the old field and no value in the new, so just copy entry.setField(newFieldName, oldValue); changes.add(new FieldChange(entry, newFieldName, null, oldValue)); @@ -34,11 +34,11 @@ public List cleanup(BibEntry entry) { } // Dates: create date out of year and month, save it and delete old fields - entry.getFieldOptional(FieldName.DATE).ifPresent(date -> { + entry.getField(FieldName.DATE).ifPresent(date -> { if (date.isEmpty()) { entry.getFieldOrAlias(FieldName.DATE).ifPresent(newDate -> { - Optional oldYear = entry.getFieldOptional(FieldName.YEAR); - Optional oldMonth = entry.getFieldOptional(FieldName.MONTH); + Optional oldYear = entry.getField(FieldName.YEAR); + Optional oldMonth = entry.getField(FieldName.MONTH); entry.setField(FieldName.DATE, newDate); entry.clearField(FieldName.YEAR); diff --git a/src/main/java/net/sf/jabref/logic/cleanup/DoiCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/DoiCleanup.java index 85fbdb16cfb..6833cb1f78e 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/DoiCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/DoiCleanup.java @@ -28,7 +28,7 @@ public List cleanup(BibEntry entry) { // First check if the Doi Field is empty if (entry.hasField(FieldName.DOI)) { - String doiFieldValue = entry.getFieldOptional(FieldName.DOI).orElse(null); + String doiFieldValue = entry.getField(FieldName.DOI).orElse(null); Optional doi = DOI.build(doiFieldValue); @@ -43,18 +43,18 @@ public List cleanup(BibEntry entry) { // Doi field seems to contain Doi -> cleanup note, url, ee field for (String field : FIELDS) { - entry.getFieldOptional(field).flatMap(DOI::build) + entry.getField(field).flatMap(DOI::build) .ifPresent(unused -> removeFieldValue(entry, field, changes)); } } } else { // As the Doi field is empty we now check if note, url, or ee field contains a Doi for (String field : FIELDS) { - Optional doi = entry.getFieldOptional(field).flatMap(DOI::build); + Optional doi = entry.getField(field).flatMap(DOI::build); if (doi.isPresent()) { // update Doi - String oldValue = entry.getFieldOptional(FieldName.DOI).orElse(null); + String oldValue = entry.getField(FieldName.DOI).orElse(null); String newValue = doi.get().getDOI(); entry.setField(FieldName.DOI, newValue); diff --git a/src/main/java/net/sf/jabref/logic/cleanup/FieldFormatterCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/FieldFormatterCleanup.java index 9c8fd8123ae..5b008cff33d 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/FieldFormatterCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/FieldFormatterCleanup.java @@ -45,7 +45,7 @@ private List cleanupSingleField(String fieldKey, BibEntry entry) { // Not set -> nothing to do return new ArrayList<>(); } - String oldValue = entry.getFieldOptional(fieldKey).orElse(null); + String oldValue = entry.getField(fieldKey).orElse(null); // Run formatter String newValue = formatter.format(oldValue); diff --git a/src/main/java/net/sf/jabref/logic/cleanup/FileLinksCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/FileLinksCleanup.java index 76dd8dd9945..d0497fb04b3 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/FileLinksCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/FileLinksCleanup.java @@ -17,7 +17,7 @@ public class FileLinksCleanup implements CleanupJob { @Override public List cleanup(BibEntry entry) { - Optional oldValue = entry.getFieldOptional(FieldName.FILE); + Optional oldValue = entry.getField(FieldName.FILE); if (!oldValue.isPresent()) { return Collections.emptyList(); } diff --git a/src/main/java/net/sf/jabref/logic/cleanup/ISSNCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/ISSNCleanup.java index 11edf0874c8..4e89702e475 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/ISSNCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/ISSNCleanup.java @@ -14,7 +14,7 @@ public class ISSNCleanup implements CleanupJob { @Override public List cleanup(BibEntry entry) { - Optional issnString = entry.getFieldOptional(FieldName.ISSN); + Optional issnString = entry.getField(FieldName.ISSN); if (!issnString.isPresent()) { return Collections.emptyList(); } diff --git a/src/main/java/net/sf/jabref/logic/cleanup/UpgradePdfPsToFileCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/UpgradePdfPsToFileCleanup.java index d9a20a736b2..ab44125022e 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/UpgradePdfPsToFileCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/UpgradePdfPsToFileCleanup.java @@ -28,12 +28,12 @@ public List cleanup(BibEntry entry) { List changes = new ArrayList<>(); // If there are already links in the file field, keep those on top: - String oldFileContent = entry.getFieldOptional(FieldName.FILE).orElse(null); + String oldFileContent = entry.getField(FieldName.FILE).orElse(null); List fileList = new ArrayList<>(FileField.parse(oldFileContent)); int oldItemCount = fileList.size(); for (String field : fields) { - entry.getFieldOptional(field).ifPresent(o -> { + entry.getField(field).ifPresent(o -> { if (o.trim().isEmpty()) { return; } diff --git a/src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java b/src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java index ec613c61914..4e9a3bf6879 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java +++ b/src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java @@ -193,7 +193,7 @@ public Document getDOMrepresentation() { } private static String getField(BibEntry e, String field) { - return e.getFieldOptional(field).orElse(""); + return e.getField(field).orElse(""); } private static void addTableCell(Document doc, Element parent, String content) { diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupsUtil.java b/src/main/java/net/sf/jabref/logic/groups/GroupsUtil.java index 5c3d74f6cae..97ab2dc48a6 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupsUtil.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupsUtil.java @@ -19,7 +19,7 @@ public static Set findDeliminatedWordsInField(BibDatabase db, String fie Set res = new TreeSet<>(); for (BibEntry be : db.getEntries()) { - be.getFieldOptional(field).ifPresent(fieldValue -> { + be.getField(field).ifPresent(fieldValue -> { StringTokenizer tok = new StringTokenizer(fieldValue.trim(), deliminator); while (tok.hasMoreTokens()) { res.add(EntryUtil.capitalizeFirst(tok.nextToken().trim())); @@ -41,7 +41,7 @@ public static Set findDeliminatedWordsInField(BibDatabase db, String fie public static Set findAllWordsInField(BibDatabase db, String field, String remove) { Set res = new TreeSet<>(); for (BibEntry be : db.getEntries()) { - be.getFieldOptional(field).ifPresent(o -> { + be.getField(field).ifPresent(o -> { StringTokenizer tok = new StringTokenizer(o, remove, false); while (tok.hasMoreTokens()) { res.add(EntryUtil.capitalizeFirst(tok.nextToken().trim())); @@ -62,7 +62,7 @@ public static Set findAuthorLastNames(BibDatabase db, List field Set res = new TreeSet<>(); for (BibEntry be : db.getEntries()) { for (String field : fields) { - be.getFieldOptional(field).ifPresent(val -> { + be.getField(field).ifPresent(val -> { if (!val.isEmpty()) { AuthorList al = AuthorList.parse(val); res.addAll(al.getAuthors().stream().map(Author::getLast).filter(Optional::isPresent) diff --git a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java index d51189b6b01..d68c58b0920 100644 --- a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java @@ -123,7 +123,7 @@ public Optional add(List entriesToAdd) { boolean modified = false; for (BibEntry entry : entriesToAdd) { if (!contains(entry)) { - String oldContent = entry.getFieldOptional(searchField).orElse(null); + String oldContent = entry.getField(searchField).orElse(null); String newContent = (oldContent == null ? "" : oldContent + keywordSeparator) + searchExpression; @@ -152,12 +152,12 @@ public Optional remove(List entriesToRemove) { boolean modified = false; for (BibEntry entry : entriesToRemove) { if (contains(entry)) { - String oldContent = entry.getFieldOptional(searchField).orElse(null); + String oldContent = entry.getField(searchField).orElse(null); removeMatches(entry); // Store change information. changes.add(new FieldChange(entry, searchField, oldContent, - entry.getFieldOptional(searchField).orElse(null))); + entry.getField(searchField).orElse(null))); modified = true; } } @@ -188,7 +188,7 @@ public boolean equals(Object o) { @Override public boolean contains(BibEntry entry) { if (regExp) { - Optional content = entry.getFieldOptional(searchField); + Optional content = entry.getField(searchField); return content.map(value -> pattern.matcher(value).find()).orElse(false); } @@ -253,7 +253,7 @@ public static boolean containsWord(String word, String text) { * possible if the search expression is not a regExp. */ private void removeMatches(BibEntry entry) { - entry.getFieldOptional(searchField).ifPresent(content -> { + entry.getField(searchField).ifPresent(content -> { StringBuffer sbOrig = new StringBuffer(content); StringBuffer sbLower = new StringBuffer(content.toLowerCase()); StringBuffer haystack = caseSensitive ? sbOrig : sbLower; diff --git a/src/main/java/net/sf/jabref/logic/importer/FulltextFetchers.java b/src/main/java/net/sf/jabref/logic/importer/FulltextFetchers.java index f3a5e9e5ce9..375ea165972 100644 --- a/src/main/java/net/sf/jabref/logic/importer/FulltextFetchers.java +++ b/src/main/java/net/sf/jabref/logic/importer/FulltextFetchers.java @@ -49,7 +49,7 @@ public FulltextFetchers(List fetcher) { public Optional findFullTextPDF(BibEntry entry) { // for accuracy, fetch DOI first but do not modify entry BibEntry clonedEntry = (BibEntry) entry.clone(); - Optional doi = clonedEntry.getFieldOptional(FieldName.DOI); + Optional doi = clonedEntry.getField(FieldName.DOI); if (!doi.isPresent() || !DOI.build(doi.get()).isPresent()) { CrossRef.findDOI(clonedEntry).ifPresent(e -> clonedEntry.setField(FieldName.DOI, e.getDOI())); diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/ACS.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/ACS.java index 9c6db43bda8..aabba6fc6c5 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/ACS.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/ACS.java @@ -40,7 +40,7 @@ public Optional findFullText(BibEntry entry) throws IOException { Optional pdfLink = Optional.empty(); // DOI search - Optional doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional doi = entry.getField(FieldName.DOI).flatMap(DOI::build); if(doi.isPresent()) { String source = String.format(SOURCE, doi.get().getDOI()); diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/ArXiv.java index db9ede756b0..6062391af00 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/ArXiv.java @@ -62,7 +62,7 @@ public Optional findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); // 1. Eprint - Optional identifier = entry.getFieldOptional(FieldName.EPRINT); + Optional identifier = entry.getField(FieldName.EPRINT); if (StringUtil.isNotBlank(identifier)) { try { // Get pdf of entry with the specified id @@ -77,7 +77,7 @@ public Optional findFullText(BibEntry entry) throws IOException { } // 2. DOI - Optional doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional doi = entry.getField(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { String doiString = doi.get().getDOI(); // Search for an entry in the ArXiv which is linked to the doi diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java index 948f3987f2b..29c7142894a 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/CrossRef.java @@ -38,7 +38,7 @@ public static Optional findDOI(BibEntry entry) { Optional doi = Optional.empty(); // title is minimum requirement - Optional title = entry.getFieldOptional(FieldName.TITLE); + Optional title = entry.getField(FieldName.TITLE); if (!title.isPresent() || title.get().isEmpty()) { return doi; @@ -68,14 +68,14 @@ public static Optional findDOI(BibEntry entry) { private static String enhanceQuery(String query, BibEntry entry) { StringBuilder enhancedQuery = new StringBuilder(query); // author - entry.getFieldOptional(FieldName.AUTHOR).ifPresent(author -> { + entry.getField(FieldName.AUTHOR).ifPresent(author -> { if (!author.isEmpty()) { enhancedQuery.append('+').append(author); } }); // year - entry.getFieldOptional(FieldName.YEAR).ifPresent(year -> { + entry.getField(FieldName.YEAR).ifPresent(year -> { if (!year.isEmpty()) { enhancedQuery.append('+').append(year); } @@ -86,7 +86,7 @@ private static String enhanceQuery(String query, BibEntry entry) { private static boolean checkValidity(BibEntry entry, JSONArray result) { // TODO: use latex-free version instead in the future - final String entryTitle = entry.getFieldOptional(FieldName.TITLE).map(CrossRef::removeLaTeX).orElse(""); + final String entryTitle = entry.getField(FieldName.TITLE).map(CrossRef::removeLaTeX).orElse(""); // currently only title-based // title: [ "How the Mind Hurts and Heals the Body." ] diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/DOItoBibTeX.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/DOItoBibTeX.java index 1765a8f38dc..2cfd61da111 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/DOItoBibTeX.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/DOItoBibTeX.java @@ -76,7 +76,7 @@ public static Optional getEntryFromDOI(String doiStr, ParserResult par private static void formatTitleField(BibEntry entry, ImportFormatPreferences importFormatPreferences) { // Optionally add curly brackets around key words to keep the case - entry.getFieldOptional(FieldName.TITLE).ifPresent(title -> { + entry.getField(FieldName.TITLE).ifPresent(title -> { // Unit formatting if (importFormatPreferences.isConvertUnitsOnSearch()) { title = unitsToLatexFormatter.format(title); diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiResolution.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiResolution.java index 9e1e0bc1f57..7b1599ff091 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiResolution.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiResolution.java @@ -33,7 +33,7 @@ public Optional findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional pdfLink = Optional.empty(); - Optional doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional doi = entry.getField(FieldName.DOI).flatMap(DOI::build); if(doi.isPresent()) { String sciLink = doi.get().getURIAsASCIIString(); diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/GoogleScholar.java index 46a79137d59..61b7b5192e7 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/GoogleScholar.java @@ -37,7 +37,7 @@ public Optional findFullText(BibEntry entry) throws IOException { } String url = String.format(SEARCH_URL, - URLEncoder.encode(entry.getFieldOptional(FieldName.TITLE).orElse(null), StandardCharsets.UTF_8.name())); + URLEncoder.encode(entry.getField(FieldName.TITLE).orElse(null), StandardCharsets.UTF_8.name())); Document doc = Jsoup.connect(url) .userAgent("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") // don't identify as a crawler diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/IEEE.java index 064d7d1a7ae..a309648fb37 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/IEEE.java @@ -38,7 +38,7 @@ public Optional findFullText(BibEntry entry) throws IOException { String stampString = ""; // Try URL first -- will primarily work for entries from the old IEEE search - Optional urlString = entry.getFieldOptional(FieldName.URL); + Optional urlString = entry.getField(FieldName.URL); if (urlString.isPresent()) { // Is the URL a direct link to IEEE? Matcher matcher = STAMP_PATTERN.matcher(urlString.get()); @@ -50,7 +50,7 @@ public Optional findFullText(BibEntry entry) throws IOException { // If not, try DOI if (stampString.isEmpty()) { - Optional doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional doi = entry.getField(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent() && doi.get().getDOI().startsWith(IEEE_DOI) && doi.get().getURI().isPresent()) { // Download the HTML page from IEEE String resolvedDOIPage = new URLDownload(doi.get().getURI().get().toURL()) diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/ScienceDirect.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/ScienceDirect.java index eac25e0d1f4..4998483f288 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/ScienceDirect.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/ScienceDirect.java @@ -39,7 +39,7 @@ public Optional findFullText(BibEntry entry) throws IOException { Optional pdfLink = Optional.empty(); // Try unique DOI first - Optional doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional doi = entry.getField(FieldName.DOI).flatMap(DOI::build); if(doi.isPresent()) { // Available in catalog? diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/SpringerLink.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/SpringerLink.java index d4ef30b1630..70724ea462b 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/SpringerLink.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/SpringerLink.java @@ -36,7 +36,7 @@ public Optional findFullText(BibEntry entry) throws IOException { Optional pdfLink = Optional.empty(); // Try unique DOI first - Optional doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); + Optional doi = entry.getField(FieldName.DOI).flatMap(DOI::build); if(doi.isPresent()) { // Available in catalog? diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java index 0f8d3c05731..fd9df902038 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexParser.java @@ -542,7 +542,7 @@ private void parseField(BibEntry entry) throws IOException { // it inconvenient // for users if JabRef did not accept it. if (InternalBibtexFields.getFieldProperties(key).contains(FieldProperty.PERSON_NAMES)) { - entry.setField(key, entry.getFieldOptional(key).get() + " and " + content); + entry.setField(key, entry.getField(key).get() + " and " + content); } else if (FieldName.KEYWORDS.equals(key)) { //multiple keywords fields should be combined to one entry.addKeyword(content, importFormatPreferences.getKeywordSeparator()); diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java index 62d72cb2eb5..d3d774a4c6c 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java @@ -140,7 +140,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { private static void setOrAppend(BibEntry b, String field, String value, String separator) { if (b.hasField(field)) { - b.setField(field, b.getFieldOptional(field).get() + separator + value); + b.setField(field, b.getField(field).get() + separator + value); } else { b.setField(field, value); } diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java index b40e5237872..c697cb2668a 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java @@ -189,7 +189,7 @@ public ParserResult importEntries(String text) { String note; if (e.hasField(FieldName.NOTE)) { // "note" could have been set during the parsing as FreeCite also returns "note" - note = e.getFieldOptional(FieldName.NOTE).get().concat(OS.NEWLINE) + note = e.getField(FieldName.NOTE).get().concat(OS.NEWLINE) .concat(noteSB.toString()); } else { note = noteSB.toString(); diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java index f4ca7d0b084..7592d2892f1 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java @@ -1,6 +1,7 @@ package net.sf.jabref.logic.importer.fileformat; import java.io.BufferedReader; +import java.io.FileInputStream; import java.io.IOException; import java.io.StringWriter; import java.nio.charset.Charset; @@ -199,7 +200,8 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { @Override public ParserResult importDatabase(Path filePath, Charset defaultEncoding) { final ArrayList result = new ArrayList<>(1); - try (PDDocument document = XMPUtil.loadWithAutomaticDecryption(filePath)) { + try (FileInputStream fileStream = new FileInputStream(filePath.toFile()); + PDDocument document = XMPUtil.loadWithAutomaticDecryption(fileStream)) { String firstPageContents = getFirstPageContents(document); Optional doi = DOI.findInText(firstPageContents); diff --git a/src/main/java/net/sf/jabref/logic/importer/util/JSONEntryParser.java b/src/main/java/net/sf/jabref/logic/importer/util/JSONEntryParser.java index 2b0375325c1..22c96395df3 100644 --- a/src/main/java/net/sf/jabref/logic/importer/util/JSONEntryParser.java +++ b/src/main/java/net/sf/jabref/logic/importer/util/JSONEntryParser.java @@ -218,7 +218,7 @@ public static BibEntry parseSpringerJSONtoBibtex(JSONObject springerJsonEntry) { } // Clean up abstract (often starting with Abstract) - entry.getFieldOptional(FieldName.ABSTRACT).ifPresent(abstractContents -> { + entry.getField(FieldName.ABSTRACT).ifPresent(abstractContents -> { if (abstractContents.startsWith("Abstract")) { entry.setField(FieldName.ABSTRACT, abstractContents.substring(8)); } diff --git a/src/main/java/net/sf/jabref/logic/importer/util/OAI2Handler.java b/src/main/java/net/sf/jabref/logic/importer/util/OAI2Handler.java index bb9ee658c8a..7ba4b205e63 100644 --- a/src/main/java/net/sf/jabref/logic/importer/util/OAI2Handler.java +++ b/src/main/java/net/sf/jabref/logic/importer/util/OAI2Handler.java @@ -78,7 +78,7 @@ public void endElement(String uri, String localName, String qualifiedName) throw pages = pages.replace(" ", ""); entry.setField(FieldName.PAGES, pages); } else if ("datestamp".equals(qualifiedName)) { - Optional year = entry.getFieldOptional(FieldName.YEAR); + Optional year = entry.getField(FieldName.YEAR); if (!year.isPresent() || year.get().isEmpty()) { entry.setField(FieldName.YEAR, content.replaceFirst("-.*", "")); } diff --git a/src/main/java/net/sf/jabref/logic/integrity/ISBNChecker.java b/src/main/java/net/sf/jabref/logic/integrity/ISBNChecker.java index 81642f3a570..d6c7bc8d5db 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/ISBNChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/ISBNChecker.java @@ -20,7 +20,7 @@ public List check(BibEntry entry) { } // Check that the ISBN is on the correct form - ISBN isbn = new ISBN(entry.getFieldOptional(FieldName.ISBN).get()); + ISBN isbn = new ISBN(entry.getField(FieldName.ISBN).get()); if (!isbn.isValidFormat()) { return Collections.singletonList( diff --git a/src/main/java/net/sf/jabref/logic/integrity/ISSNChecker.java b/src/main/java/net/sf/jabref/logic/integrity/ISSNChecker.java index 4529793cfcf..fc3503a9b56 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/ISSNChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/ISSNChecker.java @@ -21,7 +21,7 @@ public List check(BibEntry entry) { } // Check that the ISSN is on the correct form - String issnString = entry.getFieldOptional(FieldName.ISSN).get().trim(); + String issnString = entry.getField(FieldName.ISSN).get().trim(); ISSN issn = new ISSN(issnString); if (!issn.isValidFormat()) { diff --git a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java index b50a1880c90..f265f268942 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java +++ b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java @@ -95,7 +95,7 @@ private static class TypeChecker implements Checker { @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.PAGES); + Optional value = entry.getField(FieldName.PAGES); if (!value.isPresent()) { return Collections.emptyList(); } @@ -113,7 +113,7 @@ private static class BooktitleChecker implements Checker { @Override public List check(BibEntry entry) { String field = FieldName.BOOKTITLE; - Optional value = entry.getFieldOptional(field); + Optional value = entry.getField(field); if (!value.isPresent()) { return Collections.emptyList(); } @@ -136,7 +136,7 @@ private AbbreviationChecker(String field) { @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(field); + Optional value = entry.getField(field); if (!value.isPresent()) { return Collections.emptyList(); } @@ -161,7 +161,7 @@ private FileChecker(BibDatabaseContext context, FileDirectoryPreferences fileDir @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.FILE); + Optional value = entry.getField(FieldName.FILE); if (!value.isPresent()) { return Collections.emptyList(); } @@ -187,7 +187,7 @@ private static class UrlChecker implements Checker { @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.URL); + Optional value = entry.getField(FieldName.URL); if (!value.isPresent()) { return Collections.emptyList(); } @@ -207,7 +207,7 @@ public List check(BibEntry entry) { List result = new ArrayList<>(); for (String field : entry.getFieldNames()) { if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES)) { - Optional value = entry.getFieldOptional(field); + Optional value = entry.getField(field); if (!value.isPresent()) { return Collections.emptyList(); } @@ -234,7 +234,7 @@ private BracketChecker(String field) { @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(field); + Optional value = entry.getField(field); if (!value.isPresent()) { return Collections.emptyList(); } @@ -269,7 +269,7 @@ private static class TitleChecker implements Checker { @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.TITLE); + Optional value = entry.getField(FieldName.TITLE); if (!value.isPresent()) { return Collections.emptyList(); } @@ -312,7 +312,7 @@ private static class YearChecker implements Checker { */ @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.YEAR); + Optional value = entry.getField(FieldName.YEAR); if (!value.isPresent()) { return Collections.emptyList(); } @@ -353,7 +353,7 @@ private static class PagesChecker implements Checker { */ @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.PAGES); + Optional value = entry.getField(FieldName.PAGES); if (!value.isPresent()) { return Collections.emptyList(); } @@ -390,7 +390,7 @@ private static class BiblatexPagesChecker implements Checker { */ @Override public List check(BibEntry entry) { - Optional value = entry.getFieldOptional(FieldName.PAGES); + Optional value = entry.getField(FieldName.PAGES); if (!value.isPresent()) { return Collections.emptyList(); } diff --git a/src/main/java/net/sf/jabref/logic/mods/MODSEntry.java b/src/main/java/net/sf/jabref/logic/mods/MODSEntry.java index a70193e2367..eac80b0b7d1 100644 --- a/src/main/java/net/sf/jabref/logic/mods/MODSEntry.java +++ b/src/main/java/net/sf/jabref/logic/mods/MODSEntry.java @@ -84,48 +84,48 @@ public MODSEntry(BibEntry bibtex) { private void populateFromBibtex(BibEntry bibtex) { if (bibtex.hasField(FieldName.TITLE)) { if (CHARFORMAT) { - title = chars.format(bibtex.getFieldOptional(FieldName.TITLE).get()); + title = chars.format(bibtex.getField(FieldName.TITLE).get()); } else { - title = bibtex.getFieldOptional(FieldName.TITLE).get(); + title = bibtex.getField(FieldName.TITLE).get(); } } if (bibtex.hasField(FieldName.PUBLISHER)) { if (CHARFORMAT) { - publisher = chars.format(bibtex.getFieldOptional(FieldName.PUBLISHER).get()); + publisher = chars.format(bibtex.getField(FieldName.PUBLISHER).get()); } else { - publisher = bibtex.getFieldOptional(FieldName.PUBLISHER).get(); + publisher = bibtex.getField(FieldName.PUBLISHER).get(); } } if (bibtex.hasField(BibEntry.KEY_FIELD)) { - id = bibtex.getCiteKey(); + id = bibtex.getCiteKeyOptional().get(); } if (bibtex.hasField("place")) { // TODO: "place" is the MODS version, in BibTeX: "address", BibLaTeX: "location"? if (CHARFORMAT) { - place = chars.format(bibtex.getField("place")); + place = chars.format(bibtex.getField("place").get()); } else { - place = bibtex.getField("place"); + place = bibtex.getField("place").get(); } } date = getDate(bibtex); genre = getMODSgenre(bibtex); if (bibtex.hasField(FieldName.AUTHOR)) { - authors = getAuthors(bibtex.getFieldOptional(FieldName.AUTHOR).get()); + authors = getAuthors(bibtex.getField(FieldName.AUTHOR).get()); } if ("article".equals(bibtex.getType()) || "inproceedings".equals(bibtex.getType())) { host = new MODSEntry(); host.entryType = "relatedItem"; - host.title = bibtex.getField(FieldName.BOOKTITLE); - host.publisher = bibtex.getField(FieldName.PUBLISHER); - host.number = bibtex.getField(FieldName.NUMBER); + host.title = bibtex.getField(FieldName.BOOKTITLE).orElse(null); + host.publisher = bibtex.getField(FieldName.PUBLISHER).orElse(null); + host.number = bibtex.getField(FieldName.NUMBER).orElse(null); if (bibtex.hasField(FieldName.VOLUME)) { - host.volume = bibtex.getFieldOptional(FieldName.VOLUME).get(); + host.volume = bibtex.getField(FieldName.VOLUME).get(); } host.issuance = "continuing"; if (bibtex.hasField(FieldName.PAGES)) { - host.pages = new PageNumbers(bibtex.getFieldOptional(FieldName.PAGES).get()); + host.pages = new PageNumbers(bibtex.getField(FieldName.PAGES).get()); } } @@ -140,11 +140,11 @@ private void populateExtensionFields(BibEntry e) { } } - private List getAuthors(String authors) { + private List getAuthors(String authorString) { List result = new LinkedList<>(); - if (authors.contains(" and ")) { - String[] names = authors.split(" and "); + if (authorString.contains(" and ")) { + String[] names = authorString.split(" and "); for (String name : names) { if (CHARFORMAT) { result.add(new PersonName(chars.format(name))); @@ -154,9 +154,9 @@ private List getAuthors(String authors) { } } else { if (CHARFORMAT) { - result.add(new PersonName(chars.format(authors))); + result.add(new PersonName(chars.format(authorString))); } else { - result.add(new PersonName(authors)); + result.add(new PersonName(authorString)); } } return result; @@ -165,8 +165,8 @@ private List getAuthors(String authors) { /* construct a MODS date object */ private static String getDate(BibEntry bibtex) { StringBuilder result = new StringBuilder(); - bibtex.getFieldOptional(FieldName.YEAR).ifPresent(result::append); - bibtex.getFieldOptional(FieldName.MONTH).ifPresent(result.append('-')::append); + bibtex.getField(FieldName.YEAR).ifPresent(result::append); + bibtex.getField(FieldName.MONTH).ifPresent(result.append('-')::append); return result.toString(); } @@ -235,18 +235,18 @@ public Element getDOMrepresentation(Document d) { Element originInfo = d.createElement("originInfo"); mods.appendChild(originInfo); if (this.publisher != null) { - Element publisher = d.createElement(FieldName.PUBLISHER); - publisher.appendChild(d.createTextNode(StringUtil.stripNonValidXMLCharacters(this.publisher))); - originInfo.appendChild(publisher); + Element publisherElement = d.createElement(FieldName.PUBLISHER); + publisherElement.appendChild(d.createTextNode(StringUtil.stripNonValidXMLCharacters(this.publisher))); + originInfo.appendChild(publisherElement); } if (date != null) { Element dateIssued = d.createElement("dateIssued"); dateIssued.appendChild(d.createTextNode(StringUtil.stripNonValidXMLCharacters(date))); originInfo.appendChild(dateIssued); } - Element issuance = d.createElement("issuance"); - issuance.appendChild(d.createTextNode(StringUtil.stripNonValidXMLCharacters(this.issuance))); - originInfo.appendChild(issuance); + Element issuanceElement = d.createElement("issuance"); + issuanceElement.appendChild(d.createTextNode(StringUtil.stripNonValidXMLCharacters(this.issuance))); + originInfo.appendChild(issuanceElement); if (id != null) { Element idref = d.createElement("identifier"); diff --git a/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java b/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java index 278c500864e..e39dd7f0f60 100644 --- a/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java +++ b/src/main/java/net/sf/jabref/logic/msbib/MSBibConverter.java @@ -26,7 +26,7 @@ public static MSBibEntry convert(BibEntry entry) { for (String field : entry.getFieldNames()) { // clean field - String unicodeField = removeLaTeX(entry.getFieldOptional(field).orElse("")); + String unicodeField = removeLaTeX(entry.getField(field).orElse("")); if (MSBibMapping.getMSBibField(field) != null) { result.fields.put(MSBibMapping.getMSBibField(field), unicodeField); @@ -34,43 +34,43 @@ public static MSBibEntry convert(BibEntry entry) { } // Duplicate: also added as BookTitle - entry.getFieldOptional(FieldName.BOOKTITLE).ifPresent(booktitle -> result.conferenceName = booktitle); - entry.getFieldOptional(FieldName.PAGES).ifPresent(pages -> result.pages = new PageNumbers(pages)); - entry.getFieldOptional(MSBIB_PREFIX + "accessed").ifPresent(accesed -> result.dateAccessed = accesed); + entry.getField(FieldName.BOOKTITLE).ifPresent(booktitle -> result.conferenceName = booktitle); + entry.getField(FieldName.PAGES).ifPresent(pages -> result.pages = new PageNumbers(pages)); + entry.getField(MSBIB_PREFIX + "accessed").ifPresent(accesed -> result.dateAccessed = accesed); // TODO: currently this can never happen if ("SoundRecording".equals(msbibType)) { - result.albumTitle = entry.getFieldOptional(FieldName.TITLE).orElse(null); + result.albumTitle = entry.getField(FieldName.TITLE).orElse(null); } // TODO: currently this can never happen if ("Interview".equals(msbibType)) { - result.broadcastTitle = entry.getFieldOptional(FieldName.TITLE).orElse(null); + result.broadcastTitle = entry.getField(FieldName.TITLE).orElse(null); } if ("Patent".equalsIgnoreCase(entry.getType())) { - result.patentNumber = entry.getFieldOptional(FieldName.NUMBER).orElse(null); + result.patentNumber = entry.getField(FieldName.NUMBER).orElse(null); } result.journalName = entry.getFieldOrAlias(FieldName.JOURNAL).orElse(null); result.month = entry.getFieldOrAlias(FieldName.MONTH).orElse(null); - if (!entry.getFieldOptional(FieldName.YEAR).isPresent()) { + if (!entry.getField(FieldName.YEAR).isPresent()) { result.year = entry.getFieldOrAlias(FieldName.YEAR).orElse(null); } - if (!entry.getFieldOptional(FieldName.ISSUE).isPresent()) { - result.number = entry.getFieldOptional(FieldName.NUMBER).orElse(null); + if (!entry.getField(FieldName.ISSUE).isPresent()) { + result.number = entry.getField(FieldName.NUMBER).orElse(null); } // Value must be converted //Currently only english is supported - entry.getFieldOptional(FieldName.LANGUAGE) + entry.getField(FieldName.LANGUAGE) .ifPresent(lang -> result.fields.put("LCID", String.valueOf(MSBibMapping.getLCID(lang)))); StringBuilder sbNumber = new StringBuilder(); - entry.getFieldOptional(FieldName.ISBN).ifPresent(isbn -> sbNumber.append(" ISBN: " + isbn)); - entry.getFieldOptional(FieldName.ISSN).ifPresent(issn -> sbNumber.append(" ISSN: " + issn)); - entry.getFieldOptional("lccn").ifPresent(lccn -> sbNumber.append("LCCN: " + lccn)); - entry.getFieldOptional("mrnumber").ifPresent(mrnumber -> sbNumber.append(" MRN: " + mrnumber)); + entry.getField(FieldName.ISBN).ifPresent(isbn -> sbNumber.append(" ISBN: " + isbn)); + entry.getField(FieldName.ISSN).ifPresent(issn -> sbNumber.append(" ISSN: " + issn)); + entry.getField("lccn").ifPresent(lccn -> sbNumber.append("LCCN: " + lccn)); + entry.getField("mrnumber").ifPresent(mrnumber -> sbNumber.append(" MRN: " + mrnumber)); result.standardNumber = sbNumber.toString(); if (result.standardNumber.isEmpty()) { @@ -79,8 +79,8 @@ public static MSBibEntry convert(BibEntry entry) { result.address = entry.getFieldOrAlias(FieldName.ADDRESS).orElse(null); - if (entry.getFieldOptional(FieldName.TYPE).isPresent()) { - result.thesisType = entry.getFieldOptional(FieldName.TYPE).get(); + if (entry.getField(FieldName.TYPE).isPresent()) { + result.thesisType = entry.getField(FieldName.TYPE).get(); } else { if ("techreport".equalsIgnoreCase(entry.getType())) { @@ -96,16 +96,16 @@ public static MSBibEntry convert(BibEntry entry) { // TODO: currently this can never happen if (("InternetSite".equals(msbibType) || "DocumentFromInternetSite".equals(msbibType))) { - result.internetSiteTitle = entry.getFieldOptional(FieldName.TITLE).orElse(null); + result.internetSiteTitle = entry.getField(FieldName.TITLE).orElse(null); } // TODO: currently only Misc can happen if ("ElectronicSource".equals(msbibType) || "Art".equals(msbibType) || "Misc".equals(msbibType)) { - result.publicationTitle = entry.getFieldOptional(FieldName.TITLE).orElse(null); + result.publicationTitle = entry.getField(FieldName.TITLE).orElse(null); } - entry.getFieldOptional(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(authors)); - entry.getFieldOptional(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(editors)); + entry.getField(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(authors)); + entry.getField(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(editors)); return result; } diff --git a/src/main/java/net/sf/jabref/logic/openoffice/OOUtil.java b/src/main/java/net/sf/jabref/logic/openoffice/OOUtil.java index 1804173a939..faf9dbcd3cf 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/OOUtil.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/OOUtil.java @@ -72,7 +72,7 @@ public static void insertFullReferenceAtCurrentLocation(XText text, XTextCursor WrappedTargetException, IllegalArgumentException { // Backup the value of the uniq field, just in case the entry already has it: - Optional oldUniqVal = entry.getFieldOptional(UNIQUEFIER_FIELD); + Optional oldUniqVal = entry.getField(UNIQUEFIER_FIELD); // Set the uniq field with the supplied uniquefier: diff --git a/src/main/java/net/sf/jabref/logic/search/rules/GrammarBasedSearchRule.java b/src/main/java/net/sf/jabref/logic/search/rules/GrammarBasedSearchRule.java index 6e049c87c22..70c0ca479a6 100644 --- a/src/main/java/net/sf/jabref/logic/search/rules/GrammarBasedSearchRule.java +++ b/src/main/java/net/sf/jabref/logic/search/rules/GrammarBasedSearchRule.java @@ -152,7 +152,7 @@ public boolean compare(BibEntry entry) { List matchedFieldKeys = fieldsKeys.stream().filter(matchFieldKey()).collect(Collectors.toList()); for (String field : matchedFieldKeys) { - Optional fieldValue = entry.getFieldOptional(field); + Optional fieldValue = entry.getField(field); if (fieldValue.isPresent()) { if (matchFieldValue(fieldValue.get())) { return true; diff --git a/src/main/java/net/sf/jabref/logic/search/rules/RegexBasedSearchRule.java b/src/main/java/net/sf/jabref/logic/search/rules/RegexBasedSearchRule.java index 9cecfce9bc3..5a71f63e6df 100644 --- a/src/main/java/net/sf/jabref/logic/search/rules/RegexBasedSearchRule.java +++ b/src/main/java/net/sf/jabref/logic/search/rules/RegexBasedSearchRule.java @@ -52,7 +52,7 @@ public boolean applyRule(String query, BibEntry bibEntry) { for (String field : bibEntry.getFieldNames()) { if (bibEntry.hasField(field)) { String fieldContent = RegexBasedSearchRule.REMOVE_LATEX_COMMANDS - .format(bibEntry.getFieldOptional(field).get()); + .format(bibEntry.getField(field).get()); String fieldContentNoBrackets = RegexBasedSearchRule.REMOVE_LATEX_COMMANDS.format(fieldContent); Matcher m = pattern.matcher(fieldContentNoBrackets); if (m.find()) { diff --git a/src/main/java/net/sf/jabref/logic/util/UpdateField.java b/src/main/java/net/sf/jabref/logic/util/UpdateField.java index 1c0a977fd3d..4548aa69932 100644 --- a/src/main/java/net/sf/jabref/logic/util/UpdateField.java +++ b/src/main/java/net/sf/jabref/logic/util/UpdateField.java @@ -48,7 +48,7 @@ public static Optional updateField(BibEntry be, String field, Strin String writtenValue = null; String oldValue = null; if (be.hasField(field)) { - oldValue = be.getFieldOptional(field).get(); + oldValue = be.getField(field).get(); if ((newValue == null) || (oldValue.equals(newValue) && nullFieldIfValueIsTheSame)) { // If the new field value is null or the old and the new value are the same and flag is set // Clear the field diff --git a/src/main/java/net/sf/jabref/logic/util/io/DatabaseFileLookup.java b/src/main/java/net/sf/jabref/logic/util/io/DatabaseFileLookup.java index d2e83b48791..f7c0deea6c2 100644 --- a/src/main/java/net/sf/jabref/logic/util/io/DatabaseFileLookup.java +++ b/src/main/java/net/sf/jabref/logic/util/io/DatabaseFileLookup.java @@ -66,7 +66,7 @@ public boolean lookupDatabase(File file) { private List parseFileField(BibEntry entry) { Objects.requireNonNull(entry); - List entries = FileField.parse(entry.getFieldOptional(FieldName.FILE).orElse(null)); + List entries = FileField.parse(entry.getField(FieldName.FILE).orElse(null)); List fileLinks = new ArrayList<>(); for (ParsedFileField field : entries) { diff --git a/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java b/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java index afe612ec0ac..397eb07211e 100644 --- a/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java +++ b/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java @@ -357,7 +357,7 @@ public static List getListOfLinkedFiles(List bes, List f List result = new ArrayList<>(); for (BibEntry entry : bes) { - entry.getFieldOptional(FieldName.FILE).ifPresent(fileField -> { + entry.getField(FieldName.FILE).ifPresent(fileField -> { List fileList = FileField.parse(fileField); for (ParsedFileField file : fileList) { expandFilename(file.getLink(), fileDirs).ifPresent(result::add); diff --git a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java index 6b5feef0be7..ac1f1d1fe06 100644 --- a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java +++ b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java @@ -123,10 +123,6 @@ public static List readXMP(File file, XMPPreferences xmpPreferences) t return result; } - public static PDDocument loadWithAutomaticDecryption(Path filePath) throws IOException { - return loadWithAutomaticDecryption(new FileInputStream(filePath.toFile())); - } - public static PDDocument loadWithAutomaticDecryption(InputStream inputStream) throws IOException { PDDocument doc = PDDocument.load(inputStream); diff --git a/src/main/java/net/sf/jabref/model/DuplicateCheck.java b/src/main/java/net/sf/jabref/model/DuplicateCheck.java index a0152b51ab2..056920d2bd5 100644 --- a/src/main/java/net/sf/jabref/model/DuplicateCheck.java +++ b/src/main/java/net/sf/jabref/model/DuplicateCheck.java @@ -118,8 +118,8 @@ private static double[] compareFieldSet(List fields, BibEntry one, BibEn } private static int compareSingleField(String field, BibEntry one, BibEntry two) { - Optional optionalStringOne = one.getFieldOptional(field); - Optional optionalStringTwo = two.getFieldOptional(field); + Optional optionalStringOne = one.getField(field); + Optional optionalStringTwo = two.getField(field); if (!optionalStringOne.isPresent()) { if (!optionalStringTwo.isPresent()) { return EMPTY_IN_BOTH; @@ -182,8 +182,8 @@ public static double compareEntriesStrictly(BibEntry one, BibEntry two) { int score = 0; for (String field : allFields) { - Optional stringOne = one.getFieldOptional(field); - Optional stringTwo = two.getFieldOptional(field); + Optional stringOne = one.getField(field); + Optional stringTwo = two.getField(field); if (stringOne.equals(stringTwo)) { score++; } diff --git a/src/main/java/net/sf/jabref/model/database/BibDatabase.java b/src/main/java/net/sf/jabref/model/database/BibDatabase.java index cb8109c93da..2fb8f9c196f 100644 --- a/src/main/java/net/sf/jabref/model/database/BibDatabase.java +++ b/src/main/java/net/sf/jabref/model/database/BibDatabase.java @@ -520,7 +520,7 @@ public static Optional getResolvedField(String field, BibEntry entry, Bi // If this field is not set, and the entry has a crossref, try to look up the // field in the referred entry: Do not do this for the bibtex key. if (!result.isPresent() && (database != null)) { - Optional crossrefKey = entry.getFieldOptional(FieldName.CROSSREF); + Optional crossrefKey = entry.getField(FieldName.CROSSREF); if (crossrefKey.isPresent() && !crossrefKey.get().isEmpty()) { Optional referred = database.getEntryByKey(crossrefKey.get()); if (referred.isPresent()) { diff --git a/src/main/java/net/sf/jabref/model/database/KeyChangeListener.java b/src/main/java/net/sf/jabref/model/database/KeyChangeListener.java index 6c0f2a9d945..828105d63d4 100644 --- a/src/main/java/net/sf/jabref/model/database/KeyChangeListener.java +++ b/src/main/java/net/sf/jabref/model/database/KeyChangeListener.java @@ -49,7 +49,7 @@ public void listen(EntryRemovedEvent event) { private void updateEntryLinks(String newKey, String oldKey) { for (BibEntry entry : database.getEntries()) { for (String field : keyFields) { - entry.getFieldOptional(field).ifPresent(fieldContent -> { + entry.getField(field).ifPresent(fieldContent -> { if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) { replaceSingleKeyInField(newKey, oldKey, entry, field, fieldContent); } else { // MULTIPLE_ENTRY_LINK diff --git a/src/main/java/net/sf/jabref/model/entry/BibEntry.java b/src/main/java/net/sf/jabref/model/entry/BibEntry.java index 76e50464794..7e2b45d7710 100644 --- a/src/main/java/net/sf/jabref/model/entry/BibEntry.java +++ b/src/main/java/net/sf/jabref/model/entry/BibEntry.java @@ -172,7 +172,7 @@ public void setType(String type, EntryEventSource eventSource) { } else { newType = type; } - String oldType = getFieldOptional(TYPE_HEADER).orElse(null); + String oldType = getField(TYPE_HEADER).orElse(null); // We set the type before throwing the changeEvent, to enable // the change listener to access the new value if the change @@ -206,18 +206,10 @@ public Set getFieldNames() { return new TreeSet<>(fields.keySet()); } - /** - * Use {@link #getFieldOptional} instead - */ - @Deprecated - public String getField(String name) { - return fields.get(toLowerCase(name)); - } - /** * Returns the contents of the given field as an Optional. */ - public Optional getFieldOptional(String name) { + public Optional getField(String name) { return Optional.ofNullable(fields.get(toLowerCase(name))); } @@ -256,7 +248,7 @@ private String toLowerCase(String fieldName) { * extract the year from the 'date' field (analogously for 'month'). */ public Optional getFieldOrAlias(String name) { - Optional fieldValue = getFieldOptional(toLowerCase(name)); + Optional fieldValue = getField(toLowerCase(name)); if (fieldValue.isPresent() && !fieldValue.get().isEmpty()) { return fieldValue; @@ -266,14 +258,14 @@ public Optional getFieldOrAlias(String name) { String aliasForField = EntryConverter.FIELD_ALIASES.get(name); if (aliasForField != null) { - return getFieldOptional(aliasForField); + return getField(aliasForField); } // Finally, handle dates if (FieldName.DATE.equals(name)) { - Optional year = getFieldOptional(FieldName.YEAR); + Optional year = getField(FieldName.YEAR); if (year.isPresent()) { - MonthUtil.Month month = MonthUtil.getMonth(getFieldOptional(FieldName.MONTH).orElse("")); + MonthUtil.Month month = MonthUtil.getMonth(getField(FieldName.MONTH).orElse("")); if (month.isValid()) { return Optional.of(year.get() + '-' + month.twoDigitNumber); } else { @@ -282,7 +274,7 @@ public Optional getFieldOrAlias(String name) { } } if (FieldName.YEAR.equals(name) || FieldName.MONTH.equals(name)) { - Optional date = getFieldOptional(FieldName.DATE); + Optional date = getField(FieldName.DATE); if (!date.isPresent()) { return Optional.empty(); } @@ -366,7 +358,7 @@ public Optional setField(String name, String value, EntryEventSourc return clearField(fieldName); } - String oldValue = getFieldOptional(fieldName).orElse(null); + String oldValue = getField(fieldName).orElse(null); if (value.equals(oldValue)) { return Optional.empty(); } @@ -426,7 +418,7 @@ public Optional clearField(String name, EntryEventSource eventSourc throw new IllegalArgumentException("The field name '" + name + "' is reserved"); } - Optional oldValue = getFieldOptional(fieldName); + Optional oldValue = getField(fieldName); if (!oldValue.isPresent()) { return Optional.empty(); } @@ -526,8 +518,8 @@ public void setGroupHit(boolean groupHit) { * Author1, Author2: Title (Year) */ public String getAuthorTitleYear(int maxCharacters) { - String[] s = new String[] {getFieldOptional(FieldName.AUTHOR).orElse("N/A"), - getFieldOptional(FieldName.TITLE).orElse("N/A"), getFieldOptional(FieldName.YEAR).orElse("N/A")}; + String[] s = new String[] {getField(FieldName.AUTHOR).orElse("N/A"), + getField(FieldName.TITLE).orElse("N/A"), getField(FieldName.YEAR).orElse("N/A")}; String text = s[0] + ": \"" + s[1] + "\" (" + s[2] + ')'; if ((maxCharacters <= 0) || (text.length() <= maxCharacters)) { @@ -546,9 +538,9 @@ public Optional getPublicationDate() { return Optional.empty(); } - Optional year = getFieldOptional(FieldName.YEAR); + Optional year = getField(FieldName.YEAR); - Optional monthString = getFieldOptional(FieldName.MONTH); + Optional monthString = getField(FieldName.MONTH); if (monthString.isPresent()) { MonthUtil.Month month = MonthUtil.getMonth(monthString.get()); if (month.isValid()) { @@ -581,7 +573,7 @@ public void setChanged(boolean changed) { public Optional putKeywords(Collection keywords, String separator) { Objects.requireNonNull(keywords); - Optional oldValue = this.getFieldOptional(FieldName.KEYWORDS); + Optional oldValue = this.getField(FieldName.KEYWORDS); if (keywords.isEmpty()) { // Clear keyword field diff --git a/src/main/java/net/sf/jabref/model/entry/EntryUtil.java b/src/main/java/net/sf/jabref/model/entry/EntryUtil.java index eaa96e409f1..138d083b2ae 100644 --- a/src/main/java/net/sf/jabref/model/entry/EntryUtil.java +++ b/src/main/java/net/sf/jabref/model/entry/EntryUtil.java @@ -51,7 +51,7 @@ public static Set getSeparatedKeywords(String keywordString) { * @return an List containing the keywords of the entry. An empty list if keywords are null or empty */ public static Set getSeparatedKeywords(BibEntry entry) { - return getSeparatedKeywords(entry.getFieldOptional(FieldName.KEYWORDS).orElse(null)); + return getSeparatedKeywords(entry.getField(FieldName.KEYWORDS).orElse(null)); } /** diff --git a/src/main/java/net/sf/jabref/shared/DBMSProcessor.java b/src/main/java/net/sf/jabref/shared/DBMSProcessor.java index 1b1fbd49a59..e75875f85b8 100644 --- a/src/main/java/net/sf/jabref/shared/DBMSProcessor.java +++ b/src/main/java/net/sf/jabref/shared/DBMSProcessor.java @@ -187,7 +187,7 @@ public void insertEntry(BibEntry bibEntry) { // columnIndex starts with 1 preparedFieldStatement.setInt(1, bibEntry.getSharedBibEntryData().getSharedID()); preparedFieldStatement.setString(2, fieldName); - preparedFieldStatement.setString(3, bibEntry.getFieldOptional(fieldName).get()); + preparedFieldStatement.setString(3, bibEntry.getField(fieldName).get()); preparedFieldStatement.executeUpdate(); } } @@ -288,7 +288,7 @@ private void removeSharedFieldsByDifference(BibEntry localBibEntry, BibEntry sha private void insertOrUpdateFields(BibEntry localBibEntry) throws SQLException { for (String fieldName : localBibEntry.getFieldNames()) { // avoiding to use deprecated BibEntry.getField() method. null values are accepted by PreparedStatement! - Optional valueOptional = localBibEntry.getFieldOptional(fieldName); + Optional valueOptional = localBibEntry.getField(fieldName); String value = null; if (valueOptional.isPresent()) { value = valueOptional.get(); diff --git a/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java b/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java index d2aa162f0cd..794a0d00f39 100644 --- a/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java +++ b/src/main/java/net/sf/jabref/shared/DBMSSynchronizer.java @@ -174,7 +174,7 @@ public void synchronizeLocalDatabase() { localEntry.getSharedBibEntryData() .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); for (String field : sharedEntry.get().getFieldNames()) { - localEntry.setField(field, sharedEntry.get().getFieldOptional(field), EntryEventSource.SHARED); + localEntry.setField(field, sharedEntry.get().getField(field), EntryEventSource.SHARED); } Set redundantLocalEntryFields = localEntry.getFieldNames(); diff --git a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java index b5909a8a024..a23fa6f8b3b 100644 --- a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java +++ b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java @@ -36,11 +36,11 @@ public static void updateField(SpecialField e, String value, BibEntry be, NamedC UpdateField.updateField(be, e.getFieldName(), value, nullFieldIfValueIsTheSame) .ifPresent(fieldChange -> ce.addEdit(new UndoableFieldChange(fieldChange))); // we cannot use "value" here as updateField has side effects: "nullFieldIfValueIsTheSame" nulls the field if value is the same - SpecialFieldsUtils.exportFieldToKeywords(e, be.getFieldOptional(e.getFieldName()).orElse(null), be, ce); + SpecialFieldsUtils.exportFieldToKeywords(e, be.getField(e.getFieldName()).orElse(null), be, ce); } private static void exportFieldToKeywords(SpecialField e, BibEntry be, NamedCompound ce) { - SpecialFieldsUtils.exportFieldToKeywords(e, be.getFieldOptional(e.getFieldName()).orElse(null), be, ce); + SpecialFieldsUtils.exportFieldToKeywords(e, be.getField(e.getFieldName()).orElse(null), be, ce); } private static void exportFieldToKeywords(SpecialField e, String newValue, BibEntry entry, diff --git a/src/test/java/net/sf/jabref/gui/importer/EntryFromFileCreatorManagerTest.java b/src/test/java/net/sf/jabref/gui/importer/EntryFromFileCreatorManagerTest.java index 0322e9516b6..2d53875217d 100644 --- a/src/test/java/net/sf/jabref/gui/importer/EntryFromFileCreatorManagerTest.java +++ b/src/test/java/net/sf/jabref/gui/importer/EntryFromFileCreatorManagerTest.java @@ -68,7 +68,7 @@ public void testAddEntrysFromFiles() throws FileNotFoundException, IOException { boolean file1Found = false; boolean file2Found = false; for (BibEntry entry : database.getEntries()) { - String filesInfo = entry.getFieldOptional("file").get(); + String filesInfo = entry.getField("file").get(); if (filesInfo.contains(files.get(0).getName())) { file1Found = true; } diff --git a/src/test/java/net/sf/jabref/gui/importer/EntryFromPDFCreatorTest.java b/src/test/java/net/sf/jabref/gui/importer/EntryFromPDFCreatorTest.java index bd649dae522..dfb923bb0fb 100644 --- a/src/test/java/net/sf/jabref/gui/importer/EntryFromPDFCreatorTest.java +++ b/src/test/java/net/sf/jabref/gui/importer/EntryFromPDFCreatorTest.java @@ -49,9 +49,9 @@ public void testCreationOfEntryNoPDF() { public void testCreationOfEntryNotInDatabase() { Optional entry = entryCreator.createEntry(ImportDataTest.FILE_NOT_IN_DATABASE, false); Assert.assertTrue(entry.isPresent()); - Assert.assertTrue(entry.get().getFieldOptional("file").get().endsWith(":PDF")); + Assert.assertTrue(entry.get().getField("file").get().endsWith(":PDF")); Assert.assertEquals(Optional.of(ImportDataTest.FILE_NOT_IN_DATABASE.getName()), - entry.get().getFieldOptional("title")); + entry.get().getField("title")); } } \ No newline at end of file diff --git a/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java b/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java index 0caddafa8ae..20086b8671a 100644 --- a/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java +++ b/src/test/java/net/sf/jabref/gui/importer/actions/ConvertLegacyExplicitGroupsTest.java @@ -46,7 +46,7 @@ public void performActionWritesGroupMembershipInEntry() throws Exception { action.performAction(basePanel, parserResult); - assertEquals(Optional.of("TestGroup"), entry.getFieldOptional("groups")); + assertEquals(Optional.of("TestGroup"), entry.getField("groups")); } @Test @@ -68,7 +68,7 @@ public void performActionWritesGroupMembershipInEntryForComplexGroupTree() throw action.performAction(basePanel, parserResult); - assertEquals(Optional.of("TestGroup"), entry.getFieldOptional("groups")); + assertEquals(Optional.of("TestGroup"), entry.getField("groups")); } @Test diff --git a/src/test/java/net/sf/jabref/gui/importer/fetcher/OAI2HandlerFetcherTest.java b/src/test/java/net/sf/jabref/gui/importer/fetcher/OAI2HandlerFetcherTest.java index 0aa5f495ffc..9616734e715 100644 --- a/src/test/java/net/sf/jabref/gui/importer/fetcher/OAI2HandlerFetcherTest.java +++ b/src/test/java/net/sf/jabref/gui/importer/fetcher/OAI2HandlerFetcherTest.java @@ -56,22 +56,22 @@ public void testCorrectLineBreaks() { public void testParse() throws Throwable { try { saxParser.parse(this.getClass().getResourceAsStream("oai2.xml"), handler); - Assert.assertEquals(Optional.of("hep-ph/0408155"), be.getFieldOptional("eprint")); + Assert.assertEquals(Optional.of("hep-ph/0408155"), be.getField("eprint")); Assert.assertEquals(Optional.of("G. F. Giudice and A. Riotto and A. Zaffaroni and J. López-Peña"), - be.getFieldOptional("author")); - Assert.assertEquals(Optional.of("Nucl.Phys. B"), be.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("710"), be.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("2005"), be.getFieldOptional("year")); - Assert.assertEquals(Optional.of("511-525"), be.getFieldOptional("pages")); + be.getField("author")); + Assert.assertEquals(Optional.of("Nucl.Phys. B"), be.getField("journal")); + Assert.assertEquals(Optional.of("710"), be.getField("volume")); + Assert.assertEquals(Optional.of("2005"), be.getField("year")); + Assert.assertEquals(Optional.of("511-525"), be.getField("pages")); // Citekey is only generated if the user says so in the import // inspection dialog. Assert.assertEquals(Optional.empty(), be.getCiteKeyOptional()); - Assert.assertEquals(Optional.of("Heavy Particles from Inflation"), be.getFieldOptional("title")); - Assert.assertTrue(be.getFieldOptional("abstract").isPresent()); - Assert.assertEquals(Optional.of("23 pages"), be.getFieldOptional("comments")); - Assert.assertEquals(Optional.of("CERN-PH-TH/2004-151"), be.getFieldOptional("reportno")); + Assert.assertEquals(Optional.of("Heavy Particles from Inflation"), be.getField("title")); + Assert.assertTrue(be.getField("abstract").isPresent()); + Assert.assertEquals(Optional.of("23 pages"), be.getField("comments")); + Assert.assertEquals(Optional.of("CERN-PH-TH/2004-151"), be.getField("reportno")); } catch (SAXException e) { throw e.getException(); } @@ -81,7 +81,7 @@ public void testParse() throws Throwable { public void testOai22xml() throws SAXException, IOException { saxParser.parse(this.getClass().getResourceAsStream("oai22.xml"), handler); - Assert.assertEquals(Optional.of("2005"), be.getFieldOptional("year")); + Assert.assertEquals(Optional.of("2005"), be.getField("year")); } @@ -89,7 +89,7 @@ public void testOai22xml() throws SAXException, IOException { public void testOai23xml() throws SAXException, IOException { saxParser.parse(this.getClass().getResourceAsStream("oai23.xml"), handler); - Assert.assertEquals(Optional.of("Javier López Peña and Gabriel Navarro"), be.getFieldOptional("author")); + Assert.assertEquals(Optional.of("Javier López Peña and Gabriel Navarro"), be.getField("author")); } @@ -126,11 +126,11 @@ public void testOnline() throws InterruptedException { be = fetcher.importOai2Entry("math.RA/0612188"); Assert.assertNotNull(be); - Assert.assertEquals(Optional.of("math/0612188"), be.getFieldOptional("eprint")); + Assert.assertEquals(Optional.of("math/0612188"), be.getField("eprint")); Assert.assertEquals(Optional.of("On the classification and properties of noncommutative duplicates"), - be.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Javier López Peña and Gabriel Navarro"), be.getFieldOptional("author")); - Assert.assertEquals(Optional.of("2007"), be.getFieldOptional("year")); + be.getField("title")); + Assert.assertEquals(Optional.of("Javier López Peña and Gabriel Navarro"), be.getField("author")); + Assert.assertEquals(Optional.of("2007"), be.getField("year")); Thread.sleep(20000); } @@ -140,11 +140,11 @@ public void testOnline() throws InterruptedException { be = fetcher.importOai2Entry("astro-ph/0702080"); Assert.assertNotNull(be); - Assert.assertEquals(Optional.of("astro-ph/0702080"), be.getFieldOptional("eprint")); + Assert.assertEquals(Optional.of("astro-ph/0702080"), be.getField("eprint")); Assert.assertEquals( Optional.of( "Magnetized Hypermassive Neutron Star Collapse: a candidate central engine for short-hard GRBs"), - be.getFieldOptional("title")); + be.getField("title")); Thread.sleep(20000); } @@ -154,7 +154,7 @@ public void testOnline() throws InterruptedException { be = fetcher.importOai2Entry("math.QA/0601001"); Assert.assertNotNull(be); - Assert.assertEquals(Optional.of("math/0601001"), be.getFieldOptional("eprint")); + Assert.assertEquals(Optional.of("math/0601001"), be.getField("eprint")); Thread.sleep(20000); } @@ -163,7 +163,7 @@ public void testOnline() throws InterruptedException { be = fetcher.importOai2Entry("hep-ph/0408155"); Assert.assertNotNull(be); - Assert.assertEquals(Optional.of("hep-ph/0408155"), be.getFieldOptional("eprint")); + Assert.assertEquals(Optional.of("hep-ph/0408155"), be.getField("eprint")); Thread.sleep(20000); } @@ -171,8 +171,8 @@ public void testOnline() throws InterruptedException { be = fetcher.importOai2Entry("0709.3040"); Assert.assertNotNull(be); - Assert.assertEquals(Optional.of("2007"), be.getFieldOptional("year")); - Assert.assertEquals(Optional.of("#sep#"), be.getFieldOptional("month")); + Assert.assertEquals(Optional.of("2007"), be.getField("year")); + Assert.assertEquals(Optional.of("#sep#"), be.getField("month")); } } diff --git a/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java index db746ffda43..2242a73f4e6 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java @@ -295,7 +295,7 @@ public void monthFieldSpecialSyntax() throws IOException { // modify month field Set fields = entry.getFieldNames(); assertTrue(fields.contains("month")); - assertEquals("#mar#", entry.getFieldOptional("month").get()); + assertEquals("#mar#", entry.getField("month").get()); //write out bibtex string StringWriter stringWriter = new StringWriter(); diff --git a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java index 3554c218835..a273d0839d1 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java @@ -105,8 +105,8 @@ public void upgradeExternalLinksMoveFromPdfToFile() { entry.setField("pdf", "aPdfFile"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.empty(), entry.getFieldOptional("pdf")); - Assert.assertEquals(Optional.of("aPdfFile:aPdfFile:PDF"), entry.getFieldOptional("file")); + Assert.assertEquals(Optional.empty(), entry.getField("pdf")); + Assert.assertEquals(Optional.of("aPdfFile:aPdfFile:PDF"), entry.getField("file")); } @Test @@ -116,8 +116,8 @@ public void upgradeExternalLinksMoveFromPsToFile() { entry.setField("ps", "aPsFile"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.empty(), entry.getFieldOptional("pdf")); - Assert.assertEquals(Optional.of("aPsFile:aPsFile:PostScript"), entry.getFieldOptional("file")); + Assert.assertEquals(Optional.empty(), entry.getField("pdf")); + Assert.assertEquals(Optional.of("aPsFile:aPsFile:PostScript"), entry.getField("file")); } @Test @@ -127,7 +127,7 @@ public void cleanupDoiRemovesLeadingHttp() { entry.setField("doi", "http://dx.doi.org/10.1016/0001-8708(80)90035-3"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("10.1016/0001-8708(80)90035-3"), entry.getFieldOptional("doi")); + Assert.assertEquals(Optional.of("10.1016/0001-8708(80)90035-3"), entry.getField("doi")); } @Test @@ -150,8 +150,8 @@ public void cleanupDoiFindsDoiInURLFieldAndMoveItToDOIField() { entry.setField("url", "http://dx.doi.org/10.1016/0001-8708(80)90035-3"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("10.1016/0001-8708(80)90035-3"), entry.getFieldOptional("doi")); - Assert.assertEquals(Optional.empty(), entry.getFieldOptional("url")); + Assert.assertEquals(Optional.of("10.1016/0001-8708(80)90035-3"), entry.getField("doi")); + Assert.assertEquals(Optional.empty(), entry.getField("url")); } @Test @@ -175,7 +175,7 @@ public void cleanupMonthChangesNumberToBibtex() { entry.setField("month", "01"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("#jan#"), entry.getFieldOptional("month")); + Assert.assertEquals(Optional.of("#jan#"), entry.getField("month")); } @Test @@ -186,7 +186,7 @@ public void cleanupPageNumbersConvertsSingleDashToDouble() { entry.setField("pages", "1-2"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("1--2"), entry.getFieldOptional("pages")); + Assert.assertEquals(Optional.of("1--2"), entry.getField("pages")); } @Test @@ -197,7 +197,7 @@ public void cleanupDatesConvertsToCorrectFormat() { entry.setField("date", "01/1999"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("1999-01"), entry.getFieldOptional("date")); + Assert.assertEquals(Optional.of("1999-01"), entry.getField("date")); } @Test @@ -207,7 +207,7 @@ public void cleanupFixFileLinksMovesSingleDescriptionToLink() { entry.setField("file", "link::"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of(":link:"), entry.getFieldOptional("file")); + Assert.assertEquals(Optional.of(":link:"), entry.getField("file")); } @Test @@ -224,7 +224,7 @@ public void cleanupMoveFilesMovesFileFromSubfolder() throws IOException { worker.cleanup(preset, entry); ParsedFileField newFileField = new ParsedFileField("", tempFile.getName(), ""); Assert.assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), - entry.getFieldOptional("file")); + entry.getField("file")); } @Test @@ -239,7 +239,7 @@ public void cleanupRelativePathsConvertAbsoluteToRelativePath() throws IOExcepti worker.cleanup(preset, entry); ParsedFileField newFileField = new ParsedFileField("", tempFile.getName(), ""); Assert.assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), - entry.getFieldOptional("file")); + entry.getField("file")); } @Test @@ -255,7 +255,7 @@ public void cleanupRenamePdfRenamesRelativeFile() throws IOException { worker.cleanup(preset, entry); ParsedFileField newFileField = new ParsedFileField("", "Toot.tmp", ""); Assert.assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), - entry.getFieldOptional("file")); + entry.getField("file")); } @Test @@ -266,7 +266,7 @@ public void cleanupHtmlToLatexConvertsEpsilonToLatex() { entry.setField("title", "Ε"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("{{$\\Epsilon$}}"), entry.getFieldOptional("title")); + Assert.assertEquals(Optional.of("{{$\\Epsilon$}}"), entry.getField("title")); } @Test @@ -277,7 +277,7 @@ public void cleanupUnitsConvertsOneAmpereToLatex() { entry.setField("title", "1 A"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("1~{A}"), entry.getFieldOptional("title")); + Assert.assertEquals(Optional.of("1~{A}"), entry.getField("title")); } @Test @@ -292,7 +292,7 @@ public void cleanupCasesAddsBracketAroundAluminiumGalliumArsenid() { entry.setField("title", "AlGaAs"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("{AlGaAs}"), entry.getFieldOptional("title")); + Assert.assertEquals(Optional.of("{AlGaAs}"), entry.getField("title")); } @Test @@ -303,7 +303,7 @@ public void cleanupLatexMergesTwoLatexMathEnvironments() { entry.setField("title", "$\\alpha$$\\beta$"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("$\\alpha\\beta$"), entry.getFieldOptional("title")); + Assert.assertEquals(Optional.of("$\\alpha\\beta$"), entry.getField("title")); } @Test @@ -313,8 +313,8 @@ public void convertToBiblatexMovesJournalToJournalTitle() { entry.setField("journal", "test"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.empty(), entry.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("test"), entry.getFieldOptional("journaltitle")); + Assert.assertEquals(Optional.empty(), entry.getField("journal")); + Assert.assertEquals(Optional.of("test"), entry.getField("journaltitle")); } @Test @@ -325,6 +325,6 @@ public void cleanupWithDisabledFieldFormatterChangesNothing() { entry.setField("month", "01"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("01"), entry.getFieldOptional("month")); + Assert.assertEquals(Optional.of("01"), entry.getField("month")); } } diff --git a/src/test/java/net/sf/jabref/logic/cleanup/ISSNCleanupTest.java b/src/test/java/net/sf/jabref/logic/cleanup/ISSNCleanupTest.java index dfca8f9e021..eb82eb644a1 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/ISSNCleanupTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/ISSNCleanupTest.java @@ -31,7 +31,7 @@ public void cleanupISSNReturnsCorrectISSN() { entry.setField("issn", "0123-4567"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("0123-4567"), entry.getFieldOptional("issn")); + Assert.assertEquals(Optional.of("0123-4567"), entry.getField("issn")); } @Test @@ -41,7 +41,7 @@ public void cleanupISSNAddsMissingDash() { entry.setField("issn", "01234567"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("0123-4567"), entry.getFieldOptional("issn")); + Assert.assertEquals(Optional.of("0123-4567"), entry.getField("issn")); } @Test @@ -51,7 +51,7 @@ public void cleanupISSNJunkStaysJunk() { entry.setField("issn", "Banana"); worker.cleanup(preset, entry); - Assert.assertEquals(Optional.of("Banana"), entry.getFieldOptional("issn")); + Assert.assertEquals(Optional.of("Banana"), entry.getField("issn")); } } diff --git a/src/test/java/net/sf/jabref/logic/cleanup/MoveFilesCleanupTest.java b/src/test/java/net/sf/jabref/logic/cleanup/MoveFilesCleanupTest.java index 1c8950da6da..75b92a6bb6c 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/MoveFilesCleanupTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/MoveFilesCleanupTest.java @@ -59,7 +59,7 @@ public void movesFileFromSubfolder() throws IOException { assertTrue(fileAfter.exists()); assertEquals(Optional.of(FileField.getStringRepresentation(new ParsedFileField("", fileAfter.getName(), ""))), - entry.getFieldOptional("file")); + entry.getField("file")); } @Test @@ -82,6 +82,6 @@ public void movesFileFromSubfolderMultiple() throws IOException { assertEquals( Optional.of(FileField.getStringRepresentation(Arrays.asList(new ParsedFileField("", "", ""), new ParsedFileField("", fileAfter.getName(), ""), new ParsedFileField("", "", "")))), - entry.getFieldOptional("file")); + entry.getField("file")); } } \ No newline at end of file diff --git a/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java b/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java index 28eea0fb278..71fe18d31d2 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java @@ -58,7 +58,7 @@ public void cleanupRenamePdfRenamesFileEvenIfOnlyDifferenceIsCase() throws IOExc cleanup.cleanup(entry); ParsedFileField newFileField = new ParsedFileField("", "Toot.tmp", ""); - assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), entry.getFieldOptional("file")); + assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), entry.getField("file")); } @Test @@ -77,7 +77,7 @@ public void cleanupRenamePdfRenamesWithMultipleFiles() throws IOException { assertEquals( Optional.of(FileField.getStringRepresentation(Arrays.asList(new ParsedFileField("", "", ""), new ParsedFileField("", "Toot - test title.tmp", ""), new ParsedFileField("", "", "")))), - entry.getFieldOptional("file")); + entry.getField("file")); } @Test @@ -93,7 +93,7 @@ public void cleanupRenamePdfRenamesFileStartingWithBibtexKey() throws IOExceptio cleanup.cleanup(entry); ParsedFileField newFileField = new ParsedFileField("", "Toot - test title.tmp", ""); - assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), entry.getFieldOptional("file")); + assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), entry.getField("file")); } @Test @@ -110,6 +110,6 @@ public void cleanupRenamePdfRenamesFileInSameFolder() throws IOException { cleanup.cleanup(entry); ParsedFileField newFileField = new ParsedFileField("", "Toot - test title.pdf", "PDF"); - assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), entry.getFieldOptional("file")); + assertEquals(Optional.of(FileField.getStringRepresentation(newFileField)), entry.getField("file")); } } diff --git a/src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java b/src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java index a164cabfbf1..8c2f24d09d0 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java @@ -48,7 +48,7 @@ public void checkSimpleUseCase() { actions.applySaveActions(entry); - assertEquals(Optional.of("Educational session 1"), entry.getFieldOptional("title")); + assertEquals(Optional.of("Educational session 1"), entry.getField("title")); } @Test @@ -60,7 +60,7 @@ public void invalidSaveActionSting() { actions.applySaveActions(entry); - assertEquals(Optional.of("Educational session 1"), entry.getFieldOptional("title")); + assertEquals(Optional.of("Educational session 1"), entry.getField("title")); } @Test @@ -73,7 +73,7 @@ public void checkLowerCaseSaveAction() { actions.applySaveActions(entry); - assertEquals(Optional.of("educational session 1"), entry.getFieldOptional("title")); + assertEquals(Optional.of("educational session 1"), entry.getField("title")); } @Test @@ -86,7 +86,7 @@ public void checkTwoSaveActionsForOneField() { actions.applySaveActions(entry); - assertEquals(Optional.of("educational session 1"), entry.getFieldOptional("title")); + assertEquals(Optional.of("educational session 1"), entry.getField("title")); } @Test @@ -101,7 +101,7 @@ public void checkThreeSaveActionsForOneField() { actions.applySaveActions(entry); - assertEquals(Optional.of("educational session 1"), entry.getFieldOptional("title")); + assertEquals(Optional.of("educational session 1"), entry.getField("title")); } @Test @@ -116,8 +116,8 @@ public void checkMultipleSaveActions() { actions.applySaveActions(entry); - assertEquals(Optional.of("educational session 1"), entry.getFieldOptional("title")); - assertEquals(Optional.of("1--7"), entry.getFieldOptional("pages")); + assertEquals(Optional.of("educational session 1"), entry.getField("title")); + assertEquals(Optional.of("1--7"), entry.getField("pages")); } @Test @@ -134,8 +134,8 @@ public void checkMultipleSaveActionsWithMultipleFormatters() { actions.applySaveActions(entry); - assertEquals(Optional.of("educational session 1"), entry.getFieldOptional("title")); - assertEquals(Optional.of("1--7"), entry.getFieldOptional("pages")); + assertEquals(Optional.of("educational session 1"), entry.getField("title")); + assertEquals(Optional.of("1--7"), entry.getField("pages")); } @Test @@ -143,6 +143,6 @@ public void clearFormatterRemovesField() { FieldFormatterCleanups actions = new FieldFormatterCleanups(true, "mont[clear]"); actions.applySaveActions(entry); - assertEquals(Optional.empty(), entry.getFieldOptional("mont")); + assertEquals(Optional.empty(), entry.getField("mont")); } } diff --git a/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java b/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java index ae943b3582f..05dcf2207ed 100644 --- a/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/OpenDatabaseTest.java @@ -76,7 +76,7 @@ public void entriesAreParsedNoHeader() throws IOException { // Entry Assert.assertEquals(1, db.getEntryCount()); - Assert.assertEquals(Optional.of("2014"), db.getEntryByKey("1").get().getFieldOptional("year")); + Assert.assertEquals(Optional.of("2014"), db.getEntryByKey("1").get().getField("year")); } @Test @@ -86,7 +86,7 @@ public void entriesAreParsedHeader() throws IOException { // Entry Assert.assertEquals(1, db.getEntryCount()); - Assert.assertEquals(Optional.of("2014"), db.getEntryByKey("1").get().getFieldOptional("year")); + Assert.assertEquals(Optional.of("2014"), db.getEntryByKey("1").get().getField("year")); } @Test @@ -96,7 +96,7 @@ public void entriesAreParsedHeaderAndSignature() throws IOException { // Entry Assert.assertEquals(1, db.getEntryCount()); - Assert.assertEquals(Optional.of("2014"), db.getEntryByKey("1").get().getFieldOptional("year")); + Assert.assertEquals(Optional.of("2014"), db.getEntryByKey("1").get().getField("year")); } /** diff --git a/src/test/java/net/sf/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/net/sf/jabref/logic/importer/fetcher/ArXivTest.java index 644530845fc..0fe2834af5a 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fetcher/ArXivTest.java @@ -134,7 +134,7 @@ public void searchEntryByIdWith4Digits() throws Exception { public void searchEntryByIdWith5Digits() throws Exception { assertEquals(Optional.of( "An Optimal Convergence Theorem for Mean Curvature Flow of Arbitrary Codimension in Hyperbolic Spaces"), - finder.performSearchById("1503.06747").flatMap(entry -> entry.getFieldOptional("title"))); + finder.performSearchById("1503.06747").flatMap(entry -> entry.getField("title"))); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fetcher/GVKParserTest.java b/src/test/java/net/sf/jabref/logic/importer/fetcher/GVKParserTest.java index b66c7556427..2d2a47bfff3 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fetcher/GVKParserTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fetcher/GVKParserTest.java @@ -57,19 +57,19 @@ public void subTitleTest() throws IOException, ParserConfigurationException, SAX Assert.assertEquals(5, entries.size()); BibEntry entry = entries.get(0); - Assert.assertEquals(Optional.empty(), entry.getFieldOptional("subtitle")); + Assert.assertEquals(Optional.empty(), entry.getField("subtitle")); entry = entries.get(1); - Assert.assertEquals(Optional.of("C"), entry.getFieldOptional("subtitle")); + Assert.assertEquals(Optional.of("C"), entry.getField("subtitle")); entry = entries.get(2); - Assert.assertEquals(Optional.of("Word"), entry.getFieldOptional("subtitle")); + Assert.assertEquals(Optional.of("Word"), entry.getField("subtitle")); entry = entries.get(3); - Assert.assertEquals(Optional.of("Word1 word2"), entry.getFieldOptional("subtitle")); + Assert.assertEquals(Optional.of("Word1 word2"), entry.getField("subtitle")); entry = entries.get(4); - Assert.assertEquals(Optional.of("Word1 word2"), entry.getFieldOptional("subtitle")); + Assert.assertEquals(Optional.of("Word1 word2"), entry.getField("subtitle")); } } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java index 526137ed8ce..c4551bdaf62 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java @@ -56,49 +56,49 @@ public void testImportEntries() throws IOException, URISyntaxException { Optional.of( "Aks{\\i}n, {\\\"O}zge and T{\\\"u}rkmen, Hayati and Artok, Levent and {\\c{C}}etinkaya, " + "Bekir and Ni, Chaoying and B{\\\"u}y{\\\"u}kg{\\\"u}ng{\\\"o}r, Orhan and {\\\"O}zkal, Erhan"), - entry.getFieldOptional("author")); - assertEquals(Optional.of("aksin"), entry.getFieldOptional("bibtexkey")); - assertEquals(Optional.of("2006"), entry.getFieldOptional("date")); + entry.getField("author")); + assertEquals(Optional.of("aksin"), entry.getField("bibtexkey")); + assertEquals(Optional.of("2006"), entry.getField("date")); assertEquals(Optional.of("Effect of immobilization on catalytic characteristics"), - entry.getFieldOptional("indextitle")); - assertEquals(Optional.of("#jomch#"), entry.getFieldOptional("journaltitle")); - assertEquals(Optional.of("13"), entry.getFieldOptional("number")); - assertEquals(Optional.of("3027-3036"), entry.getFieldOptional("pages")); + entry.getField("indextitle")); + assertEquals(Optional.of("#jomch#"), entry.getField("journaltitle")); + assertEquals(Optional.of("13"), entry.getField("number")); + assertEquals(Optional.of("3027-3036"), entry.getField("pages")); assertEquals(Optional .of("Effect of immobilization on catalytic characteristics of saturated {Pd-N}-heterocyclic " + "carbenes in {Mizoroki-Heck} reactions"), - entry.getFieldOptional("title")); - assertEquals(Optional.of("691"), entry.getFieldOptional("volume")); + entry.getField("title")); + assertEquals(Optional.of("691"), entry.getField("volume")); } else if (entry.getCiteKeyOptional().get().equals("stdmodel")) { assertEquals(Optional .of("A \\texttt{set} with three members discussing the standard model of particle physics. " + "The \\texttt{crossref} field in the \\texttt{@set} entry and the \\texttt{entryset} field in " + "each set member entry is needed only when using BibTeX as the backend"), - entry.getFieldOptional("annotation")); - assertEquals(Optional.of("stdmodel"), entry.getFieldOptional("bibtexkey")); - assertEquals(Optional.of("glashow,weinberg,salam"), entry.getFieldOptional("entryset")); + entry.getField("annotation")); + assertEquals(Optional.of("stdmodel"), entry.getField("bibtexkey")); + assertEquals(Optional.of("glashow,weinberg,salam"), entry.getField("entryset")); } else if (entry.getCiteKeyOptional().get().equals("set")) { assertEquals(Optional .of("A \\texttt{set} with three members. The \\texttt{crossref} field in the \\texttt{@set} " + "entry and the \\texttt{entryset} field in each set member entry is needed only when using " + "BibTeX as the backend"), - entry.getFieldOptional("annotation")); - assertEquals(Optional.of("set"), entry.getFieldOptional("bibtexkey")); - assertEquals(Optional.of("herrmann,aksin,yoon"), entry.getFieldOptional("entryset")); + entry.getField("annotation")); + assertEquals(Optional.of("set"), entry.getField("bibtexkey")); + assertEquals(Optional.of("herrmann,aksin,yoon"), entry.getField("entryset")); } else if (entry.getCiteKeyOptional().get().equals("Preissel2016")) { - assertEquals(Optional.of("Heidelberg"), entry.getFieldOptional("address")); - assertEquals(Optional.of("Preißel, René"), entry.getFieldOptional("author")); - assertEquals(Optional.of("Preissel2016"), entry.getFieldOptional("bibtexkey")); + assertEquals(Optional.of("Heidelberg"), entry.getField("address")); + assertEquals(Optional.of("Preißel, René"), entry.getField("author")); + assertEquals(Optional.of("Preissel2016"), entry.getField("bibtexkey")); assertEquals(Optional.of("3., aktualisierte und erweiterte Auflage"), - entry.getFieldOptional("edition")); - assertEquals(Optional.of("978-3-86490-311-3"), entry.getFieldOptional("isbn")); - assertEquals(Optional.of("Versionsverwaltung"), entry.getFieldOptional("keywords")); - assertEquals(Optional.of("XX, 327 Seiten"), entry.getFieldOptional("pages")); - assertEquals(Optional.of("dpunkt.verlag"), entry.getFieldOptional("publisher")); + entry.getField("edition")); + assertEquals(Optional.of("978-3-86490-311-3"), entry.getField("isbn")); + assertEquals(Optional.of("Versionsverwaltung"), entry.getField("keywords")); + assertEquals(Optional.of("XX, 327 Seiten"), entry.getField("pages")); + assertEquals(Optional.of("dpunkt.verlag"), entry.getField("publisher")); assertEquals(Optional.of("Git: dezentrale Versionsverwaltung im Team : Grundlagen und Workflows"), - entry.getFieldOptional("title")); - assertEquals(Optional.of("http://d-nb.info/107601965X"), entry.getFieldOptional("url")); - assertEquals(Optional.of("2016"), entry.getFieldOptional("year")); + entry.getField("title")); + assertEquals(Optional.of("http://d-nb.info/107601965X"), entry.getField("url")); + assertEquals(Optional.of("2016"), entry.getField("year")); } } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java index d6e6d1a29f0..1031d057255 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -147,7 +147,7 @@ public void parseRecognizesEntry() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -163,7 +163,7 @@ public void parseQuotedEntries() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -192,7 +192,7 @@ public void parseRecognizesEntryWithWhitespaceAtBegining() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -208,7 +208,7 @@ public void parseRecognizesEntryWithWhitespace() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -224,7 +224,7 @@ public void parseRecognizesEntryWithNewlines() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -240,7 +240,7 @@ public void parseRecognizesEntryWithUnknownType() throws IOException { assertEquals("unknown", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -257,7 +257,7 @@ public void parseRecognizesEntryWithVeryLongType() throws IOException { assertEquals("thisisalongstringtotestmaybeitistolongwhoknowsnotme", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -273,7 +273,7 @@ public void parseRecognizesEntryInParenthesis() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } /** @@ -291,9 +291,9 @@ public void parseRecognizesEntryWithBigNumbers() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("canh05"), e.getCiteKeyOptional()); - assertEquals(Optional.of("1234567890123456789"), e.getFieldOptional("isbn")); - assertEquals(Optional.of("1234567890123456789"), e.getFieldOptional("isbn2")); - assertEquals(Optional.of("1234"), e.getFieldOptional("small")); + assertEquals(Optional.of("1234567890123456789"), e.getField("isbn")); + assertEquals(Optional.of("1234567890123456789"), e.getField("isbn2")); + assertEquals(Optional.of("1234"), e.getField("small")); } @Test @@ -309,7 +309,7 @@ public void parseRecognizesBibtexKeyWithSpecialCharacters() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("te_st:with-special(characters)"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -325,7 +325,7 @@ public void parseRecognizesEntryWhereLastFieldIsFinishedWithComma() throws IOExc assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -437,7 +437,7 @@ public void parseCombinesMultipleAuthorFields() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test and Second Author and Third Author"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test and Second Author and Third Author"), e.getField("author")); } @Test @@ -454,7 +454,7 @@ public void parseCombinesMultipleEditorFields() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test and Second Author and Third Author"), e.getFieldOptional("editor")); + assertEquals(Optional.of("Ed von Test and Second Author and Third Author"), e.getField("editor")); } /** @@ -474,7 +474,7 @@ public void parseCombinesMultipleKeywordsFields() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Test, Second Keyword, Third Keyword"), e.getFieldOptional("keywords")); + assertEquals(Optional.of("Test, Second Keyword, Third Keyword"), e.getField("keywords")); } @Test @@ -497,15 +497,15 @@ public void parseRecognizesHeaderButIgnoresEncoding() throws IOException { assertEquals(8, e.getFieldNames().size()); assertEquals(Optional.of("CroAnnHow05"), e.getCiteKeyOptional()); assertEquals(Optional.of("Crowston, K. and Annabi, H. and Howison, J. and Masango, C."), - e.getFieldOptional("author")); + e.getField("author")); assertEquals(Optional.of("Effective work practices for floss development: A model and propositions"), - e.getFieldOptional("title")); + e.getField("title")); assertEquals(Optional.of("Hawaii International Conference On System Sciences (HICSS)"), - e.getFieldOptional("booktitle")); - assertEquals(Optional.of("2005"), e.getFieldOptional("year")); - assertEquals(Optional.of("oezbek"), e.getFieldOptional("owner")); - assertEquals(Optional.of("2006.05.29"), e.getFieldOptional("timestamp")); - assertEquals(Optional.of("http://james.howison.name/publications.html"), e.getFieldOptional("url")); + e.getField("booktitle")); + assertEquals(Optional.of("2005"), e.getField("year")); + assertEquals(Optional.of("oezbek"), e.getField("owner")); + assertEquals(Optional.of("2006.05.29"), e.getField("timestamp")); + assertEquals(Optional.of("http://james.howison.name/publications.html"), e.getField("url")); } @Test @@ -526,15 +526,15 @@ public void parseRecognizesFormatedEntry() throws IOException { assertEquals(8, e.getFieldNames().size()); assertEquals(Optional.of("CroAnnHow05"), e.getCiteKeyOptional()); assertEquals(Optional.of("Crowston, K. and Annabi, H. and Howison, J. and Masango, C."), - e.getFieldOptional("author")); + e.getField("author")); assertEquals(Optional.of("Effective work practices for floss development: A model and propositions"), - e.getFieldOptional("title")); + e.getField("title")); assertEquals(Optional.of("Hawaii International Conference On System Sciences (HICSS)"), - e.getFieldOptional("booktitle")); - assertEquals(Optional.of("2005"), e.getFieldOptional("year")); - assertEquals(Optional.of("oezbek"), e.getFieldOptional("owner")); - assertEquals(Optional.of("2006.05.29"), e.getFieldOptional("timestamp")); - assertEquals(Optional.of("http://james.howison.name/publications.html"), e.getFieldOptional("url")); + e.getField("booktitle")); + assertEquals(Optional.of("2005"), e.getField("year")); + assertEquals(Optional.of("oezbek"), e.getField("owner")); + assertEquals(Optional.of("2006.05.29"), e.getField("timestamp")); + assertEquals(Optional.of("http://james.howison.name/publications.html"), e.getField("url")); } @Test @@ -550,7 +550,7 @@ public void parseRecognizesFieldValuesInQuotationMarks() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -566,7 +566,7 @@ public void parseRecognizesNumbersWithoutBracketsOrQuotationMarks() throws IOExc assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("2005"), e.getFieldOptional("year")); + assertEquals(Optional.of("2005"), e.getField("year")); } @Test @@ -582,7 +582,7 @@ public void parseRecognizesUppercaseFields() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } /** @@ -602,7 +602,7 @@ public void parseRecognizesAbsoluteFile() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("D:\\Documents\\literature\\Tansel-PRL2006.pdf"), e.getFieldOptional("file")); + assertEquals(Optional.of("D:\\Documents\\literature\\Tansel-PRL2006.pdf"), e.getField("file")); } /** @@ -621,7 +621,7 @@ public void parseRecognizesDateFieldWithConcatenation() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("1-4~#nov#"), e.getFieldOptional("date")); + assertEquals(Optional.of("1-4~#nov#"), e.getField("date")); } @Test @@ -706,7 +706,7 @@ public void parseAddsEscapedOpenBracketToFieldValue() throws IOException { BibEntry e = c.iterator().next(); assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); - assertEquals(Optional.of("escaped \\{ bracket"), e.getFieldOptional("review")); + assertEquals(Optional.of("escaped \\{ bracket"), e.getField("review")); } @Test @@ -723,7 +723,7 @@ public void parseAddsEscapedClosingBracketToFieldValue() throws IOException { BibEntry e = c.iterator().next(); assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); - assertEquals(Optional.of("escaped \\} bracket"), e.getFieldOptional("review")); + assertEquals(Optional.of("escaped \\} bracket"), e.getField("review")); } @Test @@ -785,7 +785,7 @@ public void parseAcceptsEntryWithAtSymbolInBrackets() throws IOException { entries.addAll(c); assertEquals(1, entries.size()); - assertEquals(Optional.of("author @ good"), entries.get(0).getFieldOptional("author")); + assertEquals(Optional.of("author @ good"), entries.get(0).getField("author")); } @Test @@ -801,7 +801,7 @@ public void parseRecognizesEntryWithAtSymbolInQuotationMarks() throws IOExceptio assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("author @ good"), e.getFieldOptional("author")); + assertEquals(Optional.of("author @ good"), e.getField("author")); } @Test @@ -817,7 +817,7 @@ public void parseRecognizesFieldsWithBracketsEnclosedInQuotationMarks() throws I assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Test {Ed {von} Test}"), e.getFieldOptional("author")); + assertEquals(Optional.of("Test {Ed {von} Test}"), e.getField("author")); } @Test @@ -834,7 +834,7 @@ public void parseRecognizesFieldsWithEscapedQuotationMarks() throws IOException assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Test {\" Test}"), e.getFieldOptional("author")); + assertEquals(Optional.of("Test {\" Test}"), e.getField("author")); } @Test @@ -866,7 +866,7 @@ public void parseIgnoresAndWarnsAboutCorruptedEntryButRecognizeOthers() throws I assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } /** @@ -885,8 +885,8 @@ public void parseRecognizesMonthFieldsWithFollowingComma() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(3, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); - assertEquals(Optional.of("8,"), e.getFieldOptional("month")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); + assertEquals(Optional.of("8,"), e.getField("month")); } @Test @@ -1024,12 +1024,12 @@ public void parseRecognizesStringAndEntry() throws IOException { assertEquals("book", e.getType()); assertEquals(Optional.of("bourdieu-2002-questions-sociologie"), e.getCiteKeyOptional()); - assertEquals(Optional.of("Paris"), e.getFieldOptional("address")); - assertEquals(Optional.of("#bourdieu#"), e.getFieldOptional("author")); - assertEquals(Optional.of("2707318256"), e.getFieldOptional("isbn")); - assertEquals(Optional.of("Minuit"), e.getFieldOptional("publisher")); - assertEquals(Optional.of("Questions de sociologie"), e.getFieldOptional("title")); - assertEquals(Optional.of("2002"), e.getFieldOptional("year")); + assertEquals(Optional.of("Paris"), e.getField("address")); + assertEquals(Optional.of("#bourdieu#"), e.getField("author")); + assertEquals(Optional.of("2707318256"), e.getField("isbn")); + assertEquals(Optional.of("Minuit"), e.getField("publisher")); + assertEquals(Optional.of("Questions de sociologie"), e.getField("title")); + assertEquals(Optional.of("2002"), e.getField("year")); } @Test @@ -1071,7 +1071,7 @@ public void parseIgnoresCommentsBeforeEntry() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -1087,7 +1087,7 @@ public void parseIgnoresCommentsAfterEntry() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -1111,7 +1111,7 @@ public void parseIgnoresTextBeforeEntry() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -1127,7 +1127,7 @@ public void parseIgnoresTextAfterEntry() throws IOException { assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); assertEquals(2, e.getFieldNames().size()); - assertEquals(Optional.of("Ed von Test"), e.getFieldOptional("author")); + assertEquals(Optional.of("Ed von Test"), e.getField("author")); } @Test @@ -1138,7 +1138,7 @@ public void parseConvertsNewlineToSpace() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("a b"), e.getFieldOptional("a")); + assertEquals(Optional.of("a b"), e.getField("a")); } @Test @@ -1150,9 +1150,9 @@ public void parseConvertsMultipleNewlinesToSpace() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("a b"), e.getFieldOptional("a")); - assertEquals(Optional.of("a b"), e.getFieldOptional("b")); - assertEquals(Optional.of("a b"), e.getFieldOptional("c")); + assertEquals(Optional.of("a b"), e.getField("a")); + assertEquals(Optional.of("a b"), e.getField("b")); + assertEquals(Optional.of("a b"), e.getField("c")); } @Test @@ -1163,7 +1163,7 @@ public void parseConvertsTabToSpace() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("a b"), e.getFieldOptional("a")); + assertEquals(Optional.of("a b"), e.getField("a")); } @Test @@ -1175,9 +1175,9 @@ public void parseConvertsMultipleTabsToSpace() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("a b"), e.getFieldOptional("a")); - assertEquals(Optional.of("a b"), e.getFieldOptional("b")); - assertEquals(Optional.of("a b"), e.getFieldOptional("c")); + assertEquals(Optional.of("a b"), e.getField("a")); + assertEquals(Optional.of("a b"), e.getField("b")); + assertEquals(Optional.of("a b"), e.getField("c")); } /** @@ -1193,7 +1193,7 @@ public void parsePreservesMultipleSpacesInFileField() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("ups sala"), e.getFieldOptional("file")); + assertEquals(Optional.of("ups sala"), e.getField("file")); } /** @@ -1210,7 +1210,7 @@ public void parseRemovesTabsInFileField() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("ups sala"), e.getFieldOptional("file")); + assertEquals(Optional.of("ups sala"), e.getField("file")); } /** @@ -1227,7 +1227,7 @@ public void parseRemovesNewlineInFileField() throws IOException { Collection c = result.getDatabase().getEntries(); BibEntry e = c.iterator().next(); - assertEquals(Optional.of("ups sala"), e.getFieldOptional("file")); + assertEquals(Optional.of("ups sala"), e.getField("file")); } /** @@ -1246,7 +1246,7 @@ public void parseHandlesAccentsCorrectly() throws IOException { BibEntry e = c.iterator().next(); assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); - assertEquals(Optional.of("H\'{e}lne Fiaux"), e.getFieldOptional("author")); + assertEquals(Optional.of("H\'{e}lne Fiaux"), e.getField("author")); } /** @@ -1268,7 +1268,7 @@ public void parsePreambleAndEntryWithoutNewLine() throws IOException { BibEntry e = c.iterator().next(); assertEquals("article", e.getType()); assertEquals(Optional.of("test"), e.getCiteKeyOptional()); - assertEquals(Optional.of("H\'{e}lne Fiaux"), e.getFieldOptional("author")); + assertEquals(Optional.of("H\'{e}lne Fiaux"), e.getField("author")); } /** @@ -1583,7 +1583,7 @@ public void parsePrecedingComment() throws IOException { assertEquals(5, entry.getFieldNames().size()); Set fields = entry.getFieldNames(); assertTrue(fields.contains("author")); - assertEquals(Optional.of("Foo Bar"), entry.getFieldOptional("author")); + assertEquals(Optional.of("Foo Bar"), entry.getField("author")); assertEquals(bibtexEntry, entry.getParsedSerialization()); } @@ -1609,7 +1609,7 @@ public void parseCommentAndEntryInOneLine() throws IOException { assertEquals(5, entry.getFieldNames().size()); Set fields = entry.getFieldNames(); assertTrue(fields.contains("author")); - assertEquals(Optional.of("Foo Bar"), entry.getFieldOptional("author")); + assertEquals(Optional.of("Foo Bar"), entry.getField("author")); assertEquals(bibtexEntry, entry.getParsedSerialization()); } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java index 2c662a3a894..350ee174890 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java @@ -87,40 +87,40 @@ public void testImportEntries0() throws IOException, URISyntaxException { BibEntry be0 = bibEntries.get(0); assertEquals("misc", be0.getType()); - assertEquals(Optional.of("testA0 and testA1"), be0.getFieldOptional("author")); - assertEquals(Optional.of("testE0 and testE1"), be0.getFieldOptional("editor")); - assertEquals(Optional.of("testT"), be0.getFieldOptional("title")); + assertEquals(Optional.of("testA0 and testA1"), be0.getField("author")); + assertEquals(Optional.of("testE0 and testE1"), be0.getField("editor")); + assertEquals(Optional.of("testT"), be0.getField("title")); BibEntry be1 = bibEntries.get(1); assertEquals("misc", be1.getType()); - assertEquals(Optional.of("testC"), be1.getFieldOptional("address")); - assertEquals(Optional.of("testB2"), be1.getFieldOptional("booktitle")); - assertEquals(Optional.of("test8"), be1.getFieldOptional("date")); - assertEquals(Optional.of("test7"), be1.getFieldOptional("edition")); - assertEquals(Optional.of("testJ"), be1.getFieldOptional("journal")); - assertEquals(Optional.of("testD"), be1.getFieldOptional("year")); + assertEquals(Optional.of("testC"), be1.getField("address")); + assertEquals(Optional.of("testB2"), be1.getField("booktitle")); + assertEquals(Optional.of("test8"), be1.getField("date")); + assertEquals(Optional.of("test7"), be1.getField("edition")); + assertEquals(Optional.of("testJ"), be1.getField("journal")); + assertEquals(Optional.of("testD"), be1.getField("year")); BibEntry be2 = bibEntries.get(2); assertEquals("article", be2.getType()); - assertEquals(Optional.of("testB0"), be2.getFieldOptional("journal")); + assertEquals(Optional.of("testB0"), be2.getField("journal")); BibEntry be3 = bibEntries.get(3); assertEquals("book", be3.getType()); - assertEquals(Optional.of("testI0"), be3.getFieldOptional("publisher")); - assertEquals(Optional.of("testB1"), be3.getFieldOptional("series")); + assertEquals(Optional.of("testI0"), be3.getField("publisher")); + assertEquals(Optional.of("testB1"), be3.getField("series")); BibEntry be4 = bibEntries.get(4); assertEquals("mastersthesis", be4.getType()); - assertEquals(Optional.of("testX"), be4.getFieldOptional("abstract")); - assertEquals(Optional.of("testF"), be4.getFieldOptional("bibtexkey")); - assertEquals(Optional.of("testR"), be4.getFieldOptional("doi")); - assertEquals(Optional.of("testK"), be4.getFieldOptional("keywords")); - assertEquals(Optional.of("testO1"), be4.getFieldOptional("note")); - assertEquals(Optional.of("testN"), be4.getFieldOptional("number")); - assertEquals(Optional.of("testP"), be4.getFieldOptional("pages")); - assertEquals(Optional.of("testI1"), be4.getFieldOptional("school")); - assertEquals(Optional.of("testU"), be4.getFieldOptional("url")); - assertEquals(Optional.of("testV"), be4.getFieldOptional("volume")); + assertEquals(Optional.of("testX"), be4.getField("abstract")); + assertEquals(Optional.of("testF"), be4.getField("bibtexkey")); + assertEquals(Optional.of("testR"), be4.getField("doi")); + assertEquals(Optional.of("testK"), be4.getField("keywords")); + assertEquals(Optional.of("testO1"), be4.getField("note")); + assertEquals(Optional.of("testN"), be4.getField("number")); + assertEquals(Optional.of("testP"), be4.getField("pages")); + assertEquals(Optional.of("testI1"), be4.getField("school")); + assertEquals(Optional.of("testU"), be4.getField("url")); + assertEquals(Optional.of("testV"), be4.getField("volume")); } @Test @@ -133,9 +133,9 @@ public void testImportEntries1() throws IOException { BibEntry be = bibEntries.get(0); assertEquals("misc", be.getType()); - assertEquals(Optional.of("testA"), be.getFieldOptional("author")); - assertEquals(Optional.of("testE0, testE1"), be.getFieldOptional("editor")); - assertEquals(Optional.of("testO"), be.getFieldOptional("pages")); + assertEquals(Optional.of("testA"), be.getField("author")); + assertEquals(Optional.of("testE0, testE1"), be.getField("editor")); + assertEquals(Optional.of("testO"), be.getField("pages")); } @Test @@ -147,15 +147,15 @@ public void testImportEntriesBookExample() throws IOException, URISyntaxExceptio BibEntry be = bibEntries.get(0); assertEquals("book", be.getType()); - assertEquals(Optional.of("Heidelberg"), be.getFieldOptional("address")); - assertEquals(Optional.of("Preißel, René and Stachmann, Bjørn"), be.getFieldOptional("author")); - assertEquals(Optional.of("3., aktualisierte und erweiterte Auflage"), be.getFieldOptional("edition")); - assertEquals(Optional.of("Versionsverwaltung"), be.getFieldOptional("keywords")); - assertEquals(Optional.of("XX, 327"), be.getFieldOptional("pages")); - assertEquals(Optional.of("dpunkt.verlag"), be.getFieldOptional("publisher")); + assertEquals(Optional.of("Heidelberg"), be.getField("address")); + assertEquals(Optional.of("Preißel, René and Stachmann, Bjørn"), be.getField("author")); + assertEquals(Optional.of("3., aktualisierte und erweiterte Auflage"), be.getField("edition")); + assertEquals(Optional.of("Versionsverwaltung"), be.getField("keywords")); + assertEquals(Optional.of("XX, 327"), be.getField("pages")); + assertEquals(Optional.of("dpunkt.verlag"), be.getField("publisher")); assertEquals(Optional.of("Git : dezentrale Versionsverwaltung im Team : Grundlagen und Workflows"), - be.getFieldOptional("title")); - assertEquals(Optional.of("http://d-nb.info/107601965X"), be.getFieldOptional("url")); - assertEquals(Optional.of("2016"), be.getFieldOptional("year")); + be.getField("title")); + assertEquals(Optional.of("http://d-nb.info/107601965X"), be.getField("url")); + assertEquals(Optional.of("2016"), be.getField("year")); } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java index 620d97c5fb1..db29419cd79 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java @@ -131,18 +131,18 @@ public void testImportEntries1() throws IOException, URISyntaxException { assertEquals(1, entries.size()); BibEntry entry = entries.get(0); assertEquals(Optional.of("Optical properties of MgO doped LiNbO$_3$ single crystals"), - entry.getFieldOptional("title")); + entry.getField("title")); assertEquals( Optional.of( "James Brown and James Marc Brown and Brown, J. M. and Brown, J. and Brown, J. M. and Brown, J."), - entry.getFieldOptional("author")); + entry.getField("author")); assertEquals("article", entry.getType()); - assertEquals(Optional.of("Optical Materials"), entry.getFieldOptional("journal")); - assertEquals(Optional.of("2006"), entry.getFieldOptional("year")); - assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); - assertEquals(Optional.of("5"), entry.getFieldOptional("number")); - assertEquals(Optional.of("467--72"), entry.getFieldOptional("pages")); + assertEquals(Optional.of("Optical Materials"), entry.getField("journal")); + assertEquals(Optional.of("2006"), entry.getField("year")); + assertEquals(Optional.of("28"), entry.getField("volume")); + assertEquals(Optional.of("5"), entry.getField("number")); + assertEquals(Optional.of("467--72"), entry.getField("pages")); } @Test @@ -152,14 +152,14 @@ public void testImportEntries2() throws IOException, URISyntaxException { assertEquals(3, entries.size()); BibEntry entry = entries.get(0); assertEquals(Optional.of("Optical properties of MgO doped LiNbO$_3$ single crystals"), - entry.getFieldOptional("title")); + entry.getField("title")); assertEquals("misc", entry.getType()); - assertEquals(Optional.of("Optical Materials"), entry.getFieldOptional("journal")); - assertEquals(Optional.of("2006"), entry.getFieldOptional("year")); - assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); - assertEquals(Optional.of("5"), entry.getFieldOptional("number")); - assertEquals(Optional.of("467-72"), entry.getFieldOptional("pages")); + assertEquals(Optional.of("Optical Materials"), entry.getField("journal")); + assertEquals(Optional.of("2006"), entry.getField("year")); + assertEquals(Optional.of("28"), entry.getField("volume")); + assertEquals(Optional.of("5"), entry.getField("number")); + assertEquals(Optional.of("467-72"), entry.getField("pages")); } @Test @@ -171,7 +171,7 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { BibEntry a = entries.get(0); BibEntry b = entries.get(1); - if (a.getFieldOptional("title").equals( + if (a.getField("title").equals( Optional.of("Optical and photoelectric spectroscopy of photorefractive Sn$_2$P$_2$S$_6$ crystals"))) { BibEntry tmp = a; a = b; @@ -181,22 +181,22 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { assertEquals( Optional.of( "Second harmonic generation of continuous wave ultraviolet light and production of beta -BaB$_2$O$_4$ optical waveguides"), - a.getFieldOptional("title")); + a.getField("title")); assertEquals("article", a.getType()); assertEquals(Optional.of("Degl'Innocenti, R. and Guarino, A. and Poberaj, G. and Gunter, P."), - a.getFieldOptional("author")); - assertEquals(Optional.of("Applied Physics Letters"), a.getFieldOptional("journal")); - assertEquals(Optional.of("2006"), a.getFieldOptional("year")); - assertEquals(Optional.of("#jul#"), a.getFieldOptional("month")); - assertEquals(Optional.of("89"), a.getFieldOptional("volume")); - assertEquals(Optional.of("4"), a.getFieldOptional("number")); - assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); - assertEquals(Optional.of("Aip"), a.getFieldOptional("publisher")); + a.getField("author")); + assertEquals(Optional.of("Applied Physics Letters"), a.getField("journal")); + assertEquals(Optional.of("2006"), a.getField("year")); + assertEquals(Optional.of("#jul#"), a.getField("month")); + assertEquals(Optional.of("89"), a.getField("volume")); + assertEquals(Optional.of("4"), a.getField("number")); + assertEquals(Optional.of("Lorem ipsum abstract"), a.getField("abstract")); + assertEquals(Optional.of("Aip"), a.getField("publisher")); assertEquals( Optional.of("Optical and photoelectric spectroscopy of photorefractive Sn$_2$P$_2$S$_6$ crystals"), - b.getFieldOptional("title")); + b.getField("title")); assertEquals("article", b.getType()); } @@ -210,11 +210,11 @@ public void testImportEntriesWOS() throws IOException, URISyntaxException { BibEntry b = entries.get(1); assertEquals(Optional.of("Optical and photoelectric spectroscopy of photorefractive Sn2P2S6 crystals"), - a.getFieldOptional("title")); + a.getField("title")); assertEquals(Optional.of("Optical waveguides in Sn2P2S6 by low fluence MeV He+ ion implantation"), - b.getFieldOptional("title")); + b.getField("title")); - assertEquals(Optional.of("Journal of Physics-condensed Matter"), a.getFieldOptional("journal")); + assertEquals(Optional.of("Journal of Physics-condensed Matter"), a.getField("journal")); } @Test @@ -265,19 +265,19 @@ public void testImportIEEEExport() throws IOException, URISyntaxException { assertEquals(1, entries.size()); BibEntry a = entries.get(0); assertEquals("article", a.getType()); - assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getFieldOptional("journal")); + assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getField("journal")); assertEquals(Optional.of("Improving Urban Road Extraction in High-Resolution " + "Images Exploiting Directional Filtering, Perceptual " + "Grouping, and Simple Topological Concepts"), - a.getFieldOptional("title")); - assertEquals(Optional.of("4"), a.getFieldOptional("volume")); - assertEquals(Optional.of("3"), a.getFieldOptional("number")); - assertEquals(Optional.of("1545-598X"), a.getFieldOptional("SN")); - assertEquals(Optional.of("387--391"), a.getFieldOptional("pages")); - assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getFieldOptional("author")); - assertEquals(Optional.of("2006"), a.getFieldOptional("year")); + a.getField("title")); + assertEquals(Optional.of("4"), a.getField("volume")); + assertEquals(Optional.of("3"), a.getField("number")); + assertEquals(Optional.of("1545-598X"), a.getField("SN")); + assertEquals(Optional.of("387--391"), a.getField("pages")); + assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getField("author")); + assertEquals(Optional.of("2006"), a.getField("year")); assertEquals(Optional.of("Perceptual grouping, street extraction, urban remote sensing"), - a.getFieldOptional("keywords")); - assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); + a.getField("keywords")); + assertEquals(Optional.of("Lorem ipsum abstract"), a.getField("abstract")); } @Test @@ -289,20 +289,20 @@ public void testIEEEImport() throws IOException, URISyntaxException { BibEntry a = entries.get(0); assertEquals("article", a.getType()); - assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getFieldOptional("journal")); + assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getField("journal")); assertEquals( Optional.of( "Improving Urban Road Extraction in High-Resolution Images Exploiting Directional Filtering, Perceptual Grouping, and Simple Topological Concepts"), - a.getFieldOptional("title")); - assertEquals(Optional.of("4"), a.getFieldOptional("volume")); - assertEquals(Optional.of("3"), a.getFieldOptional("number")); - assertEquals(Optional.of("1545-598X"), a.getFieldOptional("SN")); - assertEquals(Optional.of("387--391"), a.getFieldOptional("pages")); - assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getFieldOptional("author")); - assertEquals(Optional.of("2006"), a.getFieldOptional("year")); + a.getField("title")); + assertEquals(Optional.of("4"), a.getField("volume")); + assertEquals(Optional.of("3"), a.getField("number")); + assertEquals(Optional.of("1545-598X"), a.getField("SN")); + assertEquals(Optional.of("387--391"), a.getField("pages")); + assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getField("author")); + assertEquals(Optional.of("2006"), a.getField("year")); assertEquals(Optional.of("Perceptual grouping, street extraction, urban remote sensing"), - a.getFieldOptional("keywords")); - assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); + a.getField("keywords")); + assertEquals(Optional.of("Lorem ipsum abstract"), a.getField("abstract")); } @Test @@ -317,30 +317,30 @@ public void testImportEntriesMedline() throws IOException, URISyntaxException { assertEquals( Optional.of("Effects of modafinil on cognitive performance and alertness during sleep deprivation."), - a.getFieldOptional("title")); - - assertEquals(Optional.of("Wesensten, Nancy J."), a.getFieldOptional("author")); - assertEquals(Optional.of("Curr Pharm Des"), a.getFieldOptional("journal")); - assertEquals(Optional.of("2006"), a.getFieldOptional("year")); - assertEquals(Optional.empty(), a.getFieldOptional("month")); - assertEquals(Optional.of("12"), a.getFieldOptional("volume")); - assertEquals(Optional.of("20"), a.getFieldOptional("number")); - assertEquals(Optional.of("2457--71"), a.getFieldOptional("pages")); + a.getField("title")); + + assertEquals(Optional.of("Wesensten, Nancy J."), a.getField("author")); + assertEquals(Optional.of("Curr Pharm Des"), a.getField("journal")); + assertEquals(Optional.of("2006"), a.getField("year")); + assertEquals(Optional.empty(), a.getField("month")); + assertEquals(Optional.of("12"), a.getField("volume")); + assertEquals(Optional.of("20"), a.getField("number")); + assertEquals(Optional.of("2457--71"), a.getField("pages")); assertEquals("article", a.getType()); assertEquals( Optional.of( "Estrogen therapy selectively enhances prefrontal cognitive processes: a randomized, double-blind, placebo-controlled study with functional magnetic resonance imaging in perimenopausal and recently postmenopausal women."), - b.getFieldOptional("title")); + b.getField("title")); assertEquals( Optional.of( "Joffe, Hadine and Hall, Janet E. and Gruber, Staci and Sarmiento, Ingrid A. and Cohen, Lee S. and Yurgelun-Todd, Deborah and Martin, Kathryn A."), - b.getFieldOptional("author")); - assertEquals(Optional.of("2006"), b.getFieldOptional("year")); - assertEquals(Optional.of("#may#"), b.getFieldOptional("month")); - assertEquals(Optional.of("13"), b.getFieldOptional("volume")); - assertEquals(Optional.of("3"), b.getFieldOptional("number")); - assertEquals(Optional.of("411--22"), b.getFieldOptional("pages")); + b.getField("author")); + assertEquals(Optional.of("2006"), b.getField("year")); + assertEquals(Optional.of("#may#"), b.getField("month")); + assertEquals(Optional.of("13"), b.getField("volume")); + assertEquals(Optional.of("3"), b.getField("number")); + assertEquals(Optional.of("411--22"), b.getField("pages")); assertEquals("article", b.getType()); } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java index b9da2622e86..62566e9ab2c 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java @@ -87,33 +87,33 @@ public void testImportMultipleEntriesInSingleFile() throws IOException, URISynta BibEntry testEntry = entries.get(0); assertEquals("article", testEntry.getType()); - assertEquals(Optional.empty(), testEntry.getFieldOptional("month")); - assertEquals(Optional.of("Long, Vicky and Marland, Hilary"), testEntry.getFieldOptional("author")); + assertEquals(Optional.empty(), testEntry.getField("month")); + assertEquals(Optional.of("Long, Vicky and Marland, Hilary"), testEntry.getField("author")); assertEquals( Optional.of( "From danger and motherhood to health and beauty: health advice for the factory girl in early twentieth-century Britain."), - testEntry.getFieldOptional("title")); + testEntry.getField("title")); testEntry = entries.get(1); assertEquals("conference", testEntry.getType()); - assertEquals(Optional.of("06"), testEntry.getFieldOptional("month")); - assertEquals(Optional.empty(), testEntry.getFieldOptional("author")); - assertEquals(Optional.empty(), testEntry.getFieldOptional("title")); + assertEquals(Optional.of("06"), testEntry.getField("month")); + assertEquals(Optional.empty(), testEntry.getField("author")); + assertEquals(Optional.empty(), testEntry.getField("title")); testEntry = entries.get(2); assertEquals("book", testEntry.getType()); assertEquals( Optional.of( "This is a Testtitle: This title should be appended: This title should also be appended. Another append to the Title? LastTitle"), - testEntry.getFieldOptional("title")); + testEntry.getField("title")); testEntry = entries.get(3); assertEquals("techreport", testEntry.getType()); - Assert.assertTrue(testEntry.getFieldOptional("doi").isPresent()); + Assert.assertTrue(testEntry.getField("doi").isPresent()); testEntry = entries.get(4); assertEquals("inproceedings", testEntry.getType()); - assertEquals(Optional.of("Inproceedings book title"), testEntry.getFieldOptional("booktitle")); + assertEquals(Optional.of("Inproceedings book title"), testEntry.getField("booktitle")); BibEntry expectedEntry5 = new BibEntry(); expectedEntry5.setType("proceedings"); diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java index b09ea2cb361..9d31df60849 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java @@ -87,49 +87,49 @@ public void testImportEntries1() throws IOException, URISyntaxException { BibEntry entry = entries.get(0); Assert.assertEquals("misc", entry.getType()); - Assert.assertEquals(Optional.of("Mustermann and Musterfrau"), entry.getFieldOptional("author")); - Assert.assertEquals(Optional.of("Short abstract"), entry.getFieldOptional("abstract")); - Assert.assertEquals(Optional.of("Musterbuch"), entry.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Einleitung"), entry.getFieldOptional("chaptertitle")); + Assert.assertEquals(Optional.of("Mustermann and Musterfrau"), entry.getField("author")); + Assert.assertEquals(Optional.of("Short abstract"), entry.getField("abstract")); + Assert.assertEquals(Optional.of("Musterbuch"), entry.getField("title")); + Assert.assertEquals(Optional.of("Einleitung"), entry.getField("chaptertitle")); entry = entries.get(1); Assert.assertEquals("inproceedings", entry.getType()); - Assert.assertEquals(Optional.of("Max"), entry.getFieldOptional("editor")); - Assert.assertEquals(Optional.of("Max the Editor"), entry.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Very Long Title"), entry.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("2"), entry.getFieldOptional("issue")); - Assert.assertEquals(Optional.of("2015"), entry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("103--106"), entry.getFieldOptional("pages")); + Assert.assertEquals(Optional.of("Max"), entry.getField("editor")); + Assert.assertEquals(Optional.of("Max the Editor"), entry.getField("title")); + Assert.assertEquals(Optional.of("Very Long Title"), entry.getField("journal")); + Assert.assertEquals(Optional.of("28"), entry.getField("volume")); + Assert.assertEquals(Optional.of("2"), entry.getField("issue")); + Assert.assertEquals(Optional.of("2015"), entry.getField("year")); + Assert.assertEquals(Optional.of("103--106"), entry.getField("pages")); entry = entries.get(2); Assert.assertEquals("incollection", entry.getType()); - Assert.assertEquals(Optional.of("Max"), entry.getFieldOptional("author")); - Assert.assertEquals(Optional.of("Test"), entry.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Very Long Title"), entry.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("2"), entry.getFieldOptional("issue")); - Assert.assertEquals(Optional.of("April"), entry.getFieldOptional("month")); - Assert.assertEquals(Optional.of("2015"), entry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("103--106"), entry.getFieldOptional("pages")); + Assert.assertEquals(Optional.of("Max"), entry.getField("author")); + Assert.assertEquals(Optional.of("Test"), entry.getField("title")); + Assert.assertEquals(Optional.of("Very Long Title"), entry.getField("journal")); + Assert.assertEquals(Optional.of("28"), entry.getField("volume")); + Assert.assertEquals(Optional.of("2"), entry.getField("issue")); + Assert.assertEquals(Optional.of("April"), entry.getField("month")); + Assert.assertEquals(Optional.of("2015"), entry.getField("year")); + Assert.assertEquals(Optional.of("103--106"), entry.getField("pages")); entry = entries.get(3); Assert.assertEquals("book", entry.getType()); - Assert.assertEquals(Optional.of("Max"), entry.getFieldOptional("author")); - Assert.assertEquals(Optional.of("2015"), entry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("Editor"), entry.getFieldOptional("editor")); - Assert.assertEquals(Optional.of("Very Long Title"), entry.getFieldOptional("booktitle")); - Assert.assertEquals(Optional.of("103--106"), entry.getFieldOptional("pages")); - Assert.assertEquals(Optional.of("Address"), entry.getFieldOptional("address")); - Assert.assertEquals(Optional.of("Publisher"), entry.getFieldOptional("publisher")); + Assert.assertEquals(Optional.of("Max"), entry.getField("author")); + Assert.assertEquals(Optional.of("2015"), entry.getField("year")); + Assert.assertEquals(Optional.of("Editor"), entry.getField("editor")); + Assert.assertEquals(Optional.of("Very Long Title"), entry.getField("booktitle")); + Assert.assertEquals(Optional.of("103--106"), entry.getField("pages")); + Assert.assertEquals(Optional.of("Address"), entry.getField("address")); + Assert.assertEquals(Optional.of("Publisher"), entry.getField("publisher")); entry = entries.get(4); Assert.assertEquals("article", entry.getType()); - Assert.assertEquals(Optional.of("2014"), entry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("58"), entry.getFieldOptional("pages")); - Assert.assertEquals(Optional.of("Test"), entry.getFieldOptional("address")); - Assert.assertEquals(Optional.empty(), entry.getFieldOptional("title")); - Assert.assertEquals(Optional.of("TestPublisher"), entry.getFieldOptional("publisher")); + Assert.assertEquals(Optional.of("2014"), entry.getField("year")); + Assert.assertEquals(Optional.of("58"), entry.getField("pages")); + Assert.assertEquals(Optional.of("Test"), entry.getField("address")); + Assert.assertEquals(Optional.empty(), entry.getField("title")); + Assert.assertEquals(Optional.of("TestPublisher"), entry.getField("publisher")); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java index 4f98fd45af3..eb5eea37ddc 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java @@ -62,10 +62,10 @@ public void testImportEntries() throws URISyntaxException { assertEquals(1, bibEntries.size()); BibEntry be0 = bibEntries.get(0); - assertEquals(Optional.of("how to annotate a pdf"), be0.getFieldOptional("abstract")); - assertEquals(Optional.of("Chris"), be0.getFieldOptional("author")); - assertEquals(Optional.of("pdf, annotation"), be0.getFieldOptional("keywords")); - assertEquals(Optional.of("The best Pdf ever"), be0.getFieldOptional("title")); + assertEquals(Optional.of("how to annotate a pdf"), be0.getField("abstract")); + assertEquals(Optional.of("Chris"), be0.getField("author")); + assertEquals(Optional.of("pdf, annotation"), be0.getField("keywords")); + assertEquals(Optional.of("The best Pdf ever"), be0.getField("title")); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/util/JSONEntryParserTest.java b/src/test/java/net/sf/jabref/logic/importer/util/JSONEntryParserTest.java index 796d54f9026..ca82239e513 100644 --- a/src/test/java/net/sf/jabref/logic/importer/util/JSONEntryParserTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/util/JSONEntryParserTest.java @@ -28,14 +28,14 @@ public void testBibJSONConverter() { BibEntry bibEntry = jc.parseBibJSONtoBibtex(jsonObject, ", "); Assert.assertEquals("article", bibEntry.getType()); - Assert.assertEquals(Optional.of("VLSI Design"), bibEntry.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("10.1155/2014/217495"), bibEntry.getFieldOptional("doi")); - Assert.assertEquals(Optional.of("Syed Asad Alam and Oscar Gustafsson"), bibEntry.getFieldOptional("author")); + Assert.assertEquals(Optional.of("VLSI Design"), bibEntry.getField("journal")); + Assert.assertEquals(Optional.of("10.1155/2014/217495"), bibEntry.getField("doi")); + Assert.assertEquals(Optional.of("Syed Asad Alam and Oscar Gustafsson"), bibEntry.getField("author")); Assert.assertEquals( Optional.of( "Design of Finite Word Length Linear-Phase FIR Filters in the Logarithmic Number System Domain"), - bibEntry.getFieldOptional("title")); - Assert.assertEquals(Optional.of("2014"), bibEntry.getFieldOptional("year")); + bibEntry.getField("title")); + Assert.assertEquals(Optional.of("2014"), bibEntry.getField("year")); } @Test @@ -52,13 +52,13 @@ public void testSpringerJSONToBibtex() { JSONObject jsonObject = new JSONObject(jsonString); BibEntry bibEntry = JSONEntryParser.parseSpringerJSONtoBibtex(jsonObject); - Assert.assertEquals(Optional.of("1992"), bibEntry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("5"), bibEntry.getFieldOptional("number")); - Assert.assertEquals(Optional.of("#sep#"), bibEntry.getFieldOptional("month")); - Assert.assertEquals(Optional.of("10.1007/BF01201962"), bibEntry.getFieldOptional("doi")); - Assert.assertEquals(Optional.of("8"), bibEntry.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("Springer"), bibEntry.getFieldOptional("publisher")); - Assert.assertEquals(Optional.of("1992-09-01"), bibEntry.getFieldOptional("date")); + Assert.assertEquals(Optional.of("1992"), bibEntry.getField("year")); + Assert.assertEquals(Optional.of("5"), bibEntry.getField("number")); + Assert.assertEquals(Optional.of("#sep#"), bibEntry.getField("month")); + Assert.assertEquals(Optional.of("10.1007/BF01201962"), bibEntry.getField("doi")); + Assert.assertEquals(Optional.of("8"), bibEntry.getField("volume")); + Assert.assertEquals(Optional.of("Springer"), bibEntry.getField("publisher")); + Assert.assertEquals(Optional.of("1992-09-01"), bibEntry.getField("date")); } } diff --git a/src/test/java/net/sf/jabref/logic/util/UpdateFieldTest.java b/src/test/java/net/sf/jabref/logic/util/UpdateFieldTest.java index abe04bc1842..1c0b095b48f 100644 --- a/src/test/java/net/sf/jabref/logic/util/UpdateFieldTest.java +++ b/src/test/java/net/sf/jabref/logic/util/UpdateFieldTest.java @@ -29,14 +29,14 @@ public void setUp() throws Exception { public void testUpdateFieldWorksEmptyField() { assertFalse(entry.hasField("year")); UpdateField.updateField(entry, "year", "2016"); - assertEquals(Optional.of("2016"), entry.getFieldOptional("year")); + assertEquals(Optional.of("2016"), entry.getField("year")); } @Test public void testUpdateFieldWorksNonEmptyField() { entry.setField("year", "2015"); UpdateField.updateField(entry, "year", "2016"); - assertEquals(Optional.of("2016"), entry.getFieldOptional("year")); + assertEquals(Optional.of("2016"), entry.getField("year")); } @Test @@ -159,7 +159,7 @@ public void testUpdateNonDisplayableFieldUpdates() { assertFalse(entry.hasField("year")); UpdateField.updateNonDisplayableField(entry, "year", "2016"); assertTrue(entry.hasField("year")); - assertEquals(Optional.of("2016"), entry.getFieldOptional("year")); + assertEquals(Optional.of("2016"), entry.getField("year")); } @Test diff --git a/src/test/java/net/sf/jabref/logic/xmp/XMPSchemaBibtexTest.java b/src/test/java/net/sf/jabref/logic/xmp/XMPSchemaBibtexTest.java index 839734dbcc2..e6522c9add9 100644 --- a/src/test/java/net/sf/jabref/logic/xmp/XMPSchemaBibtexTest.java +++ b/src/test/java/net/sf/jabref/logic/xmp/XMPSchemaBibtexTest.java @@ -43,7 +43,7 @@ public void assertEqualsBibtexEntry(BibEntry e, BibEntry x) { Assert.assertEquals(e.getFieldNames().size(), x.getFieldNames().size()); for (String name : e.getFieldNames()) { - Assert.assertEquals(e.getFieldOptional(name), x.getFieldOptional(name)); + Assert.assertEquals(e.getField(name), x.getField(name)); } } diff --git a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java index f52ebbe70d8..33c627f8cc6 100644 --- a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java @@ -279,9 +279,9 @@ public void testReadXMPSimple() throws COSVisitorException, IOException { Assert.assertNotNull(e); Assert.assertEquals(Optional.of("OezbekC06"), e.getCiteKeyOptional()); - Assert.assertEquals(Optional.of("2003"), e.getFieldOptional("year")); + Assert.assertEquals(Optional.of("2003"), e.getField("year")); Assert.assertEquals(Optional.of("Beach sand convolution by surf-wave optimzation"), - e.getFieldOptional("title")); + e.getField("title")); Assert.assertEquals("misc", e.getType()); } @@ -304,8 +304,8 @@ public void testReadXMPUTF8() throws COSVisitorException, IOException { Assert.assertNotNull(e); Assert.assertEquals(Optional.of("OezbekC06"), e.getCiteKeyOptional()); - Assert.assertEquals(Optional.of("2003"), e.getFieldOptional("year")); - Assert.assertEquals(Optional.of("�pt�mz�t��n"), e.getFieldOptional("title")); + Assert.assertEquals(Optional.of("2003"), e.getField("year")); + Assert.assertEquals(Optional.of("�pt�mz�t��n"), e.getField("title")); Assert.assertEquals("misc", e.getType()); } @@ -378,8 +378,8 @@ public void testReadXMPSeq() throws COSVisitorException, IOException { Assert.assertNotNull(e); Assert.assertEquals(Optional.of("Clarkson06"), e.getCiteKeyOptional()); - Assert.assertEquals("Kelly Clarkson and Ozzy Osbourne", e.getFieldOptional("author").get()); - Assert.assertEquals("Huey Duck and Dewey Duck and Louie Duck", e.getFieldOptional("editor").get()); + Assert.assertEquals("Kelly Clarkson and Ozzy Osbourne", e.getField("author").get()); + Assert.assertEquals("Huey Duck and Dewey Duck and Louie Duck", e.getField("editor").get()); Assert.assertEquals("misc", e.getType()); } @@ -499,9 +499,9 @@ public void testNewlineHandling() throws COSVisitorException, IOException { BibEntry e = l.get(0); Assert.assertNotNull(e); - Assert.assertEquals("Hallo World this is not an exercise .", e.getFieldOptional("title").get()); - Assert.assertEquals("Hallo World this is not an exercise .", e.getFieldOptional("tabs").get()); - Assert.assertEquals("\n\nAbstract preserve\n\t Whitespace\n\n", e.getFieldOptional("abstract").get()); + Assert.assertEquals("Hallo World this is not an exercise .", e.getField("title").get()); + Assert.assertEquals("Hallo World this is not an exercise .", e.getField("tabs").get()); + Assert.assertEquals("\n\nAbstract preserve\n\t Whitespace\n\n", e.getField("abstract").get()); } /** @@ -767,12 +767,12 @@ public void assertEqualsBibtexEntry(BibEntry expected, BibEntry actual) { if ("author".equalsIgnoreCase(field) || "editor".equalsIgnoreCase(field)) { - AuthorList expectedAuthors = AuthorList.parse(expected.getFieldOptional(field).get()); - AuthorList actualAuthors = AuthorList.parse(actual.getFieldOptional(field).get()); + AuthorList expectedAuthors = AuthorList.parse(expected.getField(field).get()); + AuthorList actualAuthors = AuthorList.parse(actual.getField(field).get()); Assert.assertEquals(expectedAuthors, actualAuthors); } else { - Assert.assertEquals("comparing " + field, expected.getFieldOptional(field), - actual.getFieldOptional(field)); + Assert.assertEquals("comparing " + field, expected.getField(field), + actual.getField(field)); } } @@ -825,12 +825,12 @@ public void testXMPreadString() throws Exception { } Assert.assertEquals(Optional.of("canh05"), a.getCiteKeyOptional()); - Assert.assertEquals("K. Crowston and H. Annabi", a.getFieldOptional("author").get()); - Assert.assertEquals("Title A", a.getFieldOptional("title").get()); + Assert.assertEquals("K. Crowston and H. Annabi", a.getField("author").get()); + Assert.assertEquals("Title A", a.getField("title").get()); Assert.assertEquals("article", a.getType()); Assert.assertEquals(Optional.of("foo"), b.getCiteKeyOptional()); - Assert.assertEquals("Norton Bar", b.getFieldOptional("author").get()); + Assert.assertEquals("Norton Bar", b.getField("author").get()); Assert.assertEquals("inproceedings", b.getType()); } @@ -1334,7 +1334,7 @@ public void testResolveStrings() throws IOException, TransformerException { BibEntry x = l.get(0); Assert.assertEquals(AuthorList.parse("Crowston, K. and Annabi, H. and Howison, J. and Masango, C."), - AuthorList.parse(x.getFieldOptional("author").get())); + AuthorList.parse(x.getField("author").get())); } @Test(expected = EncryptedPdfsNotSupportedException.class) @@ -1377,7 +1377,7 @@ public void testResolveStrings2() throws IOException, TransformerException { // Test whether we the main function can load the bibtex correctly BibEntry b = XMPUtil.readXMP(pdfFile, xmpPreferences).get(0); Assert.assertNotNull(b); - Assert.assertEquals(originalAuthors, AuthorList.parse(b.getFieldOptional("author").get())); + Assert.assertEquals(originalAuthors, AuthorList.parse(b.getField("author").get())); // Next check from Document Information try (PDDocument document = PDDocument.load(pdfFile.getAbsoluteFile())) { @@ -1386,7 +1386,7 @@ public void testResolveStrings2() throws IOException, TransformerException { AuthorList.parse(document.getDocumentInformation().getAuthor())); b = XMPUtil.getBibtexEntryFromDocumentInformation(document.getDocumentInformation()).get(); - Assert.assertEquals(originalAuthors, AuthorList.parse(b.getFieldOptional("author").get())); + Assert.assertEquals(originalAuthors, AuthorList.parse(b.getField("author").get())); // Now check from Dublin Core PDDocumentCatalog catalog = document.getDocumentCatalog(); @@ -1412,7 +1412,7 @@ public void testResolveStrings2() throws IOException, TransformerException { b = XMPUtil.getBibtexEntryFromDublinCore(dcSchema, xmpPreferences).get(); Assert.assertNotNull(b); - Assert.assertEquals(originalAuthors, AuthorList.parse(b.getFieldOptional("author").get())); + Assert.assertEquals(originalAuthors, AuthorList.parse(b.getField("author").get())); } } finally { if (!pdfFile.delete()) { diff --git a/src/test/java/net/sf/jabref/model/database/KeyChangeListenerTest.java b/src/test/java/net/sf/jabref/model/database/KeyChangeListenerTest.java index 976a9a601c3..d6e4de5947a 100644 --- a/src/test/java/net/sf/jabref/model/database/KeyChangeListenerTest.java +++ b/src/test/java/net/sf/jabref/model/database/KeyChangeListenerTest.java @@ -46,48 +46,48 @@ public void setUp() { @Test public void testCrossrefChanged() { - assertEquals(Optional.of("Entry4"), entry1.getFieldOptional("crossref")); + assertEquals(Optional.of("Entry4"), entry1.getField("crossref")); entry4.setCiteKey("Banana"); - assertEquals(Optional.of("Banana"), entry1.getFieldOptional("crossref")); + assertEquals(Optional.of("Banana"), entry1.getField("crossref")); } @Test public void testRelatedChanged() { - assertEquals(Optional.of("Entry1,Entry3"), entry2.getFieldOptional("related")); + assertEquals(Optional.of("Entry1,Entry3"), entry2.getField("related")); entry1.setCiteKey("Banana"); - assertEquals(Optional.of("Banana,Entry3"), entry2.getFieldOptional("related")); + assertEquals(Optional.of("Banana,Entry3"), entry2.getField("related")); } @Test public void testRelatedChangedInSameEntry() { - assertEquals(Optional.of("Entry1,Entry2,Entry3"), entry3.getFieldOptional("related")); + assertEquals(Optional.of("Entry1,Entry2,Entry3"), entry3.getField("related")); entry3.setCiteKey("Banana"); - assertEquals(Optional.of("Entry1,Entry2,Banana"), entry3.getFieldOptional("related")); + assertEquals(Optional.of("Entry1,Entry2,Banana"), entry3.getField("related")); } @Test public void testCrossrefRemoved() { entry4.clearField(BibEntry.KEY_FIELD); - assertEquals(Optional.empty(), entry1.getFieldOptional("crossref")); + assertEquals(Optional.empty(), entry1.getField("crossref")); } @Test public void testCrossrefEntryRemoved() { db.removeEntry(entry4); - assertEquals(Optional.empty(), entry1.getFieldOptional("crossref")); + assertEquals(Optional.empty(), entry1.getField("crossref")); } @Test public void testRelatedEntryRemoved() { db.removeEntry(entry1); - assertEquals(Optional.of("Entry3"), entry2.getFieldOptional("related")); + assertEquals(Optional.of("Entry3"), entry2.getField("related")); } @Test public void testRelatedAllEntriesRemoved() { db.removeEntry(entry1); db.removeEntry(entry3); - assertEquals(Optional.empty(), entry2.getFieldOptional("related")); + assertEquals(Optional.empty(), entry2.getField("related")); } } diff --git a/src/test/java/net/sf/jabref/model/entry/BibEntryTest.java b/src/test/java/net/sf/jabref/model/entry/BibEntryTest.java index d89ee609e47..8d03d79baeb 100644 --- a/src/test/java/net/sf/jabref/model/entry/BibEntryTest.java +++ b/src/test/java/net/sf/jabref/model/entry/BibEntryTest.java @@ -34,6 +34,6 @@ public void notClearReservedFields() { public void getFieldIsCaseInsensitive() throws Exception { entry.setField("TeSt", "value"); - Assert.assertEquals(Optional.of("value"), entry.getFieldOptional("tEsT")); + Assert.assertEquals(Optional.of("value"), entry.getField("tEsT")); } } diff --git a/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java b/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java index 64257d65e49..3b8ec54a781 100644 --- a/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java +++ b/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java @@ -41,7 +41,7 @@ public void testDefaultConstructor() { // we have to use `getType("misc")` in the case of biblatex mode Assert.assertEquals("misc", entry.getType()); Assert.assertNotNull(entry.getId()); - Assert.assertFalse(entry.getFieldOptional("author").isPresent()); + Assert.assertFalse(entry.getField("author").isPresent()); } @Test @@ -364,9 +364,9 @@ public void testCiteKeyAndID() { be.setCiteKey("Einstein1931"); Assert.assertTrue(be.hasCiteKey()); Assert.assertEquals(Optional.of("Einstein1931"), be.getCiteKeyOptional()); - Assert.assertEquals(Optional.of("Albert Einstein"), be.getFieldOptional("author")); + Assert.assertEquals(Optional.of("Albert Einstein"), be.getField("author")); be.clearField("author"); - Assert.assertEquals(Optional.empty(), be.getFieldOptional("author")); + Assert.assertEquals(Optional.empty(), be.getField("author")); String id = IdGenerator.next(); be.setId(id); diff --git a/src/test/java/net/sf/jabref/specialfields/SpecialFieldsUtilsTest.java b/src/test/java/net/sf/jabref/specialfields/SpecialFieldsUtilsTest.java index b08a501cbfa..0fb364fb34f 100644 --- a/src/test/java/net/sf/jabref/specialfields/SpecialFieldsUtilsTest.java +++ b/src/test/java/net/sf/jabref/specialfields/SpecialFieldsUtilsTest.java @@ -27,7 +27,7 @@ public void testSyncKeywordsFromSpecialFieldsBibEntry() { BibEntry entry = new BibEntry(); entry.setField("ranking", "rank2"); SpecialFieldsUtils.syncKeywordsFromSpecialFields(entry); - assertEquals(Optional.of("rank2"), entry.getFieldOptional("keywords")); + assertEquals(Optional.of("rank2"), entry.getField("keywords")); } @Test @@ -45,7 +45,7 @@ public void testSyncKeywordsFromSpecialFieldsBibEntryExisitingKeyword() { entry.setField("ranking", "rank2"); entry.setField("keywords", "rank3"); SpecialFieldsUtils.syncKeywordsFromSpecialFields(entry); - assertEquals(Optional.of("rank2"), entry.getFieldOptional("keywords")); + assertEquals(Optional.of("rank2"), entry.getField("keywords")); } @Test @@ -54,7 +54,7 @@ public void testSyncKeywordsFromSpecialFieldsBibEntryNamedCompoundCorrectContent NamedCompound nc = new NamedCompound("Test"); entry.setField("ranking", "rank2"); SpecialFieldsUtils.syncKeywordsFromSpecialFields(entry, nc); - assertEquals(Optional.of("rank2"), entry.getFieldOptional("keywords")); + assertEquals(Optional.of("rank2"), entry.getField("keywords")); } @Test @@ -70,7 +70,7 @@ public void testSyncSpecialFieldsFromKeywordsBibEntry() { BibEntry entry = new BibEntry(); entry.setField("keywords", "rank2"); SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry); - assertEquals(Optional.of("rank2"), entry.getFieldOptional("ranking")); + assertEquals(Optional.of("rank2"), entry.getField("ranking")); } @Test @@ -88,7 +88,7 @@ public void testSyncSpecialFieldsFromKeywordsBibEntryNamedCompoundCorrectContent NamedCompound nc = new NamedCompound("Test"); entry.setField("keywords", "rank2"); SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, nc); - assertEquals(Optional.of("rank2"), entry.getFieldOptional("ranking")); + assertEquals(Optional.of("rank2"), entry.getField("ranking")); } @Test