]> git.ktnx.net Git - mobile-ledger.git/commitdiff
helper methids for comparing currency objects and strings
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 Apr 2020 20:30:27 +0000 (23:30 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 Apr 2020 20:30:27 +0000 (23:30 +0300)
app/src/main/java/net/ktnx/mobileledger/model/Currency.java

index 3cb70f8bd6cec7ea199a4d81f9bfdcf17828a4c2..e32513f2170a9ecba710631ea86a168df6f14ef7 100644 (file)
@@ -24,6 +24,7 @@ import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.DiffUtil;
 
 import net.ktnx.mobileledger.App;
+import net.ktnx.mobileledger.utils.Misc;
 
 public class Currency {
     public static final DiffUtil.ItemCallback<Currency> DIFF_CALLBACK =
@@ -104,6 +105,27 @@ public class Currency {
     public void setHasGap(boolean hasGap) {
         this.hasGap = hasGap;
     }
+    static public boolean equal(Currency left, Currency right) {
+        if (left == null) {
+            return right == null;
+        }
+        else
+            return left.equals(right);
+    }
+    static public boolean equal(Currency left, String right) {
+        right = Misc.emptyIsNull(right);
+        if (left == null) {
+            return right == null;
+        }
+        else {
+            String leftName = Misc.emptyIsNull(left.getName());
+            if (leftName == null) {
+                return right == null;
+            }
+            else
+                return leftName.equals(right);
+        }
+    }
     public enum Position {
         before(-1), after(1), unknown(0), none(-2);
         private int value;