i2psnark: Comparable type arguments

This commit is contained in:
str4d
2013-11-26 21:09:36 +00:00
parent c59ef24acf
commit 8770d7eae0
4 changed files with 13 additions and 16 deletions

View File

@ -31,7 +31,7 @@ import net.i2p.util.SecureFile;
* *
* @since 0.8.2 * @since 0.8.2
*/ */
class PartialPiece implements Comparable { class PartialPiece implements Comparable<PartialPiece> {
// we store the piece so we can use it in compareTo() // we store the piece so we can use it in compareTo()
private final Piece piece; private final Piece piece;
@ -295,8 +295,7 @@ class PartialPiece implements Comparable {
* then rarest first, * then rarest first,
* then highest downloaded first * then highest downloaded first
*/ */
public int compareTo(Object o) throws ClassCastException { public int compareTo(PartialPiece opp) {
PartialPiece opp = (PartialPiece)o;
int d = this.piece.compareTo(opp.piece); int d = this.piece.compareTo(opp.piece);
if (d != 0) if (d != 0)
return d; return d;

View File

@ -39,7 +39,7 @@ import net.i2p.util.Log;
import org.klomp.snark.bencode.BEValue; import org.klomp.snark.bencode.BEValue;
public class Peer implements Comparable public class Peer implements Comparable<Peer>
{ {
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(Peer.class); private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(Peer.class);
// Identifying property, the peer id of the other side. // Identifying property, the peer id of the other side.
@ -194,7 +194,7 @@ public class Peer implements Comparable
* Compares the PeerIDs. * Compares the PeerIDs.
* @deprecated unused? * @deprecated unused?
*/ */
public int compareTo(Object o) public int compareTo(Peer o)
{ {
Peer p = (Peer)o; Peer p = (Peer)o;
int rv = peerID.compareTo(p.peerID); int rv = peerID.compareTo(p.peerID);

View File

@ -42,7 +42,7 @@ import org.klomp.snark.bencode.InvalidBEncodingException;
* and the PeerID is not required. * and the PeerID is not required.
* Equality is now determined solely by the dest hash. * Equality is now determined solely by the dest hash.
*/ */
class PeerID implements Comparable class PeerID implements Comparable<PeerID>
{ {
private byte[] id; private byte[] id;
private Destination address; private Destination address;
@ -76,15 +76,15 @@ class PeerID implements Comparable
* Creates a PeerID from a Map containing BEncoded peer id, ip and * Creates a PeerID from a Map containing BEncoded peer id, ip and
* port. * port.
*/ */
public PeerID(Map m) public PeerID(Map<String, BEValue> m)
throws InvalidBEncodingException, UnknownHostException throws InvalidBEncodingException, UnknownHostException
{ {
BEValue bevalue = (BEValue)m.get("peer id"); BEValue bevalue = m.get("peer id");
if (bevalue == null) if (bevalue == null)
throw new InvalidBEncodingException("peer id missing"); throw new InvalidBEncodingException("peer id missing");
id = bevalue.getBytes(); id = bevalue.getBytes();
bevalue = (BEValue)m.get("ip"); bevalue = m.get("ip");
if (bevalue == null) if (bevalue == null)
throw new InvalidBEncodingException("ip missing"); throw new InvalidBEncodingException("ip missing");
address = I2PSnarkUtil.getDestinationFromBase64(bevalue.getString()); address = I2PSnarkUtil.getDestinationFromBase64(bevalue.getString());
@ -195,10 +195,8 @@ class PeerID implements Comparable
* Compares port, address and id. * Compares port, address and id.
* @deprecated unused? and will NPE now that address can be null? * @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; int result = port - pid.port;
if (result != 0) if (result != 0)
return result; return result;

View File

@ -7,7 +7,7 @@ import java.util.Set;
* This class is used solely by PeerCoordinator. * This class is used solely by PeerCoordinator.
* Caller must synchronize on many of these methods. * Caller must synchronize on many of these methods.
*/ */
class Piece implements Comparable { class Piece implements Comparable<Piece> {
private final int id; private final int id;
private final Set<PeerID> peers; private final Set<PeerID> peers;
@ -26,11 +26,11 @@ class Piece implements Comparable {
* Highest priority first, * Highest priority first,
* then rarest first * then rarest first
*/ */
public int compareTo(Object o) throws ClassCastException { public int compareTo(Piece op) {
int pdiff = ((Piece)o).priority - this.priority; // reverse int pdiff = op.priority - this.priority; // reverse
if (pdiff != 0) if (pdiff != 0)
return pdiff; return pdiff;
return this.peers.size() - ((Piece)o).peers.size(); return this.peers.size() - op.peers.size();
} }
@Override @Override