- break;
-
- case EXPECTING_TRANSACTION:
- if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
- m = reTransactionStart.matcher(line);
- if (m.find()) {
- transactionId = Integer.valueOf(m.group(1));
- state = ParserState.EXPECTING_TRANSACTION_DESCRIPTION;
- L(String.format("found transaction %d → expecting description",
- transactionId));
- progress.setProgress(++processedTransactionCount);
- if (maxTransactionId < transactionId)
- maxTransactionId = transactionId;
- if ((progress.getTotal() == Progress.INDETERMINATE) ||
- (progress.getTotal() < transactionId))
- progress.setTotal(transactionId);
- publishProgress(progress);
- }
- m = reEnd.matcher(line);
- if (m.find()) {
- L("--- transaction value complete ---");
- break LINES;
- }
- break;
-
- case EXPECTING_TRANSACTION_DESCRIPTION:
- if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
- m = reTransactionDescription.matcher(line);
- if (m.find()) {
- if (transactionId == 0) throw new TransactionParserException(
- "Transaction Id is 0 while expecting " + "description");
-
- String date = m.group(1);
- try {
- int equalsIndex = date.indexOf('=');
- if (equalsIndex >= 0)
- date = date.substring(equalsIndex + 1);
- transaction = new LedgerTransaction(transactionId, date,
- m.group(2));
- }
- catch (ParseException e) {
- e.printStackTrace();
- return String.format("Error parsing date '%s'", date);
- }
- state = ParserState.EXPECTING_TRANSACTION_DETAILS;
- L(String.format("transaction %d created for %s (%s) →" +
- " expecting details", transactionId, date,
- m.group(2)));
- }
- break;
-
- case EXPECTING_TRANSACTION_DETAILS:
- if (line.isEmpty()) {
- // transaction data collected
- if (transaction.existsInDb(db)) {
- profile.markTransactionAsPresent(db, transaction);
- matchedTransactionsCount++;
-
- if (matchedTransactionsCount ==
- MATCHING_TRANSACTIONS_LIMIT)
- {
- profile.markTransactionsBeforeTransactionAsPresent(db,
- transaction);
- progress.setTotal(progress.getProgress());
- publishProgress(progress);
- break LINES;
- }
- }
- else {
- profile.storeTransaction(db, transaction);
- matchedTransactionsCount = 0;
- progress.setTotal(maxTransactionId);
- }
-
- state = ParserState.EXPECTING_TRANSACTION;
- L(String.format("transaction %s saved → expecting transaction",
- transaction.getId()));
- transaction.finishLoading();
+ if (match_found) {
+ syntheticAccounts.clear();
+ state = ParserState.EXPECTING_ACCOUNT;
+ L("→ expecting account");
+ }
+
+ break;
+
+ case EXPECTING_TRANSACTION:
+ if (!line.isEmpty() && (line.charAt(0) == ' '))
+ continue;
+ m = reTransactionStart.matcher(line);
+ if (m.find()) {
+ transactionId = Integer.parseInt(Objects.requireNonNull(m.group(1)));
+ state = ParserState.EXPECTING_TRANSACTION_DESCRIPTION;
+ L(String.format(Locale.ENGLISH,
+ "found transaction %d → expecting description", transactionId));
+ progress.setProgress(++processedTransactionCount);
+ if (maxTransactionId < transactionId)
+ maxTransactionId = transactionId;
+ if ((progress.isIndeterminate()) ||
+ (progress.getTotal() < transactionId))
+ progress.setTotal(transactionId);
+ publishProgress(progress);
+ }
+ m = reEnd.matcher(line);
+ if (m.find()) {
+ L("--- transaction value complete ---");
+ break LINES;
+ }
+ break;
+
+ case EXPECTING_TRANSACTION_DESCRIPTION:
+ if (!line.isEmpty() && (line.charAt(0) == ' '))
+ continue;
+ m = reTransactionDescription.matcher(line);
+ if (m.find()) {
+ if (transactionId == 0)
+ throw new TransactionParserException(
+ "Transaction Id is 0 while expecting description");
+
+ String date = Objects.requireNonNull(m.group(1));
+ try {
+ int equalsIndex = date.indexOf('=');
+ if (equalsIndex >= 0)
+ date = date.substring(equalsIndex + 1);
+ transaction =
+ new LedgerTransaction(transactionId, date, m.group(2));
+ }
+ catch (ParseException e) {
+ throw new TransactionParserException(
+ String.format("Error parsing date '%s'", date));
+ }
+ state = ParserState.EXPECTING_TRANSACTION_DETAILS;
+ L(String.format(Locale.ENGLISH,
+ "transaction %d created for %s (%s) →" + " expecting details",
+ transactionId, date, m.group(2)));
+ }
+ break;
+
+ case EXPECTING_TRANSACTION_DETAILS:
+ if (line.isEmpty()) {
+ // transaction data collected
+
+ transaction.finishLoading();
+ transactions.add(transaction);
+
+ state = ParserState.EXPECTING_TRANSACTION;
+ L(String.format("transaction %s parsed → expecting transaction",
+ transaction.getLedgerId()));