Skip to content

Commit b112686

Browse files
committed
Show vulnerable items at the top of the list
1 parent b46870e commit b112686

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

app/src/main/java/fuzion24/device/vulnerability/test/adapter/RecyclerAdapter.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,32 @@ private static List<Pair<VulnerabilityTestResult, VulnerabilityDescriptor>> buil
5656
}
5757

5858
Collections.sort(res, new Comparator<Pair<VulnerabilityTestResult, VulnerabilityDescriptor>>() {
59+
private final static int leftFirst = 1;
60+
private final static int rightFirst = -1;
61+
private final static int areEqual = 0;
62+
5963
@Override
6064
public int compare(Pair<VulnerabilityTestResult, VulnerabilityDescriptor> lhs, Pair<VulnerabilityTestResult, VulnerabilityDescriptor> rhs) {
6165
VulnerabilityDescriptor lhDesc = lhs.second;
6266
VulnerabilityDescriptor rhDesc = rhs.second;
63-
return lhDesc.getCVEDate().before(rhDesc.getCVEDate()) ? 1 : -1;
67+
68+
boolean rIsNewer = lhDesc.getCVEDate().before(rhDesc.getCVEDate());
69+
boolean sameDate = lhDesc.getCVEDate().equals(rhDesc.getCVEDate());
70+
boolean lVuln = lhs.first.getException() == null && lhs.first.isVulnerable();
71+
boolean rVuln = rhs.first.getException() == null && rhs.first.isVulnerable();
72+
73+
if(lVuln && !rVuln){
74+
return leftFirst;
75+
}else if(!lVuln && rVuln){
76+
return rightFirst;
77+
}else if(sameDate) {
78+
return areEqual;
79+
} else {
80+
return rIsNewer ? rightFirst : leftFirst;
81+
}
6482
}
6583
});
84+
6685
}catch(Exception e){
6786
e.printStackTrace();
6887
}

0 commit comments

Comments
 (0)