From e91cc71217a31e82ea4755d5a63f89a54ee5f787 Mon Sep 17 00:00:00 2001 From: Johannes Hupe Date: Thu, 17 Oct 2019 19:14:25 +0200 Subject: [PATCH 1/4] Remove unnecessary sort The list gets sorted before. Therefore its not necessary to sort it again. --- .../org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index b88a0cd5fe7..33d94148deb 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -41,7 +41,6 @@ public WebSearchPaneViewModel(ImportFormatPreferences importPreferences, JabRefF this.dialogService = dialogService; List allFetchers = WebFetchers.getSearchBasedFetchers(importPreferences); - allFetchers.sort(Comparator.comparing(WebFetcher::getName)); fetchers.setAll(allFetchers); // Choose last-selected fetcher as default From 465186be3993660ec5dde0b3453b46516be4ed04 Mon Sep 17 00:00:00 2001 From: Johannes Hupe Date: Thu, 17 Oct 2019 19:43:55 +0200 Subject: [PATCH 2/4] Remove unnecessary sort The list gets sorted before. Therefore its not necessary to sort it again. --- .../org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index 33d94148deb..b3bbb20308b 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -1,6 +1,5 @@ package org.jabref.gui.importer.fetcher; -import java.util.Comparator; import java.util.List; import javafx.beans.property.ListProperty; @@ -18,7 +17,6 @@ import org.jabref.gui.util.BackgroundTask; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.SearchBasedFetcher; -import org.jabref.logic.importer.WebFetcher; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; From 7333da70a577a4c0f938007b6e49cbd9cd73885c Mon Sep 17 00:00:00 2001 From: Johannes Hupe Date: Thu, 17 Oct 2019 23:01:17 +0200 Subject: [PATCH 3/4] Changed return type to SortedList --- .../jabref/logic/importer/WebFetchers.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index 604cd750541..210d8e5d13d 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -5,6 +5,10 @@ import java.util.List; import java.util.Optional; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.collections.transformation.SortedList; + import org.jabref.logic.importer.fetcher.ACMPortalFetcher; import org.jabref.logic.importer.fetcher.ACS; import org.jabref.logic.importer.fetcher.ArXiv; @@ -76,7 +80,10 @@ public static Optional> getIdFetcherForField(Fie return Optional.empty(); } - public static List getSearchBasedFetchers(ImportFormatPreferences importFormatPreferences) { + /** + * @return sorted list containing search based fetchers + */ + public static SortedList getSearchBasedFetchers(ImportFormatPreferences importFormatPreferences) { ArrayList list = new ArrayList<>(); list.add(new ArXiv(importFormatPreferences)); list.add(new INSPIREFetcher(importFormatPreferences)); @@ -93,10 +100,14 @@ public static List getSearchBasedFetchers(ImportFormatPrefer list.add(new CiteSeer()); list.add(new DOAJFetcher(importFormatPreferences)); list.add(new IEEE(importFormatPreferences)); - list.sort(Comparator.comparing(WebFetcher::getName)); - return list; + + ObservableList observableList = FXCollections.observableList(list); + return new SortedList<>(observableList, Comparator.comparing(WebFetcher::getName)); } + /** + * @return sorted list containing id based fetchers + */ public static List getIdBasedFetchers(ImportFormatPreferences importFormatPreferences) { ArrayList list = new ArrayList<>(); list.add(new ArXiv(importFormatPreferences)); @@ -111,10 +122,14 @@ public static List getIdBasedFetchers(ImportFormatPreferences im list.add(new LibraryOfCongress(importFormatPreferences)); list.add(new IacrEprintFetcher(importFormatPreferences)); list.add(new RfcFetcher(importFormatPreferences)); - list.sort(Comparator.comparing(WebFetcher::getName)); - return list; + + ObservableList observableList = FXCollections.observableList(list); + return new SortedList<>(observableList, Comparator.comparing(WebFetcher::getName)); } + /** + * @return sorted list containing entry based fetchers + */ public static List getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences) { ArrayList list = new ArrayList<>(); list.add(new AstrophysicsDataSystem(importFormatPreferences)); @@ -122,18 +137,26 @@ public static List getEntryBasedFetchers(ImportFormatPreferen list.add(new IsbnFetcher(importFormatPreferences)); list.add(new MathSciNet(importFormatPreferences)); list.add(new CrossRef()); - list.sort(Comparator.comparing(WebFetcher::getName)); - return list; + + ObservableList observableList = FXCollections.observableList(list); + return new SortedList<>(observableList, Comparator.comparing(WebFetcher::getName)); } - public static List getIdFetchers(ImportFormatPreferences importFormatPreferences) { + /** + * @return sorted list containing id fetchers + */ + public static SortedList getIdFetchers(ImportFormatPreferences importFormatPreferences) { ArrayList list = new ArrayList<>(); list.add(new CrossRef()); list.add(new ArXiv(importFormatPreferences)); - list.sort(Comparator.comparing(WebFetcher::getName)); - return list; + + ObservableList observableList = FXCollections.observableList(list); + return new SortedList<>(observableList, Comparator.comparing(WebFetcher::getName)); } + /** + * @return unsorted list containing fulltext fetchers + */ public static List getFullTextFetchers(ImportFormatPreferences importFormatPreferences) { List fetchers = new ArrayList<>(); // Original From 5b7dfc546326aef6483d0ac8e756b653f7350b84 Mon Sep 17 00:00:00 2001 From: Johannes Hupe Date: Thu, 17 Oct 2019 23:14:30 +0200 Subject: [PATCH 4/4] Added javadoc: return sorted list --- src/main/java/org/jabref/logic/importer/WebFetchers.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index 210d8e5d13d..85f0feca7c3 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -108,7 +108,7 @@ public static SortedList getSearchBasedFetchers(ImportFormat /** * @return sorted list containing id based fetchers */ - public static List getIdBasedFetchers(ImportFormatPreferences importFormatPreferences) { + public static SortedList getIdBasedFetchers(ImportFormatPreferences importFormatPreferences) { ArrayList list = new ArrayList<>(); list.add(new ArXiv(importFormatPreferences)); list.add(new AstrophysicsDataSystem(importFormatPreferences)); @@ -130,7 +130,7 @@ public static List getIdBasedFetchers(ImportFormatPreferences im /** * @return sorted list containing entry based fetchers */ - public static List getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences) { + public static SortedList getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences) { ArrayList list = new ArrayList<>(); list.add(new AstrophysicsDataSystem(importFormatPreferences)); list.add(new DoiFetcher(importFormatPreferences));