Skip to content

Commit

Permalink
Fixed some minor things and removed the final BibEntry.getField() (#1870
Browse files Browse the repository at this point in the history
)
  • Loading branch information
oscargus authored Aug 27, 2016
1 parent 55fe381 commit 4e0ff50
Show file tree
Hide file tree
Showing 126 changed files with 672 additions and 682 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public void testFieldChangedEventListener() {

List<BibEntry> 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());

}

Expand Down Expand Up @@ -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());

}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/sf/jabref/cli/CrossrefFetcherEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibEntry> entries = db.getEntries();

AtomicInteger dois = new AtomicInteger();
AtomicInteger doiFound = new AtomicInteger();
AtomicInteger doiNew = new AtomicInteger();
AtomicInteger doiIdentical = new AtomicInteger();

List<BibEntry> entries = db.getEntries();
CountDownLatch countDownLatch = new CountDownLatch(entries.size());
int total = entries.size();

CountDownLatch countDownLatch = new CountDownLatch(total);

ExecutorService executorService = Executors.newFixedThreadPool(5);

Expand All @@ -48,7 +49,7 @@ public static void main(String[] args) throws IOException, InterruptedException

@Override
public void run() {
Optional<DOI> origDOI = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build);
Optional<DOI> origDOI = entry.getField(FieldName.DOI).flatMap(DOI::build);
if (origDOI.isPresent()) {
dois.incrementAndGet();
Optional<DOI> crossrefDOI = CrossRef.findDOI(entry);
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/net/sf/jabref/collab/EntryChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> mem = memEntry.getField(field);
Optional<String> tmp = tmpEntry.getField(field);
Optional<String> 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)));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/external/AttachFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/external/AutoSetLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void run() {
// Iterate over the entries:
for (Entry<BibEntry, List<File>> entryFilePair : result.entrySet()) {
FileListTableModel tableModel;
Optional<String> oldVal = entryFilePair.getKey().getFieldOptional(FieldName.FILE);
Optional<String> oldVal = entryFilePair.getKey().getField(FieldName.FILE);
if (singleTableModel == null) {
tableModel = new FileListTableModel();
oldVal.ifPresent(tableModel::setContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy
private void doLink(BibEntry entry, ExternalFileType fileType, String filename,
boolean avoidDuplicate, NamedCompound edits) {

Optional<String> oldValue = entry.getFieldOptional(FieldName.FILE);
Optional<String> oldValue = entry.getField(FieldName.FILE);
FileListTableModel tm = new FileListTableModel();
oldValue.ifPresent(tm::setContent);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/external/FindFullTextAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void run() {
boolean removeAllBroken = false;
mainLoop: for (BibEntry aSel : sel) {
panel.frame().setProgressBarValue(progress++);
final Optional<String> old = aSel.getFieldOptional(FieldName.FILE);
final Optional<String> old = aSel.getField(FieldName.FILE);
// Check if a extension is set:
if (old.isPresent() && !(old.get().isEmpty())) {
FileListTableModel tableModel = new FileListTableModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TransferableFileLinkSelection implements Transferable {

public TransferableFileLinkSelection(BasePanel panel, List<BibEntry> 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<String> dirs = panel.getBibDatabaseContext()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/external/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void run() {
List<File> files = new ArrayList<>();

// First check the (legacy) "pdf" field:
entry.getFieldOptional(FieldName.PDF)
entry.getField(FieldName.PDF)
.ifPresent(
pdf -> FileUtil
.expandFilename(pdf,
Expand All @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void actionPerformed(ActionEvent actionEvent) {
List<File> 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));
Expand All @@ -63,7 +63,7 @@ public void actionPerformed(ActionEvent actionEvent) {
List<String> 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())) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -2010,9 +2010,9 @@ public void action() {
final List<BibEntry> bes = mainTable.getSelectedEntries();
if (bes.size() == 1) {
String field = FieldName.DOI;
Optional<String> link = bes.get(0).getFieldOptional(FieldName.DOI);
Optional<String> 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()) {
Expand All @@ -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())
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/sf/jabref/gui/EntryMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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<Object> 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();
Expand All @@ -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);
}
}
Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/sf/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +150,6 @@ public class FindUnlinkedFilesDialog extends JDialog {
private JComboBox<BibtexEntryTypeWrapper> comboBoxEntryTypeSelection;
private JProgressBar progressBarSearching;
private JProgressBar progressBarImporting;
private JFileChooser fileChooser;

private MouseListener treeMouseListener;
private Action actionSelectAll;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/ReplaceStringDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private static UndoableEdit massSetField(Collection<BibEntry> entries, String fi

NamedCompound ce = new NamedCompound(Localization.lang("Set field"));
for (BibEntry entry : entries) {
Optional<String> oldVal = entry.getFieldOptional(field);
Optional<String> oldVal = entry.getField(field);
// If we are not allowed to overwrite values, check if there is a
// nonempty
// value already for this entry:
Expand Down Expand Up @@ -293,14 +293,14 @@ private static UndoableEdit massRenameField(Collection<BibEntry> entries, String
boolean overwriteValues) {
NamedCompound ce = new NamedCompound(Localization.lang("Rename field"));
for (BibEntry entry : entries) {
Optional<String> valToMove = entry.getFieldOptional(field);
Optional<String> 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<String> valInNewField = entry.getFieldOptional(newField);
Optional<String> valInNewField = entry.getField(newField);
if (!overwriteValues && (valInNewField.isPresent()) && !valInNewField.get().isEmpty()) {
continue;
}
Expand Down
Loading

0 comments on commit 4e0ff50

Please sign in to comment.