[git]: cleanUp - to stream API

This commit is contained in:
Nadya Zabrodina
2016-12-02 19:01:27 +03:00
committed by Nadya Zabrodina
parent a78c54687f
commit f3f591bcab
2 changed files with 36 additions and 29 deletions
@@ -33,6 +33,9 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.List;
import java.util.Objects;
import static java.util.stream.Collectors.toList;
/**
* The popup which allows to quickly switch and control Git branches.
@@ -106,17 +109,25 @@ class GitBranchPopup extends DvcsBranchPopup<GitRepository> {
popupGroup.addAll(createRepositoriesActions());
popupGroup.addSeparator("Common Local Branches");
for (String branch : myMultiRootBranchConfig.getLocalBranchNames()) {
List<GitRepository> repositories = filterRepositoriesNotOnThisBranch(branch, allRepositories);
if (!repositories.isEmpty()) {
popupGroup.add(new GitBranchPopupActions.LocalBranchActions(myProject, repositories, branch, myCurrentRepository));
}
}
List<GitBranchPopupActions.LocalBranchActions> localBranchActions =
myMultiRootBranchConfig.getLocalBranchNames().stream().map(l -> createLocalBranchActions(allRepositories, l)).filter(Objects::nonNull)
.collect(toList());
popupGroup.addAll(localBranchActions);
popupGroup.addSeparator("Common Remote Branches");
for (String branch : ((GitMultiRootBranchConfig)myMultiRootBranchConfig).getRemoteBranches()) {
popupGroup.add(new GitBranchPopupActions.RemoteBranchActions(myProject, allRepositories, branch, myCurrentRepository));
}
List<GitBranchPopupActions.RemoteBranchActions> remoteBranchActions =
((GitMultiRootBranchConfig)myMultiRootBranchConfig).getRemoteBranches().stream()
.map(r -> new GitBranchPopupActions.RemoteBranchActions(myProject, allRepositories, r, myCurrentRepository)).collect(toList());
popupGroup.addAll(remoteBranchActions);
}
@Nullable
private GitBranchPopupActions.LocalBranchActions createLocalBranchActions(@NotNull List<GitRepository> allRepositories,
@NotNull String branch) {
List<GitRepository> repositories = filterRepositoriesNotOnThisBranch(branch, allRepositories);
return repositories.isEmpty()
? null
: new GitBranchPopupActions.LocalBranchActions(myProject, repositories, branch, myCurrentRepository);
}
@NotNull
@@ -124,11 +135,11 @@ class GitBranchPopup extends DvcsBranchPopup<GitRepository> {
protected DefaultActionGroup createRepositoriesActions() {
DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
popupGroup.addSeparator("Repositories");
for (GitRepository repository : DvcsUtil.sortRepositories(myRepositoryManager.getRepositories())) {
popupGroup.add(new RootAction<>(repository, highlightCurrentRepo() ? myCurrentRepository : null,
new GitBranchPopupActions(repository.getProject(), repository).createActions(),
GitBranchUtil.getDisplayableBranchText(repository)));
}
List<RootAction<GitRepository>> rootActions = DvcsUtil.sortRepositories(myRepositoryManager.getRepositories()).stream()
.map(repo -> new RootAction<>(repo, highlightCurrentRepo() ? myCurrentRepository : null,
new GitBranchPopupActions(repo.getProject(), repo).createActions(),
GitBranchUtil.getDisplayableBranchText(repo))).collect(toList());
popupGroup.addAll(rootActions);
return popupGroup;
}
@@ -27,7 +27,6 @@ import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.util.containers.ContainerUtil;
import git4idea.GitBranch;
import git4idea.branch.GitBranchUtil;
import git4idea.branch.GitBrancher;
import git4idea.repo.GitRepository;
@@ -35,9 +34,9 @@ import git4idea.validators.GitNewBranchNameValidator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static git4idea.GitStatisticsCollectorKt.reportUsage;
@@ -65,22 +64,19 @@ class GitBranchPopupActions {
if (toInsert != null) {
popupGroup.addAll(toInsert);
}
popupGroup.addSeparator("Local Branches" + repoInfo);
List<GitBranch> localBranches = new ArrayList<>(myRepository.getBranches().getLocalBranches());
Collections.sort(localBranches);
for (GitBranch localBranch : localBranches) {
if (!localBranch.equals(myRepository.getCurrentBranch())) { // don't show current branch in the list
popupGroup.add(new LocalBranchActions(myProject, repositoryList, localBranch.getName(), myRepository));
}
}
List<AnAction> localBranchActions =
myRepository.getBranches().getLocalBranches().stream().sorted().filter(l -> !l.equals(myRepository.getCurrentBranch()))
.map(l -> new LocalBranchActions(myProject, repositoryList, l.getName(), myRepository)).collect(
Collectors.toList());
popupGroup.addAll(localBranchActions);
popupGroup.addSeparator("Remote Branches" + repoInfo);
List<GitBranch> remoteBranches = new ArrayList<>(myRepository.getBranches().getRemoteBranches());
Collections.sort(remoteBranches);
for (GitBranch remoteBranch : remoteBranches) {
popupGroup.add(new RemoteBranchActions(myProject, repositoryList, remoteBranch.getName(), myRepository));
}
List<AnAction> remoteBranchActions = myRepository.getBranches().getRemoteBranches().stream().sorted()
.map(r -> new RemoteBranchActions(myProject, repositoryList, r.getName(), myRepository))
.collect(Collectors.toList());
popupGroup.addAll(remoteBranchActions);
return popupGroup;
}