Making the AssetAmount class implement the Comparable<AssetAmount> interface

feat_callback_support
Nelson R. Pérez 2020-03-12 17:59:01 -05:00
parent bba825ca62
commit 1d029c3111
1 changed files with 9 additions and 1 deletions

View File

@ -27,7 +27,7 @@ import cy.agorise.graphenej.interfaces.JsonSerializable;
/**
* Class used to represent a specific amount of a certain asset
*/
public class AssetAmount implements ByteSerializable, JsonSerializable {
public class AssetAmount implements ByteSerializable, JsonSerializable, Comparable<AssetAmount> {
/**
* Constants used in the JSON serialization procedure.
*/
@ -196,6 +196,14 @@ public class AssetAmount implements ByteSerializable, JsonSerializable {
return String.format("(asset=%s, amount=%s)", asset.getObjectId(), amount.toString(10));
}
@Override
public int compareTo(AssetAmount other) {
if(!other.asset.equals(this.asset)) throw new AssertionError("Cannot compare amounts of different assets");
if(this.amount == null) throw new NullPointerException("Asset amount field is null");
if(other.amount == null) throw new NullPointerException("Asser amount field is null");
return amount.compareTo(other.amount);
}
/**
* Custom serializer used to translate this object into the JSON-formatted entry we need for a transaction.
*/