| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.plugin.api.model.impl; |
| 5 | |
|
| 6 | |
import java.util.Date; |
| 7 | |
import java.util.List; |
| 8 | |
|
| 9 | |
import org.homeunix.thecave.buddi.i18n.keys.BudgetCategoryTypes; |
| 10 | |
import org.homeunix.thecave.buddi.model.Account; |
| 11 | |
import org.homeunix.thecave.buddi.model.AccountType; |
| 12 | |
import org.homeunix.thecave.buddi.model.BudgetCategory; |
| 13 | |
import org.homeunix.thecave.buddi.model.BudgetCategoryType; |
| 14 | |
import org.homeunix.thecave.buddi.model.Document; |
| 15 | |
import org.homeunix.thecave.buddi.model.Source; |
| 16 | |
import org.homeunix.thecave.buddi.model.Transaction; |
| 17 | |
import org.homeunix.thecave.buddi.model.impl.ModelFactory; |
| 18 | |
import org.homeunix.thecave.buddi.model.impl.WrapperLists; |
| 19 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableAccount; |
| 20 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableAccountType; |
| 21 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableBudgetCategory; |
| 22 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableBudgetCategoryType; |
| 23 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableDocument; |
| 24 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableSource; |
| 25 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableTransaction; |
| 26 | |
|
| 27 | |
public class ImmutableDocumentImpl extends ImmutableModelObjectImpl implements ImmutableDocument { |
| 28 | |
private final Document model; |
| 29 | |
|
| 30 | |
public ImmutableDocumentImpl(Document model) { |
| 31 | 0 | super(model); |
| 32 | 0 | this.model = model; |
| 33 | 0 | } |
| 34 | |
|
| 35 | |
|
| 36 | |
public ImmutableAccount getAccount(String name) { |
| 37 | 0 | if (getModel().getAccount(name) == null) |
| 38 | 0 | return null; |
| 39 | 0 | return new MutableAccountImpl(getModel().getAccount(name)); |
| 40 | |
} |
| 41 | |
|
| 42 | |
public List<ImmutableAccount> getImmutableAccounts(){ |
| 43 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableAccount, Account>(getModel(), getModel().getAccounts()); |
| 44 | |
} |
| 45 | |
|
| 46 | |
public List<ImmutableBudgetCategory> getImmutableBudgetCategories(){ |
| 47 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableBudgetCategory, BudgetCategory>(getModel(), getModel().getBudgetCategories()); |
| 48 | |
} |
| 49 | |
|
| 50 | |
public ImmutableBudgetCategory getBudgetCategory(String fullName) { |
| 51 | 0 | if (getModel().getBudgetCategory(fullName) == null) |
| 52 | 0 | return null; |
| 53 | 0 | return new MutableBudgetCategoryImpl(getModel().getBudgetCategory(fullName)); |
| 54 | |
} |
| 55 | |
|
| 56 | |
public Document getModel(){ |
| 57 | 0 | return model; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public List<ImmutableTransaction> getImmutableTransactions(){ |
| 61 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions()); |
| 62 | |
} |
| 63 | |
|
| 64 | |
public List<ImmutableTransaction> getImmutableTransactions(Date startDate, Date endDate){ |
| 65 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions(startDate, endDate)); |
| 66 | |
} |
| 67 | |
|
| 68 | |
public List<ImmutableTransaction> getImmutableTransactions(ImmutableSource source){ |
| 69 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions((Source) source.getRaw())); |
| 70 | |
} |
| 71 | |
|
| 72 | |
public List<ImmutableTransaction> getImmutableTransactions(ImmutableSource source, Date startDate, Date endDate){ |
| 73 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions((Source) source.getRaw(), startDate, endDate)); |
| 74 | |
} |
| 75 | |
|
| 76 | |
public ImmutableAccountType getAccountType(String name) { |
| 77 | 0 | if (getModel().getAccountType(name) == null) |
| 78 | 0 | return null; |
| 79 | 0 | return new MutableAccountTypeImpl(getModel().getAccountType(name)); |
| 80 | |
} |
| 81 | |
|
| 82 | |
public List<ImmutableAccountType> getImmutableAccountTypes(){ |
| 83 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableAccountType, AccountType>(getModel(), getModel().getAccountTypes()); |
| 84 | |
} |
| 85 | |
|
| 86 | |
@Override |
| 87 | |
public String toString() { |
| 88 | 0 | return getUid(); |
| 89 | |
} |
| 90 | |
|
| 91 | |
public ImmutableBudgetCategoryType getBudgetCategoryType(BudgetCategoryTypes name){ |
| 92 | 0 | return getBudgetCategoryType(name.toString()); |
| 93 | |
} |
| 94 | |
|
| 95 | |
public ImmutableBudgetCategoryType getBudgetCategoryType(String name) { |
| 96 | 0 | BudgetCategoryType type = ModelFactory.getBudgetCategoryType(name); |
| 97 | 0 | if (type == null) |
| 98 | 0 | return null; |
| 99 | 0 | return new ImmutableBudgetCategoryTypeImpl(type); |
| 100 | |
} |
| 101 | |
public long getNetWorth(Date date) { |
| 102 | 0 | return getModel().getNetWorth(date); |
| 103 | |
} |
| 104 | |
} |