import java.util.ArrayList;
import java.util.List;
import java.util.stream.*;
public class ParallelTeams {
enum Sport {Baseball, Football,Basketball,Hockey}
class athlete {
public Sport game;
public String name;
public String year; //Frosh, Soph, Jr, Senior
public int testgrade; //entrance exam grade
public athlete(Sport s,String n,String y,int t){
game=s;
name=n;
year=y;
testgrade=t;
}
}
public static void main(String args[]) {
new ParallelTeams();
}
public ParallelTeams(){
athlete ss = new athlete(Sport.Baseball, "Sam Smith", "Jr", 95);
athlete jj = new athlete(Sport.Basketball, "Joe Johnson", "Jr", 90);
athlete rb = new athlete(Sport.Baseball,"Robert Brown", "Soph", 80);
athlete bj = new athlete(Sport.Hockey, "Bob Jones", "Jr", 85);
athlete jr = new athlete(Sport.Baseball, "Joe Roberts", "Senior", 65);
athlete le = new athlete(Sport.Basketball,"Ed Edwards", "Soph", 70);
List<athlete> allplayers = new ArrayList<>();
allplayers.add(ss);allplayers.add(jj);allplayers.add(rb);
allplayers.add(bj);allplayers.add(jr);allplayers.add(le);
Stream<athlete> baseballers = allplayers.stream().filter((a) -> a.game==Sport.Baseball);
Stream<athlete> basketballers = allplayers.stream().filter((a) -> a.game==Sport.Basketball);
Stream<athlete> hockeyplayers = allplayers.stream().filter((a) -> a.game==Sport.Hockey);
List<Stream<athlete>> the_sports= new ArrayList<>();
the_sports.add(baseballers);the_sports.add(basketballers);the_sports.add(hockeyplayers);
the_sports.parallelStream().forEach(e->{System.out.println(e.count());});
}
}
Parallelism