abstract public class PatternDetailsItem {
private final Type type;
- protected long id;
- protected long position;
+ protected Long id;
+ protected Long position;
- protected PatternDetailsItem(Type type, long id, long position) {
+ protected PatternDetailsItem(Type type) {
this.type = type;
- this.id = (id <= 0) ? -position - 2 : id;
- this.position = position;
}
@Contract(" -> new")
public static @NotNull PatternDetailsItem.Header createHeader() {
public static @NotNull PatternDetailsItem.Header createHeader(Header origin) {
return new Header(origin);
}
- @Contract("_ -> new")
- public static @NotNull PatternDetailsItem.AccountRow createAccountRow(long position) {
- return new AccountRow(-1, position);
+ @Contract("-> new")
+ public static @NotNull PatternDetailsItem.AccountRow createAccountRow() {
+ return new AccountRow();
}
public static PatternDetailsItem fromRoomObject(PatternBase p) {
if (p instanceof PatternHeader) {
PatternHeader ph = (PatternHeader) p;
Header header = createHeader();
+ header.setId(ph.getId());
header.setName(ph.getName());
header.setPattern(ph.getRegularExpression());
- header.setTestText(null);
- header.setTransactionDescription(ph.getTransactionDescription());
- header.setTransactionComment(ph.getTransactionComment());
- header.setDateDayMatchGroup(ph.getDateDayMatchGroup());
- header.setDateMonthMatchGroup(ph.getDateMonthMatchGroup());
- header.setDateYearMatchGroup(ph.getDateYearMatchGroup());
+ header.setTestText(ph.getTestText());
+
+ 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;
}
else if (p instanceof PatternAccount) {
PatternAccount pa = (PatternAccount) p;
- AccountRow acc = createAccountRow(pa.getPosition());
+ AccountRow acc = createAccountRow();
+ acc.setId(pa.getId());
- if (Misc.emptyIsNull(pa.getAccountName()) != null)
- acc.setAccountName(pa.getAccountName());
+ if (pa.getAccountNameMatchGroup() == null)
+ acc.setAccountName(Misc.nullIsEmpty(pa.getAccountName()));
else
acc.setAccountNameMatchGroup(pa.getAccountNameMatchGroup());
- if (Misc.emptyIsNull(pa.getAccountComment()) == null)
- acc.setAccountCommentMatchGroup(pa.getAccountCommentMatchGroup());
+ if (pa.getAccountCommentMatchGroup() == null)
+ acc.setAccountComment(Misc.nullIsEmpty(pa.getAccountComment()));
else
- acc.setAccountComment(pa.getAccountComment());
+ acc.setAccountCommentMatchGroup(pa.getAccountCommentMatchGroup());
- if (pa.getCurrency() == null) {
- acc.setCurrencyMatchGroup(pa.getCurrencyMatchGroup());
- }
- else {
- acc.setCurrency(Currency.loadById(pa.getCurrency()));
+ if (pa.getCurrencyMatchGroup() == null) {
+ final Integer currencyId = pa.getCurrency();
+ if (currencyId != null && currencyId > 0)
+ acc.setCurrency(Currency.loadById(currencyId));
}
+ else
+ acc.setCurrencyMatchGroup(pa.getCurrencyMatchGroup());
- if (pa.getAmount() == null)
- acc.setAmountMatchGroup(pa.getAmountMatchGroup());
+ final Integer amountMatchGroup = pa.getAmountMatchGroup();
+ if (amountMatchGroup != null && amountMatchGroup > 0) {
+ acc.setAmountMatchGroup(amountMatchGroup);
+ final Boolean negateAmount = pa.getNegateAmount();
+ acc.setNegateAmount(negateAmount != null && negateAmount);
+ }
else
acc.setAmount(pa.getAmount());
public long getId() {
return id;
}
- public void setId(int id) {
+ public void setId(Long id) {
this.id = id;
}
+ public void setId(int id) {
+ this.id = (long) id;
+ }
public long getPosition() {
return position;
}
- public void setPosition(int position) {
+ public void setPosition(Long position) {
this.position = position;
}
abstract public String getProblem(@NonNull Resources r, int patternGroupCount);
matchGroup = origin.matchGroup;
}
@NonNull
- public static PossiblyMatchedValue<Integer> withLiteralInt(int initialValue) {
+ public static PossiblyMatchedValue<Integer> withLiteralInt(Integer initialValue) {
PossiblyMatchedValue<Integer> result = new PossiblyMatchedValue<>();
result.setValue(initialValue);
return result;
}
@NonNull
- public static PossiblyMatchedValue<Float> withLiteralFloat(float initialValue) {
+ public static PossiblyMatchedValue<Float> withLiteralFloat(Float initialValue) {
PossiblyMatchedValue<Float> result = new PossiblyMatchedValue<>();
result.setValue(initialValue);
return result;
}
- public static PossiblyMatchedValue<Short> withLiteralShort(short initialValue) {
+ public static PossiblyMatchedValue<Short> withLiteralShort(Short initialValue) {
PossiblyMatchedValue<Short> result = new PossiblyMatchedValue<>();
result.setValue(initialValue);
return result;
public boolean equals(PossiblyMatchedValue<T> other) {
if (!other.literalValue == literalValue)
return false;
- if (literalValue)
+ if (literalValue) {
+ if (value == null)
+ return other.value == null;
return value.equals(other.value);
+ }
else
return matchGroup == other.matchGroup;
}
public void switchToLiteral() {
literalValue = true;
}
+ public String toString() {
+ if (literalValue)
+ if (value == null)
+ return "<null>";
+ else
+ return value.toString();
+ if (matchGroup > 0)
+ return "grp:" + matchGroup;
+ return "<null>";
+ }
}
public static class TYPE {
private final PossiblyMatchedValue<Float> amount =
PossiblyMatchedValue.withLiteralFloat(0f);
private final PossiblyMatchedValue<Currency> currency = new PossiblyMatchedValue<>();
- private AccountRow(long id, long position) {
- super(Type.ACCOUNT_ITEM, id, position);
+ 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();
public void setAmountMatchGroup(int group) {
amount.setMatchGroup(group);
}
- public float getAmount() {
+ public Float getAmount() {
return amount.getValue();
}
- public void setAmount(float amount) {
+ public void setAmount(Float amount) {
this.amount.setValue(amount);
}
public String getProblem(@NonNull Resources r, int patternGroupCount) {
}
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();
accountComment.switchToLiteral();
}
public PatternAccount toDBO(@NonNull Long patternId) {
- PatternAccount result = new PatternAccount((id <= 0L) ? null : id, patternId, position);
+ PatternAccount result = new PatternAccount(id, patternId, position);
if (accountName.hasLiteralValue())
result.setAccountName(accountName.getValue());
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;
}
PossiblyMatchedValue.withLiteralString("");
private PossiblyMatchedValue<String> transactionComment =
PossiblyMatchedValue.withLiteralString("");
- private PossiblyMatchedValue<Short> dateYear =
- PossiblyMatchedValue.withLiteralShort((short) 0);
- private PossiblyMatchedValue<Short> dateMonth =
- PossiblyMatchedValue.withLiteralShort((short) 0);
- private PossiblyMatchedValue<Short> dateDay =
- PossiblyMatchedValue.withLiteralShort((short) 0);
+ private PossiblyMatchedValue<Integer> dateYear = PossiblyMatchedValue.withLiteralInt(null);
+ private PossiblyMatchedValue<Integer> dateMonth = PossiblyMatchedValue.withLiteralInt(null);
+ private PossiblyMatchedValue<Integer> dateDay = PossiblyMatchedValue.withLiteralInt(null);
private Header() {
- super(Type.HEADER, -1, -1);
+ super(Type.HEADER);
}
public Header(Header origin) {
this();
+ id = origin.id;
name = origin.name;
testText = origin.testText;
setPattern(origin.pattern);
@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;
public void setTransactionComment(String transactionComment) {
this.transactionComment.setValue(transactionComment);
}
- public short getDateYear() {
+ public Integer getDateYear() {
return dateYear.getValue();
}
- public void setDateYear(short dateYear) {
+ public void setDateYear(Integer dateYear) {
this.dateYear.setValue(dateYear);
}
- public short getDateMonth() {
+ public Integer getDateMonth() {
return dateMonth.getValue();
}
- public void setDateMonth(short dateMonth) {
+ public void setDateMonth(Integer dateMonth) {
this.dateMonth.setValue(dateMonth);
}
- public short getDateDay() {
+ public Integer getDateDay() {
return dateDay.getValue();
}
- public void setDateDay(short dateDay) {
+ public void setDateDay(Integer dateDay) {
this.dateDay.setValue(dateDay);
}
public int getDateYearMatchGroup() {
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() {
}
public void switchToLiteralDateDay() { dateDay.switchToLiteral(); }
public PatternHeader toDBO() {
- PatternHeader result =
- new PatternHeader((id <= 0) ? null : id, name, position, pattern);
+ PatternHeader result = new PatternHeader(id, name, pattern);
+
+ if (Misc.emptyIsNull(testText) != null)
+ result.setTestText(testText);
+
if (transactionDescription.hasLiteralValue())
result.setTransactionDescription(transactionDescription.getValue());
else
else
result.setTransactionCommentMatchGroup(transactionComment.getMatchGroup());
+ if (dateYear.hasLiteralValue())
+ result.setDateYear(dateYear.getValue());
+ else
+ result.setDateYearMatchGroup(dateYear.getMatchGroup());
+
+ if (dateMonth.hasLiteralValue())
+ result.setDateMonth(dateMonth.getValue());
+ else
+ result.setDateMonthMatchGroup(dateMonth.getMatchGroup());
+
+ if (dateDay.hasLiteralValue())
+ result.setDateDay(dateDay.getValue());
+ else
+ result.setDateDayMatchGroup(dateDay.getMatchGroup());
+
return result;
}
}