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.