Skip to content

Commit

Permalink
Fix enum class cast in TreeSet error by specifying an explicit compar…
Browse files Browse the repository at this point in the history
…ator

because natural order will require same types of the enum

Followup from  #5148
  • Loading branch information
Siedlerchr committed Aug 10, 2019
1 parent 09c17e6 commit 0eabed6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@ public EntryChangeViewModel(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskE
LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("<no BibTeX key set>")
+ "\n Modified locally: " + isModifiedLocally + " Modifications agree: " + modificationsAgree);

Set<Field> allFields = new TreeSet<>();
Set<Field> allFields = new TreeSet<>(Comparator.comparing(Field::getName));
allFields.addAll(memEntry.getFields());
allFields.addAll(tmpEntry.getFields());
allFields.addAll(diskEntry.getFields());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Field> jointFields = new TreeSet<>(mergedEntry.get().getFields());
Set<Field> originalFields = new TreeSet<>(originalEntry.getFields());
Set<Field> jointFields = new TreeSet<>(Comparator.comparing(Field::getName));
jointFields.addAll(mergedEntry.get().getFields());
Set<Field> originalFields = new TreeSet<>(Comparator.comparing(Field::getName));
originalFields.addAll(originalEntry.getFields());
boolean edited = false;

// entry type
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/jabref/gui/mergeentries/MergeEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,18 +47,18 @@ public class MergeEntries extends BorderPane {

// Headings
private final List<String> 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<Field> identicalFields = new HashSet<>();
private final Set<Field> differentFields = new HashSet<>();
private final BibEntry mergedEntry = new BibEntry();
private final BibEntry leftEntry;
private final BibEntry rightEntry;
private final Map<Field, TextFlow> leftTextPanes = new HashMap<>();
private final Set<Field> allFields = new TreeSet<>();
private final Set<Field> allFields = new TreeSet<>(Comparator.comparing(Field::getName));
private final Map<Field, TextFlow> rightTextPanes = new HashMap<>();
private final Map<Field, List<RadioButton>> radioButtons = new HashMap<>();
private Boolean identicalTypes;
Expand All @@ -81,7 +82,6 @@ public MergeEntries(BibEntry entryLeft, BibEntry entryRight, String headingLeft,
setRightHeaderText(headingRight);
}


/**
* Constructor taking two entries
*
Expand Down Expand Up @@ -240,8 +240,8 @@ private void setupHeadingRows(GridPane mergePanel) {
private void fillDiffModes() {
diffMode.setItems(FXCollections.observableList(Arrays.asList(DiffMode.values())));
new ViewModelListCellFactory<DiffMode>()
.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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/database/BibDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public ObservableList<BibEntry> getEntries() {
* @return set of fieldnames, that are visible
*/
public Set<Field> getAllVisibleFields() {
Set<Field> allFields = new TreeSet<>();
Set<Field> allFields = new TreeSet<>(Comparator.comparing(Field::getName));
for (BibEntry e : getEntries()) {
allFields.addAll(e.getFields());
}
Expand Down

0 comments on commit 0eabed6

Please sign in to comment.