]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix storing/retrieval of currency position
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 17 Sep 2020 07:25:04 +0000 (07:25 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 17 Sep 2020 13:25:07 +0000 (13:25 +0000)
no need of trickery. standard enum has it all

app/src/main/java/net/ktnx/mobileledger/model/Currency.java
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java

index f332f001667cf1e83cff65571271dcb141847c2c..5f488e28634eb4ca72a156b05371be075747c0af 100644 (file)
@@ -119,22 +119,6 @@ public class Currency {
         this.hasGap = hasGap;
     }
     public enum Position {
-        before(-1), after(1), unknown(0), none(-2);
-        Position(int value) {
-        }
-        static Position valueOf(int value) {
-            switch (value) {
-                case -1:
-                    return before;
-                case +1:
-                    return after;
-                case 0:
-                    return unknown;
-                case -2:
-                    return none;
-                default:
-                    throw new IllegalStateException(String.format("Unexpected value (%d)", value));
-            }
-        }
+        before, after, unknown, none
     }
 }
index 229e53483979a7927d5184df36d46952a8059089..4ac99fe14ad0149dffd985c7dc666c34710ac7a6 100644 (file)
@@ -527,7 +527,7 @@ public final class MobileLedgerProfile {
         {
             while (c.moveToNext()) {
                 Currency currency = new Currency(c.getInt(0), c.getString(1),
-                        Currency.Position.valueOf(c.getInt(2)), c.getInt(3) == 1);
+                        Currency.Position.valueOf(c.getString(2)), c.getInt(3) == 1);
                 result.add(currency);
             }
         }
@@ -548,7 +548,7 @@ public final class MobileLedgerProfile {
         {
             if (cursor.moveToFirst()) {
                 return new Currency(cursor.getInt(0), cursor.getString(1),
-                        Currency.Position.valueOf(cursor.getInt(2)), cursor.getInt(3) == 1);
+                        Currency.Position.valueOf(cursor.getString(2)), cursor.getInt(3) == 1);
             }
             return null;
         }