Skip to content

Commit

Permalink
Merge pull request #5070 from JabRef/performance
Browse files Browse the repository at this point in the history
Refactor for loop to stream in groupTree
  • Loading branch information
Siedlerchr committed Jun 22, 2019
2 parents 6265e24 + 45d1f57 commit 4b673a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
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

0 comments on commit 4b673a0

Please sign in to comment.