]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java
methods for duplication of a template with its data
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / TemplateWithAccounts.java
index a40ecae924417214d543e880421fb1e3d2b92e3e..8572167ddc63677bd416080ac2741875ac7d434c 100644 (file)
@@ -20,6 +20,7 @@ package net.ktnx.mobileledger.db;
 import androidx.room.Embedded;
 import androidx.room.Relation;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class TemplateWithAccounts {
@@ -28,7 +29,27 @@ public class TemplateWithAccounts {
     @Relation(parentColumn = "id", entityColumn = "template_id")
     public List<TemplateAccount> accounts;
 
+    public static TemplateWithAccounts from(TemplateWithAccounts o) {
+        TemplateWithAccounts result = new TemplateWithAccounts();
+        result.header = new TemplateHeader(o.header);
+        result.accounts = new ArrayList<>();
+        for (TemplateAccount acc : o.accounts) {
+            result.accounts.add(new TemplateAccount(acc));
+        }
+
+        return result;
+    }
     public Long getId() {
         return header.getId();
     }
+    public TemplateWithAccounts createDuplicate() {
+        TemplateWithAccounts result = new TemplateWithAccounts();
+        result.header = header.createDuplicate();
+        result.accounts = new ArrayList<>();
+        for (TemplateAccount acc : accounts) {
+            result.accounts.add(acc.createDuplicate());
+        }
+
+        return result;
+    }
 }