Having StreamStream how can we get the Stream containing more elements in the other stream

0

I have 3 interfaces

public interface IGhOrg {
    int getId();

    String getLogin();

    String getName();

    String getLocation();

    Stream<IGhRepo> getRepos();
}

public interface IGhRepo {
    int getId();

    int getSize();

    int getWatchersCount();

    String getLanguage();

    Stream<IGhUser> getContributors();

}

public interface IGhUser {
    int getId();

    String getLogin();

    String getName();

    String getCompany();

    Stream<IGhOrg> getOrgs();
}
  • I want to get IGhRepo with the largest number of users to contribute
    (% with%)

Signature method:

Optional<IGhRepo> highestContributors(Stream<IGhOrg> organizations)
  • What I've done to reach the goal, but without success:

    Optional<IGhRepo> highestContributors(Stream<IGhOrg> organizations){
        return organizations
                .flatMap(IGhOrg::getRepos)
                .max((repo1,repo2)-> (int)repo1.getContributors().count() -(int)repo2.getContributors().count() );
    }
    

The result is this exception:

  

java.lang.IllegalStateException: stream has already been operated upon or closed

NOTE: I understand that Stream<IGhUser> getContributors() is a terminal operation of class count() and that's why it gives me this exception.

I can not solve this problem, please help.

Thank you.

    
asked by anonymous 27.06.2016 / 05:20

0 answers