Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enum class cast error in TreeSet by specifying an explicit comparator #5184

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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