littlecowk35 / eic-bao-tri-he-thong-oss

Automatically exported from code.google.com/p/eic-bao-tri-he-thong-oss
0 stars 0 forks source link

Error java.lang.IllegalArgumentException: Comparison method violates its general contract! #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Lỗi khi sử dụng comperator
java.lang.IllegalArgumentException: Comparison method violates its general 
contract!

Original issue reported on code.google.com by ntanh...@gmail.com on 19 Sep 2014 at 9:08

GoogleCodeExporter commented 9 years ago
Lý do lỗi:
if(orderByType.equalsIgnoreCase("desc")) {
result = ketQuaTinhDiem1.getDiemSo()>ketQuaTinhDiem2.getDiemSo()?-1:1;
} else {
result = ketQuaTinhDiem1.getDiemSo()>ketQuaTinhDiem2.getDiemSo()?1:-1;
        }

Thiếu trường hợp return 0 khi bằng nhau

Original comment by ntanh...@gmail.com on 19 Sep 2014 at 9:08

GoogleCodeExporter commented 9 years ago
Solved
if(ketQuaTinhDiem1.getDiemSo()>ketQuaTinhDiem2.getDiemSo()){
                                    result = -1;
                                }else if(ketQuaTinhDiem1.getDiemSo()<ketQuaTinhDiem2.getDiemSo()){
                                    result = 1;
                                }else{
                                    result = 0;
                                }

Original comment by ntanh...@gmail.com on 19 Sep 2014 at 9:09