diff --git a/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java b/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java index bfeb49b7f..bcf0aefd0 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PartialPiece.java @@ -31,7 +31,7 @@ import net.i2p.util.SecureFile; * * @since 0.8.2 */ -class PartialPiece implements Comparable { +class PartialPiece implements Comparable { // we store the piece so we can use it in compareTo() private final Piece piece; @@ -295,8 +295,7 @@ class PartialPiece implements Comparable { * then rarest first, * then highest downloaded first */ - public int compareTo(Object o) throws ClassCastException { - PartialPiece opp = (PartialPiece)o; + public int compareTo(PartialPiece opp) { int d = this.piece.compareTo(opp.piece); if (d != 0) return d; diff --git a/apps/i2psnark/java/src/org/klomp/snark/Peer.java b/apps/i2psnark/java/src/org/klomp/snark/Peer.java index 821c39db8..683b3f221 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Peer.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Peer.java @@ -39,7 +39,7 @@ import net.i2p.util.Log; import org.klomp.snark.bencode.BEValue; -public class Peer implements Comparable +public class Peer implements Comparable { private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(Peer.class); // Identifying property, the peer id of the other side. @@ -194,7 +194,7 @@ public class Peer implements Comparable * Compares the PeerIDs. * @deprecated unused? */ - public int compareTo(Object o) + public int compareTo(Peer o) { Peer p = (Peer)o; int rv = peerID.compareTo(p.peerID); diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerID.java b/apps/i2psnark/java/src/org/klomp/snark/PeerID.java index cac80c826..16dc9224a 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerID.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerID.java @@ -42,7 +42,7 @@ import org.klomp.snark.bencode.InvalidBEncodingException; * and the PeerID is not required. * Equality is now determined solely by the dest hash. */ -class PeerID implements Comparable +class PeerID implements Comparable { private byte[] id; private Destination address; @@ -76,15 +76,15 @@ class PeerID implements Comparable * Creates a PeerID from a Map containing BEncoded peer id, ip and * port. */ - public PeerID(Map m) + public PeerID(Map m) throws InvalidBEncodingException, UnknownHostException { - BEValue bevalue = (BEValue)m.get("peer id"); + BEValue bevalue = m.get("peer id"); if (bevalue == null) throw new InvalidBEncodingException("peer id missing"); id = bevalue.getBytes(); - bevalue = (BEValue)m.get("ip"); + bevalue = m.get("ip"); if (bevalue == null) throw new InvalidBEncodingException("ip missing"); address = I2PSnarkUtil.getDestinationFromBase64(bevalue.getString()); @@ -195,10 +195,8 @@ class PeerID implements Comparable * Compares port, address and id. * @deprecated unused? and will NPE now that address can be null? */ - public int compareTo(Object o) + public int compareTo(PeerID pid) { - PeerID pid = (PeerID)o; - int result = port - pid.port; if (result != 0) return result; diff --git a/apps/i2psnark/java/src/org/klomp/snark/Piece.java b/apps/i2psnark/java/src/org/klomp/snark/Piece.java index 582505bc4..202afe4c4 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Piece.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Piece.java @@ -7,7 +7,7 @@ import java.util.Set; * This class is used solely by PeerCoordinator. * Caller must synchronize on many of these methods. */ -class Piece implements Comparable { +class Piece implements Comparable { private final int id; private final Set peers; @@ -26,11 +26,11 @@ class Piece implements Comparable { * Highest priority first, * then rarest first */ - public int compareTo(Object o) throws ClassCastException { - int pdiff = ((Piece)o).priority - this.priority; // reverse + public int compareTo(Piece op) { + int pdiff = op.priority - this.priority; // reverse if (pdiff != 0) return pdiff; - return this.peers.size() - ((Piece)o).peers.size(); + return this.peers.size() - op.peers.size(); } @Override