我有3个接口
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();
}
Run Code Online (Sandbox Code Playgroud)
我需要实施 Optional<IGhRepo> highestContributors(Stream<IGhOrg> organizations)
此方法返回一个包含大多数贡献者的 IGhRepo(getContributors())
我试过这个
Optional<IGhRepo> highestContributors(Stream<IGhOrg> organizations){
return organizations
.flatMap(IGhOrg::getRepos)
.max((repo1,repo2)-> (int)repo1.getContributors().count() - (int)repo2.getContributors().count() );
}
Run Code Online (Sandbox Code Playgroud)
但它给了我
java.lang.IllegalStateException: 流已经被操作或关闭
我知道count()是Stream中的一个终端操作但是我无法解决这个问题,请帮忙!
谢谢