I know that this kind of question has been asked millions of times if not billions, however I couldn't find my answer yet :)
This compare()
method doesn't have Long
, Double
, Float
, ..., it only has Date
, boolean
, and Null
checker, however it shows me that contract violation error
, can any one help plz?
Collections.sort(users, new Comparator<MiniUser>() {
@Override
public int compare(MiniUser u1, MiniUser u2) {
boolean resComing = checkMatchConditions(u1,user);
boolean resExists = checkMatchConditions(u2,user);
if(Boolean.valueOf(resComing) && Boolean.valueOf(resExists)) {
if(u1.getLastMatchDate() == null){
return -1;
}else if(u2.getLastMatchDate() ==null ){
return 1;
}else if (u1.getLastMatchDate().toInstant().isBefore(u2.getLastMatchDate().toInstant())){
return -1;
}else {
return 1;
}
}
else if (Boolean.valueOf(resComing)) {
return -1;
}
return 1;
}
});
MiniUser.class
public class MiniUser implements Serializable {
String id;
String name;
Date lastMatchDate;
boolean showCompleteName;
//getters, setters
}
checkMatchConditions
return boolean based on some calculations