From 0eabed630da87dd5fe96c2604df9ad8230f445e7 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 10 Aug 2019 14:29:23 +0200 Subject: [PATCH] Fix enum class cast in TreeSet error by specifying an explicit comparator because natural order will require same types of the enum Followup from #5148 --- .../gui/collab/EntryChangeViewModel.java | 3 ++- .../gui/mergeentries/FetchAndMergeEntry.java | 7 +++++-- .../jabref/gui/mergeentries/MergeEntries.java | 18 +++++++++--------- .../org/jabref/model/database/BibDatabase.java | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java index 8cd799b204c..68b6452a1c2 100644 --- a/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui.collab; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.Set; @@ -44,7 +45,7 @@ public EntryChangeViewModel(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskE LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + "\n Modified locally: " + isModifiedLocally + " Modifications agree: " + modificationsAgree); - Set allFields = new TreeSet<>(); + Set allFields = new TreeSet<>(Comparator.comparing(Field::getName)); allFields.addAll(memEntry.getFields()); allFields.addAll(tmpEntry.getFields()); allFields.addAll(diskEntry.getFields()); diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index d8b7e722fe1..159b6cae598 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -2,6 +2,7 @@ import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.Set; @@ -92,8 +93,10 @@ private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebF NamedCompound ce = new NamedCompound(Localization.lang("Merge entry with %0 information", fetcher.getName())); // Updated the original entry with the new fields - Set jointFields = new TreeSet<>(mergedEntry.get().getFields()); - Set originalFields = new TreeSet<>(originalEntry.getFields()); + Set jointFields = new TreeSet<>(Comparator.comparing(Field::getName)); + jointFields.addAll(mergedEntry.get().getFields()); + Set originalFields = new TreeSet<>(Comparator.comparing(Field::getName)); + originalFields.addAll(originalEntry.getFields()); boolean edited = false; // entry type diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java index e842598fe32..30d393a236c 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -46,18 +47,18 @@ public class MergeEntries extends BorderPane { // Headings private final List columnHeadings = Arrays.asList(Localization.lang("Field"), - Localization.lang("Left entry"), - Localization.lang("Left"), - Localization.lang("None"), - Localization.lang("Right"), - Localization.lang("Right entry")); + Localization.lang("Left entry"), + Localization.lang("Left"), + Localization.lang("None"), + Localization.lang("Right"), + Localization.lang("Right entry")); private final Set identicalFields = new HashSet<>(); private final Set differentFields = new HashSet<>(); private final BibEntry mergedEntry = new BibEntry(); private final BibEntry leftEntry; private final BibEntry rightEntry; private final Map leftTextPanes = new HashMap<>(); - private final Set allFields = new TreeSet<>(); + private final Set allFields = new TreeSet<>(Comparator.comparing(Field::getName)); private final Map rightTextPanes = new HashMap<>(); private final Map> radioButtons = new HashMap<>(); private Boolean identicalTypes; @@ -81,7 +82,6 @@ public MergeEntries(BibEntry entryLeft, BibEntry entryRight, String headingLeft, setRightHeaderText(headingRight); } - /** * Constructor taking two entries * @@ -240,8 +240,8 @@ private void setupHeadingRows(GridPane mergePanel) { private void fillDiffModes() { diffMode.setItems(FXCollections.observableList(Arrays.asList(DiffMode.values()))); new ViewModelListCellFactory() - .withText(MergeEntries::getDisplayText) - .install(diffMode); + .withText(MergeEntries::getDisplayText) + .install(diffMode); DiffMode diffModePref = Globals.prefs.getAsOptional(JabRefPreferences.MERGE_ENTRIES_DIFF_MODE) .flatMap(DiffMode::parse) .orElse(DiffMode.WORD); diff --git a/src/main/java/org/jabref/model/database/BibDatabase.java b/src/main/java/org/jabref/model/database/BibDatabase.java index b641a05b803..a970dd438e6 100644 --- a/src/main/java/org/jabref/model/database/BibDatabase.java +++ b/src/main/java/org/jabref/model/database/BibDatabase.java @@ -133,7 +133,7 @@ public ObservableList getEntries() { * @return set of fieldnames, that are visible */ public Set getAllVisibleFields() { - Set allFields = new TreeSet<>(); + Set allFields = new TreeSet<>(Comparator.comparing(Field::getName)); for (BibEntry e : getEntries()) { allFields.addAll(e.getFields()); }