Greeting,
I have 2 objects :
- Petition
- Signataire (signatory)
I wrote this code:
public List<Petition> getTheMostSigned(long groupId){
List<Petition> petitionList = petitionPersistence.findByStatusAndGroupId(0,groupId);
_log.info("list avant getTheMostSigned size : "+petitionList.stream().map(petition -> petition.getSignataires().size()).collect(Collectors.toList()));
List<Petition> resultList = petitionList.stream()
.sorted(Comparator.comparingInt(petition -> petition.getSignataires().size()))
.sorted(Collections.reverseOrder())
.collect(Collectors.toList());
_log.info("list apres getTheMostSigned size : "+resultList.stream().map(petition -> petition.getSignataires().size()).collect(Collectors.toList()));
return resultList;
The getSignataires() return a List.
but the result wasn't what I expected :
2018-09-12 12:44:25.686 INFO [http-nio-8080-exec-10][PetitionLocalServiceImpl:390] list avant getTheMostSigned size : [0, 0, 400, 0, 3, 401, 5501]
2018-09-12 12:44:25.856 INFO [http-nio-8080-exec-10][PetitionLocalServiceImpl:396] list apres getTheMostSigned size : [5501, 401, 3, 0, 0, **400**, 0]
As you can see, the penultimate is not the good one. do you know why the Comparator isn't doing the job ?
