--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class AccountListParser {
+
+ private final MappingIterator<ParsedLedgerAccount> iter;
+
+ public AccountListParser(InputStream input) throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectReader reader = mapper.readerFor(ParsedLedgerAccount.class);
+
+ iter = reader.readValues(input);
+ }
+ public ParsedLedgerAccount nextAccount() throws IOException {
+ return iter.hasNext() ? iter.next() : null;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedAmount {
+ private String acommodity;
+ private ParsedQuantity aquantity;
+ private boolean aismultiplier;
+ private ParsedStyle astyle;
+ public ParsedAmount() {
+ }
+ public String getAcommodity() {
+ return acommodity;
+ }
+ public void setAcommodity(String acommodity) {
+ this.acommodity = acommodity;
+ }
+ public ParsedQuantity getAquantity() {
+ return aquantity;
+ }
+ public void setAquantity(ParsedQuantity aquantity) {
+ this.aquantity = aquantity;
+ }
+ public boolean isAismultiplier() {
+ return aismultiplier;
+ }
+ public void setAismultiplier(boolean aismultiplier) {
+ this.aismultiplier = aismultiplier;
+ }
+ public ParsedStyle getAstyle() {
+ return astyle;
+ }
+ public void setAstyle(ParsedStyle astyle) {
+ this.astyle = astyle;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedBalance {
+ private ParsedQuantity aquantity;
+ private String acommodity;
+ private ParsedStyle astyle;
+ public ParsedBalance() {
+ }
+ public ParsedQuantity getAquantity() {
+ return aquantity;
+ }
+ public void setAquantity(ParsedQuantity aquantity) {
+ this.aquantity = aquantity;
+ }
+ public String getAcommodity() {
+ return acommodity;
+ }
+ public void setAcommodity(String acommodity) {
+ this.acommodity = acommodity;
+ }
+ public ParsedStyle getAstyle() {
+ return astyle;
+ }
+ public void setAstyle(ParsedStyle astyle) {
+ this.astyle = astyle;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedLedgerAccount {
+ private List<ParsedBalance> aebalance;
+ private String aname;
+ public ParsedLedgerAccount() {
+ }
+ public List<ParsedBalance> getAebalance() {
+ return aebalance;
+ }
+ public void setAebalance(List<ParsedBalance> aebalance) {
+ this.aebalance = aebalance;
+ }
+ public String getAname() {
+ return aname;
+ }
+ public void setAname(String aname) {
+ this.aname = aname;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import net.ktnx.mobileledger.model.LedgerTransaction;
+import net.ktnx.mobileledger.utils.Globals;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedLedgerTransaction {
+ private String tdate, tdate2, tdescription, tcomment;
+ private int tindex;
+ private List<ParsedPosting> tpostings;
+ public ParsedLedgerTransaction() {
+ }
+ public String getTdate() {
+ return tdate;
+ }
+ public void setTdate(String tdate) {
+ this.tdate = tdate;
+ }
+ public String getTdate2() {
+ return tdate2;
+ }
+ public void setTdate2(String tdate2) {
+ this.tdate2 = tdate2;
+ }
+ public String getTdescription() {
+ return tdescription;
+ }
+ public void setTdescription(String tdescription) {
+ this.tdescription = tdescription;
+ }
+ public String getTcomment() {
+ return tcomment;
+ }
+ public void setTcomment(String tcomment) {
+ this.tcomment = tcomment;
+ }
+ public int getTindex() {
+ return tindex;
+ }
+ public void setTindex(int tindex) {
+ this.tindex = tindex;
+ }
+ public List<ParsedPosting> getTpostings() {
+ return tpostings;
+ }
+ public void setTpostings(List<ParsedPosting> tpostings) {
+ this.tpostings = tpostings;
+ }
+ public LedgerTransaction asLedgerTransaction() throws ParseException {
+ Date date = Globals.parseIsoDate(tdate);
+ LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
+
+ List<ParsedPosting> postings = tpostings;
+
+ if (postings != null) {
+ for (ParsedPosting p : postings) {
+ tr.addAccount(p.asLedgerAccount());
+ }
+ }
+ return tr;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedPosting {
+ private String paccount;
+ private List<ParsedAmount> pamount;
+ public ParsedPosting() {
+ }
+ public String getPaccount() {
+ return paccount;
+ }
+ public void setPaccount(String paccount) {
+ this.paccount = paccount;
+ }
+ public List<ParsedAmount> getPamount() {
+ return pamount;
+ }
+ public void setPamount(List<ParsedAmount> pamount) {
+ this.pamount = pamount;
+ }
+ public LedgerTransactionAccount asLedgerAccount() {
+ ParsedAmount amt = pamount.get(0);
+ return new LedgerTransactionAccount(paccount, amt.getAquantity().asFloat(),
+ amt.getAcommodity());
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedQuantity {
+ private long decimalMantissa;
+ private int decimalPlaces;
+ public ParsedQuantity() {
+ }
+ public long getDecimalMantissa() {
+ return decimalMantissa;
+ }
+ public void setDecimalMantissa(long decimalMantissa) {
+ this.decimalMantissa = decimalMantissa;
+ }
+ public int getDecimalPlaces() {
+ return decimalPlaces;
+ }
+ public void setDecimalPlaces(int decimalPlaces) {
+ this.decimalPlaces = decimalPlaces;
+ }
+ public float asFloat() {
+ return (float) (decimalMantissa * Math.pow(10, -decimalPlaces));
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ParsedStyle {
+ private int asprecision;
+ private char asdecimalpoint;
+ private char ascommodityside;
+ private int digitgroups;
+ private boolean ascommodityspaced;
+ public ParsedStyle() {
+ }
+ public int getAsprecision() {
+ return asprecision;
+ }
+ public void setAsprecision(int asprecision) {
+ this.asprecision = asprecision;
+ }
+ public char getAsdecimalpoint() {
+ return asdecimalpoint;
+ }
+ public void setAsdecimalpoint(char asdecimalpoint) {
+ this.asdecimalpoint = asdecimalpoint;
+ }
+ public char getAscommodityside() {
+ return ascommodityside;
+ }
+ public void setAscommodityside(char ascommodityside) {
+ this.ascommodityside = ascommodityside;
+ }
+ public int getDigitgroups() {
+ return digitgroups;
+ }
+ public void setDigitgroups(int digitgroups) {
+ this.digitgroups = digitgroups;
+ }
+ public boolean isAscommodityspaced() {
+ return ascommodityspaced;
+ }
+ public void setAscommodityspaced(boolean ascommodityspaced) {
+ this.ascommodityspaced = ascommodityspaced;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2019 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import com.fasterxml.jackson.databind.MappingIterator;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class TransactionListParser {
+
+ private final MappingIterator<ParsedLedgerTransaction> iter;
+
+ public TransactionListParser(InputStream input) throws IOException {
+
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectReader reader = mapper.readerFor(ParsedLedgerTransaction.class);
+ iter = reader.readValues(input);
+ }
+ public ParsedLedgerTransaction nextTransaction() {
+ return iter.hasNext() ? iter.next() : null;
+ }
+}