Say I have following simple data structure.
public class Player {
private Long id;
private String name;
private Integer scores;
//getter setter
}
So far so good. Now question is , how do I get what's a players rank? I have another data structure for ranking, that is-
public class Ranking {
private Integer score;
private Integer rank;
//getter/setter
}
So I have a list of player and i want to compute a list of ranking and I would like to use java8 stream api.
I have a service named PlayerService
as following
public class PlayerService {
@Autowired
private PlayerRepository playerRepository;
public List<Ranking> findAllRanking(Long limit) {
List<Player> players = playerRepository.findAll();
// calculation
return null;
}
The calculation is simple, whoever has most score has most ranking.
If I have 5,7,8,9,3
scores then ranking would be
rank score
1 9
2 8
3 7
4 5
5 3
Any help would be appreciated.