X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FTemplateDetailsItem.java;h=84e83d54a314a10275554b9322fd08ebceee4914;hb=7976a12a55de234c277d593467b94395422fbc30;hp=7c33386670cd72619cde97179579fd7adc428876;hpb=28380d6c07e26d72ad570c14b33f5cd1227226b8;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java index 7c333866..84e83d54 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java @@ -32,11 +32,13 @@ import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.db.TemplateAccount; import net.ktnx.mobileledger.db.TemplateBase; import net.ktnx.mobileledger.db.TemplateHeader; +import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.Locale; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -45,7 +47,7 @@ import java.util.regex.PatternSyntaxException; abstract public class TemplateDetailsItem { private final Type type; protected Long id; - protected Long position; + protected long position; protected TemplateDetailsItem(Type type) { this.type = type; @@ -172,7 +174,7 @@ abstract public class TemplateDetailsItem { public long getPosition() { return position; } - public void setPosition(Long position) { + public void setPosition(long position) { this.position = position; } abstract public String getProblem(@NonNull Resources r, int patternGroupCount); @@ -226,6 +228,11 @@ abstract public class TemplateDetailsItem { result.setValue(initialValue); return result; } + public void copyFrom(@NonNull PossiblyMatchedValue origin) { + literalValue = origin.literalValue; + value = origin.value; + matchGroup = origin.matchGroup; + } public T getValue() { if (!literalValue) throw new IllegalStateException("Value is not literal"); @@ -271,6 +278,12 @@ abstract public class TemplateDetailsItem { return "grp:" + matchGroup; return ""; } + public boolean isEmpty() { + if (literalValue) + return value == null || Misc.emptyIsNull(value.toString()) == null; + + return matchGroup > 0; + } } public static class TYPE { @@ -287,9 +300,19 @@ abstract public class TemplateDetailsItem { PossiblyMatchedValue.withLiteralFloat(null); private final PossiblyMatchedValue currency = new PossiblyMatchedValue<>(); private boolean negateAmount; - private AccountRow() { + public AccountRow() { super(Type.ACCOUNT_ITEM); } + public AccountRow(AccountRow origin) { + super(Type.ACCOUNT_ITEM); + id = origin.id; + position = origin.position; + accountName.copyFrom(origin.accountName); + accountComment.copyFrom(origin.accountComment); + amount.copyFrom(origin.amount); + currency.copyFrom(origin.currency); + negateAmount = origin.negateAmount; + } public boolean isNegateAmount() { return negateAmount; } @@ -361,8 +384,15 @@ abstract public class TemplateDetailsItem { return accountComment.hasLiteralValue(); } public boolean equalContents(AccountRow o) { + if (position != o.position) { + Logger.debug("cmpAcc", + String.format(Locale.US, "[%d] != [%d]: pos %d != pos %d", getId(), + o.getId(), position, o.position)); + return false; + } return amount.equals(o.amount) && accountName.equals(o.accountName) && - accountComment.equals(o.accountComment) && negateAmount == o.negateAmount; + position == o.position && accountComment.equals(o.accountComment) && + negateAmount == o.negateAmount; } public void switchToLiteralAmount() { amount.switchToLiteral(); @@ -397,6 +427,9 @@ abstract public class TemplateDetailsItem { return result; } + public boolean isEmpty() { + return accountName.isEmpty() && accountComment.isEmpty() && amount.isEmpty(); + } } public static class Header extends TemplateDetailsItem {