From 1d029c31114c45fe633b9a58f84f23b187cd3dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20R=2E=20P=C3=A9rez?= Date: Thu, 12 Mar 2020 17:59:01 -0500 Subject: [PATCH] Making the AssetAmount class implement the Comparable interface --- .../main/java/cy/agorise/graphenej/AssetAmount.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java b/graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java index 37d087a..71b24c9 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java @@ -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 { /** * 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. */