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

Refactor for loop to stream in groupTree #5070

Merged
merged 1 commit into from
Jun 22, 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
18 changes: 3 additions & 15 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -280,12 +281,7 @@ private void updateSelection(List<TreeItem<GroupNodeViewModel>> newSelectedGroup
if ((newSelectedGroups == null) || newSelectedGroups.isEmpty()) {
viewModel.selectedGroupsProperty().clear();
} else {
List<GroupNodeViewModel> list = new ArrayList<>();
for (TreeItem<GroupNodeViewModel> model : newSelectedGroups) {
if ((model != null) && (model.getValue() != null) && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)) {
list.add(model.getValue());
}
}
List<GroupNodeViewModel> list = newSelectedGroups.stream().filter(model -> model != null && !(model.getValue().getGroupNode().getGroup() instanceof AllEntriesGroup)).map(TreeItem<GroupNodeViewModel>::getValue).collect(Collectors.toList());
viewModel.selectedGroupsProperty().setAll(list);
}
}
Expand All @@ -304,15 +300,7 @@ private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(TreeItem<Group
if (root.getValue().equals(value)) {
return Optional.of(root);
}

for (TreeItem<GroupNodeViewModel> child : root.getChildren()) {
Optional<TreeItem<GroupNodeViewModel>> 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) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/logic/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Version parse(String version) {
* Grabs all the available releases from the GitHub repository
*/
public static List<Version> 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()))) {

Expand All @@ -102,6 +102,7 @@ public static List<Version> getAllAvailableVersions() throws IOException {
Version version = Version.parse(jsonObject.getString("tag_name").replaceFirst("v", ""));
versions.add(version);
}
connection.disconnect();
return versions;
}
}
Expand Down