forked from I2P_Developers/i2p.i2p
i2psnark: Comparable type arguments
This commit is contained in:
@ -31,7 +31,7 @@ import net.i2p.util.SecureFile;
|
||||
*
|
||||
* @since 0.8.2
|
||||
*/
|
||||
class PartialPiece implements Comparable {
|
||||
class PartialPiece implements Comparable<PartialPiece> {
|
||||
|
||||
// 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;
|
||||
|
@ -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<Peer>
|
||||
{
|
||||
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);
|
||||
|
@ -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<PeerID>
|
||||
{
|
||||
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<String, BEValue> 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;
|
||||
|
@ -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<Piece> {
|
||||
|
||||
private final int id;
|
||||
private final Set<PeerID> 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
|
||||
|
Reference in New Issue
Block a user