class ProjectBranchBreadcrumb implements BreadcrumbPresenter {

    public ProjectBranchBreadcrumb setup(final Collection<Branch> branches) {
        final Set<Branch> branchesSet = new HashSet<>();
        final List<Promise<Boolean>> canReadBranchPromises = branches.stream().map(b -> projectController.canReadBranch(libraryPlaces.getActiveWorkspace(),
                                                                                                                        b.getName()).then(canReadBranch -> {
            if (canReadBranch) {
                branchesSet.add(b);
            }
            return promises.resolve(true);
        })).collect(Collectors.toList());

        promises.all(canReadBranchPromises.toArray(new Promise[canReadBranchPromises.size()])).then(ignored -> {
            this.branches = branchesSet.stream().sorted(BRANCH_ALPHABETICAL_ORDER_COMPARATOR).collect(Collectors.toList());
            view.init(this);
            return promises.resolve();
        });

        return this;
    }

    @Inject public  ProjectBranchBreadcrumb(final View view,
                                   final LibraryPlaces libraryPlaces,
                                   final Event<NotificationEvent> notificationEvent,
                                   final ProjectController projectController,
                                   final Promises promises);

}