Source:
<code>public List<Branch> branchList(BranchListRequest request) throws GitException { String listMode = request.getListMode(); if (!(listMode == null || listMode.equals(BranchListRequest.LIST_ALL) || listMode.equals(BranchListRequest.LIST_REMOTE))) { throw new IllegalArgumentException(String.format(ERROR_UNSUPPORTED_LIST_MODE, listMode)); } ListBranchCommand listBranchCommand = getGit().branchList(); if (listMode != null) { if (listMode.equals(BranchListRequest.LIST_ALL)) { listBranchCommand.setListMode(ListMode.ALL); } else if (listMode.equals(BranchListRequest.LIST_REMOTE)) { listBranchCommand.setListMode(ListMode.REMOTE); } } List<Ref> refs; String currentRef; try { refs = listBranchCommand.call(); String headBranch = getRepository().getBranch(); Optional<Ref> currentTag = getGit().tagList().call().stream() .filter(tag -> tag.getObjectId().getName().equals(headBranch)) .findFirst(); if (currentTag.isPresent()) { currentRef = currentTag.get().getName(); } else { currentRef = "refs/heads/" + headBranch; } } catch (GitAPIException | IOException exception) { throw new GitException(exception.getMessage(), exception); } List<Branch> branches = new ArrayList<>(); <START> for (Ref ref : refs) { <END> String refName = ref.getName(); boolean isCommitOrTag = Constants.HEAD.equals(refName); String branchName = isCommitOrTag ? currentRef : refName; String branchDisplayName; if (isCommitOrTag) { branchDisplayName = "(detached from " + Repository.shortenRefName(currentRef) + ")"; } else { branchDisplayName = Repository.shortenRefName(refName); } Branch branch = newDto(Branch.class).withName(branchName) .withActive(isCommitOrTag || refName.equals(currentRef)) .withDisplayName(branchDisplayName) .withRemote(ref.getName().startsWith("refs/remotes")); branches.add(branch); } return branches; }</code><technical_language>benefit stream api</technical_language>

Target:
public List<Branch> branchList(BranchListRequest request) throws GitException { String listMode = request.getListMode(); if (listMode != null && !BranchListRequest.LIST_ALL.equals(listMode) && !BranchListRequest.LIST_REMOTE.equals(listMode)) { throw new IllegalArgumentException(String.format(ERROR_UNSUPPORTED_LIST_MODE, listMode)); } ListBranchCommand listBranchCommand = getGit().branchList(); if (BranchListRequest.LIST_ALL.equals(listMode)) { listBranchCommand.setListMode(ListMode.ALL); } else if (BranchListRequest.LIST_REMOTE.equals(listMode)) { listBranchCommand.setListMode(ListMode.REMOTE); } List<Ref> refs; String currentRef; try { refs = listBranchCommand.call(); String headBranch = getRepository().getBranch(); Optional<Ref> currentTag = getGit().tagList().call().stream() .filter(tag -> tag.getObjectId().getName().equals(headBranch)) .findFirst(); if (currentTag.isPresent()) { currentRef = currentTag.get().getName(); } else { currentRef = "refs/heads/" + headBranch; } } catch (GitAPIException | IOException exception) { throw new GitException(exception.getMessage(), exception); } List<Branch> branches = new ArrayList<>(); for (Ref ref : refs) { String refName = ref.getName(); boolean isCommitOrTag = Constants.HEAD.equals(refName); String branchName = isCommitOrTag ? currentRef : refName; String branchDisplayName; if (isCommitOrTag) { branchDisplayName = "(detached from " + Repository.shortenRefName(currentRef) + ")"; } else { branchDisplayName = Repository.shortenRefName(refName); } Branch branch = newDto(Branch.class).withName(branchName) .withActive(isCommitOrTag || refName.equals(currentRef)) .withDisplayName(branchDisplayName) .withRemote(refName.startsWith("refs/remotes")); branches.add(branch); } return branches; }