forked from I2P_Developers/i2p.i2p
Use Double.compare() in comparators (findbugs)
This commit is contained in:
@ -115,11 +115,7 @@ class SybilRenderer {
|
||||
reasons.add(reason);
|
||||
}
|
||||
public int compareTo(Points r) {
|
||||
if (points > r.points)
|
||||
return 1;
|
||||
if (points < r.points)
|
||||
return -1;
|
||||
return 0;
|
||||
return Double.compare(points, r.points);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,13 @@ class InverseCapacityComparator implements Comparator<PeerProfile>, Serializable
|
||||
|
||||
double rval = right.getCapacityValue();
|
||||
double lval = left.getCapacityValue();
|
||||
int rv = Double.compare(rval, lval);
|
||||
|
||||
if (lval == rval) {
|
||||
if (rv == 0) {
|
||||
rval = right.getSpeedValue();
|
||||
lval = left.getSpeedValue();
|
||||
if (lval == rval) {
|
||||
rv = Double.compare(rval, lval);
|
||||
if (rv == 0) {
|
||||
// note the following call inverts right and left (see: classname)
|
||||
return DataHelper.compareTo(right.getPeer().getData(), left.getPeer().getData());
|
||||
} else {
|
||||
@ -35,18 +37,6 @@ class InverseCapacityComparator implements Comparator<PeerProfile>, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
boolean rightBigger = rval > lval;
|
||||
|
||||
//if (_log.shouldLog(Log.DEBUG))
|
||||
// _log.debug("The capacity of " + right.getPeer().toBase64()
|
||||
// + " and " + left.getPeer().toBase64() + " marks " + (rightBigger ? "right" : "left")
|
||||
// + " as larger: r=" + right.getCapacityValue()
|
||||
// + " l="
|
||||
// + left.getCapacityValue());
|
||||
|
||||
if (rightBigger)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
@ -15,19 +15,16 @@ class SpeedComparator implements Comparator<PeerProfile>, Serializable {
|
||||
|
||||
double lval = left.getSpeedValue();
|
||||
double rval = right.getSpeedValue();
|
||||
|
||||
if (lval > rval)
|
||||
return 1;
|
||||
if (lval < rval)
|
||||
return -1;
|
||||
int rv = Double.compare(lval, rval);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
|
||||
// we don't wan't to return 0 so profiles don't vanish in the TreeSet
|
||||
lval = left.getCapacityValue();
|
||||
rval = right.getCapacityValue();
|
||||
if (lval > rval)
|
||||
return 1;
|
||||
if (lval < rval)
|
||||
return -1;
|
||||
rv = Double.compare(lval, rval);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
return DataHelper.compareTo(right.getPeer().getData(), left.getPeer().getData());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user