Changeset 6fccfc9


Ignore:
Timestamp:
Oct 8, 2018 1:34:15 PM (22 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
184b617
Parents:
524c375
Message:

Use Double.compare() in comparators (findbugs)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java

    r524c375 r6fccfc9  
    116116         }
    117117         public int compareTo(Points r) {
    118              if (points > r.points)
    119                  return 1;
    120              if (points < r.points)
    121                  return -1;
    122              return 0;
     118             return Double.compare(points, r.points);
    123119        }
    124120    }
  • router/java/src/net/i2p/router/peermanager/InverseCapacityComparator.java

    r524c375 r6fccfc9  
    2424        double rval = right.getCapacityValue();
    2525        double lval = left.getCapacityValue();
     26        int rv = Double.compare(rval, lval);
    2627
    27         if (lval == rval) {
     28        if (rv == 0) {
    2829            rval = right.getSpeedValue();
    2930            lval = left.getSpeedValue();
    30             if (lval == rval) {
     31            rv = Double.compare(rval, lval);
     32            if (rv == 0) {
    3133                // note the following call inverts right and left (see: classname)
    3234                return DataHelper.compareTo(right.getPeer().getData(), left.getPeer().getData());
     
    3638        }
    3739
    38         boolean rightBigger = rval > lval;
    39 
    40         //if (_log.shouldLog(Log.DEBUG))
    41         //    _log.debug("The capacity of " + right.getPeer().toBase64()
    42         //               + " and " + left.getPeer().toBase64() + " marks " + (rightBigger ? "right" : "left")
    43         //               + " as larger: r=" + right.getCapacityValue()
    44         //               + " l="
    45         //               + left.getCapacityValue());
    46 
    47         if (rightBigger)
    48             return 1;
    49         else
    50             return -1;
     40        return rv;
    5141    }
    5242}
  • router/java/src/net/i2p/router/peermanager/SpeedComparator.java

    r524c375 r6fccfc9  
    1616        double lval = left.getSpeedValue();
    1717        double rval = right.getSpeedValue();
    18 
    19         if (lval > rval)
    20             return 1;
    21         if (lval < rval)
    22             return -1;
     18        int rv = Double.compare(lval, rval);
     19        if (rv != 0)
     20            return rv;
    2321
    2422        // we don't wan't to return 0 so profiles don't vanish in the TreeSet
    2523        lval = left.getCapacityValue();
    2624        rval = right.getCapacityValue();
    27         if (lval > rval)
    28             return 1;
    29         if (lval < rval)
    30             return -1;
     25        rv = Double.compare(lval, rval);
     26        if (rv != 0)
     27            return rv;
    3128        return DataHelper.compareTo(right.getPeer().getData(), left.getPeer().getData());
    3229    }
Note: See TracChangeset for help on using the changeset viewer.