diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index abc6e9fb460..1d2c4646dc6 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Optional; import java.util.function.Consumer; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -280,12 +281,7 @@ private void updateSelection(List> newSelectedGroup if ((newSelectedGroups == null) || newSelectedGroups.isEmpty()) { viewModel.selectedGroupsProperty().clear(); } else { - List list = new ArrayList<>(); - for (TreeItem model : newSelectedGroups) { - if ((model != null) && (model.getValue() != null) && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)) { - list.add(model.getValue()); - } - } + List list = newSelectedGroups.stream().filter(model -> model != null && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)).map(TreeItem::getValue).collect(Collectors.toList()); viewModel.selectedGroupsProperty().setAll(list); } } @@ -304,15 +300,7 @@ private Optional> getTreeItemByValue(TreeItem child : root.getChildren()) { - Optional> treeItemByValue = getTreeItemByValue(child, value); - if (treeItemByValue.isPresent()) { - return treeItemByValue; - } - } - - return Optional.empty(); + return root.getChildren().stream().filter(child -> getTreeItemByValue(child, value).isPresent()).findFirst(); } private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { diff --git a/src/main/java/org/jabref/logic/util/Version.java b/src/main/java/org/jabref/logic/util/Version.java index 11ecd279f17..e288c718064 100644 --- a/src/main/java/org/jabref/logic/util/Version.java +++ b/src/main/java/org/jabref/logic/util/Version.java @@ -3,8 +3,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -91,7 +91,7 @@ public static Version parse(String version) { * Grabs all the available releases from the GitHub repository */ public static List getAllAvailableVersions() throws IOException { - URLConnection connection = new URL(JABREF_GITHUB_RELEASES).openConnection(); + HttpURLConnection connection = (HttpURLConnection) new URL(JABREF_GITHUB_RELEASES).openConnection(); connection.setRequestProperty("Accept-Charset", "UTF-8"); try (BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { @@ -102,6 +102,7 @@ public static List getAllAvailableVersions() throws IOException { Version version = Version.parse(jsonObject.getString("tag_name").replaceFirst("v", "")); versions.add(version); } + connection.disconnect(); return versions; } }