Authored by qinchao

排序

... ... @@ -116,12 +116,7 @@ public class ZkSvcLookupServiceImpl implements IZkSvcLookupService {
list.add(zkSvc);
}
Collections.sort(list, new Comparator<ZkSvc>(){//使用匿名类自定义规则来排序
@Override
public int compare(ZkSvc obj1, ZkSvc obj2) {
return obj2.getCreteSvcSize().compareTo(obj1.getCreteSvcSize());
}
});
list.sort(Comparator.comparing(ZkSvc::getCreteSvcSize).reversed());
response.setCurrentPage(1);
response.setTotalPage(1);
... ...
... ... @@ -367,11 +367,11 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
return response;
}
listMaliciousIp = (List<MaliciousIp>) JSON.parseArray(ips_json, MaliciousIp.class);
Comparator comp = new ComparatorIp();
/*Collections.sort(newlistMaliciousIp, comp);
response.setData(newlistMaliciousIp);*/
Collections.sort(listMaliciousIp, comp);
if(listMaliciousIp!=null&&listMaliciousIp.size()>1){
listMaliciousIp.sort(Comparator.comparing(MaliciousIp::getQps).reversed());
}
response.setData(listMaliciousIp);
}catch(Exception e){
... ... @@ -400,8 +400,10 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
maliciousDetailIp.setPercent(maliciousDetailIp.getCount() * 100 / Integer.parseInt(count));
}
}
Comparator comp = new ComparatorDetailIp();
Collections.sort(listMaliciousDetailIp, comp);
if(listMaliciousDetailIp!=null&&listMaliciousDetailIp.size()>1){
listMaliciousDetailIp.sort(Comparator.comparing(MaliciousDetailIp::getCount).reversed());
}
response.setData(listMaliciousDetailIp);
}catch(Exception e){
logger.error(" - MaliciousIpServiceImpl - getDetail - error", e);
... ... @@ -437,34 +439,6 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
return response;
}
class ComparatorIp implements Comparator<MaliciousIp> {
public int compare(MaliciousIp e1, MaliciousIp e2) {
long count1 = e1.getQps();
long count2 = e2.getQps();
if (count1 < count2) {
return 1;
} else if (count1 > count2) {
return -1;
} else {
return 0;
}
}
}
class ComparatorDetailIp implements Comparator<MaliciousDetailIp> {
public int compare(MaliciousDetailIp e1, MaliciousDetailIp e2) {
int count1 = e1.getCount();
int count2 = e2.getCount();
if (count1 < count2) {
return 1;
} else if (count1 > count2) {
return -1;
} else {
return 0;
}
}
}
@Override
public BaseResponse<Integer> saveMalIpRule(MalIpRule malIpRule){
try{
... ...