how to find max LawInfo by date fo all games in groupingBy LawInfoType?
i have simple model :
public enum Game {
football,
hokey,
golf,
basketball
}
public class LawInfo {
private Date minDate;
private State state;
private LawInfoType textType;
private String lawInfoText;
private Game game;
}
public enum LawInfoType {
big, middle , small;
}
public enum State {
draft, ready, cancel;
}
main test
List<LawInfo> list = new ArrayList<>();
LawInfo info = null;
Random random = new Random(123);
for (int i = 0; i < 3; i++) {
for (State state : State.values()) {
for (LawInfoType lawInfoType : LawInfoType.values()) {
for (Game game : Game.values()) {
info = new LawInfo(new Date(random.nextLong()), state, lawInfoType, "TEXT", game);
list.add(info);
}
}
}
}
Predicate<LawInfo> isReady = l->l.getState().equals(State.ready);
Map<LawInfoType, List<LawInfo>> map0 = list.stream()
.filter(isReady)
.collect(groupingBy(LawInfo::getTextType)); //!!!????
but I need to get in each group max by date group by games
like this : Map<LawInfoType, List<LawInfo>>
small->[LawInfo(football, max date),LawInfo(hokey, max date) ,LawInfo(golf, max date) , LawInfo(basketball, max date)]
middle->[LawInfo(football, max date),LawInfo(hokey, max date) ,LawInfo(golf, max date) , LawInfo(basketball, max date)]
big->[LawInfo(football, max date),LawInfo(hokey, max date) ,LawInfo(golf, max date) , LawInfo(basketball, max date)]