mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-18 21:25:49 +00:00
Sha256Hash: Fix compareTo() not being consistent with equals().
This commit is contained in:
parent
1eaf05cacf
commit
4b75c336bb
@ -266,8 +266,15 @@ public class Sha256Hash implements Serializable, Comparable<Sha256Hash> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Sha256Hash o) {
|
public int compareTo(final Sha256Hash other) {
|
||||||
// note that in this implementation compareTo() is not consistent with equals()
|
for (int i = 31; i >= 0; i--) {
|
||||||
return this.hashCode() - o.hashCode(); // arbitrary but consistent
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user