3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 03:35:52 +00:00

Sha256Hash: Fix compareTo() not being consistent with equals().

This commit is contained in:
Andreas Schildbach 2016-03-07 11:42:41 +01:00
parent 1eaf05cacf
commit 4b75c336bb

View File

@ -266,8 +266,15 @@ public class Sha256Hash implements Serializable, Comparable<Sha256Hash> {
}
@Override
public int compareTo(Sha256Hash o) {
// note that in this implementation compareTo() is not consistent with equals()
return this.hashCode() - o.hashCode(); // arbitrary but consistent
public int compareTo(final Sha256Hash other) {
for (int i = 31; i >= 0; i--) {
final int thisByte = this.bytes[i] & 0xff;
final int otherByte = other.bytes[i] & 0xff;
if (thisByte > otherByte)
return 1;
if (thisByte < otherByte)
return -1;
}
return 0;
}
}