X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FPatternDetailsItem.java;h=eeab37aed6a53431cda383e8c0067063e41ac533;hb=1688588d70ab1f75c0369080087af46958aacbbe;hp=43c77f72e5ff7416041a20383df421c71c4be4b0;hpb=b0404689e0dbb2b08f02deca7ee5d14636a3baa6;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java b/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java index 43c77f72..eeab37ae 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java @@ -61,11 +61,32 @@ abstract public class PatternDetailsItem { header.setName(ph.getName()); header.setPattern(ph.getRegularExpression()); header.setTestText(ph.getTestText()); - header.setTransactionDescription(ph.getTransactionDescription()); - header.setTransactionComment(ph.getTransactionComment()); - header.setDateDayMatchGroup(ph.getDateDayMatchGroup()); - header.setDateMonthMatchGroup(ph.getDateMonthMatchGroup()); - header.setDateYearMatchGroup(ph.getDateYearMatchGroup()); + + if (ph.getTransactionDescriptionMatchGroup() == null) + header.setTransactionDescription(ph.getTransactionDescription()); + else + header.setTransactionDescriptionMatchGroup( + ph.getTransactionDescriptionMatchGroup()); + + if (ph.getTransactionCommentMatchGroup() == null) + header.setTransactionComment(ph.getTransactionComment()); + else + header.setTransactionCommentMatchGroup(ph.getTransactionCommentMatchGroup()); + + if (ph.getDateDayMatchGroup() == null) + header.setDateDay(ph.getDateDay()); + else + header.setDateDayMatchGroup(ph.getDateDayMatchGroup()); + + if (ph.getDateMonthMatchGroup() == null) + header.setDateMonth(ph.getDateMonth()); + else + header.setDateMonthMatchGroup(ph.getDateMonthMatchGroup()); + + if (ph.getDateYearMatchGroup() == null) + header.setDateYear(ph.getDateYear()); + else + header.setDateYearMatchGroup(ph.getDateYearMatchGroup()); return header; } @@ -93,8 +114,11 @@ abstract public class PatternDetailsItem { acc.setCurrencyMatchGroup(pa.getCurrencyMatchGroup()); final Integer amountMatchGroup = pa.getAmountMatchGroup(); - if (amountMatchGroup != null && amountMatchGroup > 0) + if (amountMatchGroup != null && amountMatchGroup > 0) { acc.setAmountMatchGroup(amountMatchGroup); + final Boolean negateAmount = pa.getNegateAmount(); + acc.setNegateAmount(negateAmount != null && negateAmount); + } else acc.setAmount(pa.getAmount()); @@ -228,6 +252,16 @@ abstract public class PatternDetailsItem { public void switchToLiteral() { literalValue = true; } + public String toString() { + if (literalValue) + if (value == null) + return ""; + else + return value.toString(); + if (matchGroup > 0) + return "grp:" + matchGroup; + return ""; + } } public static class TYPE { @@ -243,9 +277,16 @@ abstract public class PatternDetailsItem { private final PossiblyMatchedValue amount = PossiblyMatchedValue.withLiteralFloat(0f); private final PossiblyMatchedValue currency = new PossiblyMatchedValue<>(); + private boolean negateAmount; private AccountRow() { super(Type.ACCOUNT_ITEM); } + public boolean isNegateAmount() { + return negateAmount; + } + public void setNegateAmount(boolean negateAmount) { + this.negateAmount = negateAmount; + } public int getAccountCommentMatchGroup() { return accountComment.getMatchGroup(); } @@ -312,7 +353,7 @@ abstract public class PatternDetailsItem { } public boolean equalContents(AccountRow o) { return amount.equals(o.amount) && accountName.equals(o.accountName) && - accountComment.equals(o.accountComment); + accountComment.equals(o.accountComment) && negateAmount == o.negateAmount; } public void switchToLiteralAmount() { amount.switchToLiteral(); @@ -336,10 +377,14 @@ abstract public class PatternDetailsItem { else result.setAccountCommentMatchGroup(accountComment.getMatchGroup()); - if (amount.hasLiteralValue()) + if (amount.hasLiteralValue()) { result.setAmount(amount.getValue()); - else + result.setNegateAmount(null); + } + else { result.setAmountMatchGroup(amount.getMatchGroup()); + result.setNegateAmount(negateAmount ? true : null); + } return result; } @@ -404,7 +449,8 @@ abstract public class PatternDetailsItem { @Override public String toString() { return super.toString() + - String.format(" name[%s] pat[%s] test[%s]", name, pattern, testText); + String.format(" name[%s] pat[%s] test[%s] tran[%s] com[%s]", name, pattern, + testText, transactionDescription, transactionComment); } public String getTestText() { return testText; @@ -528,13 +574,13 @@ abstract public class PatternDetailsItem { public int getTransactionDescriptionMatchGroup() { return transactionDescription.getMatchGroup(); } - public void setTransactionDescriptionMatchGroup(short group) { + public void setTransactionDescriptionMatchGroup(int group) { transactionDescription.setMatchGroup(group); } public int getTransactionCommentMatchGroup() { return transactionComment.getMatchGroup(); } - public void setTransactionCommentMatchGroup(short group) { + public void setTransactionCommentMatchGroup(int group) { transactionComment.setMatchGroup(group); } public void switchToLiteralDateYear() {