From: Damyan Ivanov Date: Wed, 2 Jan 2019 20:44:51 +0000 (+0000) Subject: use enum for the parser state X-Git-Tag: v0.3~140 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=1c5029961976470f2a7691f8dd9bb52a591a6467;p=mobile-ledger.git use enum for the parser state --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index e3f50cc3..0768817e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -110,7 +110,7 @@ public class RetrieveTransactionsTask extends try { db.execSQL("UPDATE transactions set keep=0"); - int state = ParserState.EXPECTING_JOURNAL; + ParserState state = ParserState.EXPECTING_JOURNAL; String line; BufferedReader buf = new BufferedReader(new InputStreamReader(resp, "UTF-8")); @@ -125,14 +125,14 @@ public class RetrieveTransactionsTask extends Matcher m; //L(String.format("State is %d", state)); switch (state) { - case ParserState.EXPECTING_JOURNAL: + case EXPECTING_JOURNAL: if (!line.isEmpty() && (line.charAt(0) == ' ')) continue; if (line.equals("

General Journal

")) { state = ParserState.EXPECTING_TRANSACTION; L("→ expecting transaction"); } break; - case ParserState.EXPECTING_TRANSACTION: + case EXPECTING_TRANSACTION: if (!line.isEmpty() && (line.charAt(0) == ' ')) continue; m = transactionStartPattern.matcher(line); if (m.find()) { @@ -156,7 +156,7 @@ public class RetrieveTransactionsTask extends break LINES; } break; - case ParserState.EXPECTING_TRANSACTION_DESCRIPTION: + case EXPECTING_TRANSACTION_DESCRIPTION: if (!line.isEmpty() && (line.charAt(0) == ' ')) continue; m = transactionDescriptionPattern.matcher(line); if (m.find()) { @@ -174,7 +174,7 @@ public class RetrieveTransactionsTask extends m.group(1), m.group(2))); } break; - case ParserState.EXPECTING_TRANSACTION_DETAILS: + case EXPECTING_TRANSACTION_DETAILS: if (line.isEmpty()) { // transaction data collected if (transaction.existsInDb(db)) { @@ -235,7 +235,7 @@ public class RetrieveTransactionsTask extends break; default: throw new RuntimeException( - String.format("Unknown parser state %d", state)); + String.format("Unknown parser state %s", state.name())); } } if (!isCancelled()) { @@ -274,6 +274,11 @@ public class RetrieveTransactionsTask extends return contextRef.get(); } + private enum ParserState { + EXPECTING_JOURNAL, EXPECTING_TRANSACTION, EXPECTING_TRANSACTION_DESCRIPTION, + EXPECTING_TRANSACTION_DETAILS + } + public static class Params { private SharedPreferences backendPref; @@ -315,11 +320,4 @@ public class RetrieveTransactionsTask extends super(message); } } - - private class ParserState { - static final int EXPECTING_JOURNAL = 0; - static final int EXPECTING_TRANSACTION = 1; - static final int EXPECTING_TRANSACTION_DESCRIPTION = 2; - static final int EXPECTING_TRANSACTION_DETAILS = 3; - } }