mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
Implement dumb Comparable in Sha256Hash.
This commit is contained in:
parent
6cdfad43a3
commit
28292b45a5
@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
* A Sha256Hash just wraps a byte[] so that equals and hashcode work correctly, allowing it to be used as keys in a
|
||||
* map. It also checks that the length is correct and provides a bit more type safety.
|
||||
*/
|
||||
public class Sha256Hash implements Serializable {
|
||||
public class Sha256Hash implements Serializable, Comparable {
|
||||
private byte[] bytes;
|
||||
public static final Sha256Hash ZERO_HASH = new Sha256Hash(new byte[32]);
|
||||
|
||||
@ -127,4 +127,12 @@ public class Sha256Hash implements Serializable {
|
||||
public Sha256Hash duplicate() {
|
||||
return new Sha256Hash(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
checkArgument(o instanceof Sha256Hash);
|
||||
int thisCode = this.hashCode();
|
||||
int oCode = ((Sha256Hash)o).hashCode();
|
||||
return thisCode > oCode ? 1 : (thisCode == oCode ? 0 : -1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user