Implementing the equals and hashcode methods for the Authority class

master
Nelson R. Perez 2016-12-18 17:18:41 -05:00
parent f93f91fc1f
commit 5fa4d8667f
1 changed files with 22 additions and 1 deletions

View File

@ -61,7 +61,7 @@ public class Authority implements GrapheneSerializable {
this.account_auths = accountAuthorities;
}
public List<PublicKey> getKeyAuths(){
public List<PublicKey> getKeyAuthList(){
ArrayList<PublicKey> keys = new ArrayList<>();
for(PublicKey pk : key_auths.keySet()){
keys.add(pk);
@ -69,6 +69,14 @@ public class Authority implements GrapheneSerializable {
return keys;
}
public HashMap<PublicKey, Integer> getKeyAuths(){
return this.key_auths;
}
public HashMap<UserAccount, Integer> getAccountAuths(){
return this.account_auths;
}
@Override
public String toJsonString() {
return null;
@ -138,6 +146,19 @@ public class Authority implements GrapheneSerializable {
return Bytes.toArray(byteArray);
}
@Override
public boolean equals(Object obj) {
Authority authority = (Authority) obj;
HashMap<PublicKey, Integer> keyAuths = authority.getKeyAuths();
HashMap<UserAccount, Integer> accountAuths = authority.getAccountAuths();
System.out.println("key auths match: "+this.key_auths.equals(keyAuths));
System.out.println("account auths match: "+this.account_auths.equals(accountAuths));
System.out.println("weight threshold matches: "+(this.weight_threshold == authority.weight_threshold));
return this.key_auths.equals(keyAuths) &&
this.account_auths.equals(accountAuths) &&
this.weight_threshold == authority.weight_threshold;
}
/**
* Custom deserializer used while parsing the 'get_account_by_name' API call response.
*