]> git.ktnx.net Git - mobile-ledger-staging.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java
remove references to style members from the parser classes
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / json / v1_15 / ParsedPosting.java
index 0789f0d9fbd8e43fea1c6afec1a1d9699e507f70..d773420ef1cf4c7be20263d6a87edce6591e2f6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -25,32 +25,55 @@ import java.util.ArrayList;
 import java.util.List;
 
 @JsonIgnoreProperties(ignoreUnknown = true)
-public class ParsedPosting {
+public class ParsedPosting extends net.ktnx.mobileledger.json.ParsedPosting {
     private Void pbalanceassertion;
     private String pstatus = "Unmarked";
     private String paccount;
     private List<ParsedAmount> pamount;
     private String pdate = null;
-    public String getPdate2() {
-        return pdate2;
-    }
-    public void setPdate2(String pdate2) {
-        this.pdate2 = pdate2;
-    }
     private String pdate2 = null;
     private String ptype = "RegularPosting";
     private String pcomment = "";
     private List<List<String>> ptags = new ArrayList<>();
     private String poriginal = null;
     private int ptransaction_;
+    public ParsedPosting() {
+    }
+    public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) {
+        ParsedPosting result = new ParsedPosting();
+        result.setPaccount(acc.getAccountName());
+
+        String comment = acc.getComment();
+        if (comment == null)
+            comment = "";
+        result.setPcomment(comment);
+
+        ArrayList<ParsedAmount> amounts = new ArrayList<>();
+        ParsedAmount amt = new ParsedAmount();
+        amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency());
+        amt.setAismultiplier(false);
+        ParsedQuantity qty = new ParsedQuantity();
+        qty.setDecimalPlaces(2);
+        qty.setDecimalMantissa(Math.round(acc.getAmount() * 100));
+        amt.setAquantity(qty);
+        if (acc.getCurrency() != null)
+            amt.setAcommodity(acc.getCurrency());
+        amounts.add(amt);
+        result.setPamount(amounts);
+        return result;
+    }
+    public String getPdate2() {
+        return pdate2;
+    }
+    public void setPdate2(String pdate2) {
+        this.pdate2 = pdate2;
+    }
     public int getPtransaction_() {
         return ptransaction_;
     }
     public void setPtransaction_(int ptransaction_) {
         this.ptransaction_ = ptransaction_;
     }
-    public ParsedPosting() {
-    }
     public String getPdate() {
         return pdate;
     }
@@ -67,7 +90,7 @@ public class ParsedPosting {
         return pcomment;
     }
     public void setPcomment(String pcomment) {
-        this.pcomment = pcomment;
+        this.pcomment = (pcomment == null) ? null : pcomment.trim();
     }
     public List<List<String>> getPtags() {
         return ptags;
@@ -107,35 +130,9 @@ public class ParsedPosting {
     }
     public LedgerTransactionAccount asLedgerAccount() {
         ParsedAmount amt = pamount.get(0);
-        return new LedgerTransactionAccount(paccount, amt.getAquantity().asFloat(),
-                amt.getAcommodity());
-    }
-    public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) {
-        ParsedPosting result = new ParsedPosting();
-        result.setPaccount(acc.getAccountName());
-
-        String comment = acc.getComment();
-        if (comment == null)
-            comment = "";
-        result.setPcomment(comment);
-
-        ArrayList<ParsedAmount> amounts = new ArrayList<>();
-        ParsedAmount amt = new ParsedAmount();
-        amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency());
-        amt.setAismultiplier(false);
-        ParsedQuantity qty = new ParsedQuantity();
-        qty.setDecimalPlaces(2);
-        qty.setDecimalMantissa(Math.round(acc.getAmount() * 100));
-        amt.setAquantity(qty);
-        ParsedStyle style = new ParsedStyle();
-        style.setAscommodityside('L');
-        style.setAscommodityspaced(false);
-        style.setAsprecision(2);
-        style.setAsdecimalpoint('.');
-        amt.setAstyle(style);
-        amounts.add(amt);
-        result.setPamount(amounts);
-        return result;
+        return new LedgerTransactionAccount(paccount, amt.getAquantity()
+                                                         .asFloat(), amt.getAcommodity(),
+                getPcomment());
     }
 
 }