| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.plugin.api.model.impl; |
| 5 | |
|
| 6 | |
import org.homeunix.thecave.buddi.model.Account; |
| 7 | |
import org.homeunix.thecave.buddi.model.BudgetCategory; |
| 8 | |
import org.homeunix.thecave.buddi.model.TransactionSplit; |
| 9 | |
import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException; |
| 10 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableSource; |
| 11 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableSource; |
| 12 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableTransactionSplit; |
| 13 | |
|
| 14 | |
public class MutableTransactionSplitImpl extends MutableModelObjectImpl implements MutableTransactionSplit { |
| 15 | |
|
| 16 | |
public MutableTransactionSplitImpl(TransactionSplit transactionSplit) { |
| 17 | 0 | super(transactionSplit); |
| 18 | 0 | } |
| 19 | |
|
| 20 | |
public TransactionSplit getTransactionSplit(){ |
| 21 | 0 | return (TransactionSplit) getRaw(); |
| 22 | |
} |
| 23 | |
|
| 24 | |
public void setAmount(long amount) { |
| 25 | 0 | getTransactionSplit().setAmount(amount); |
| 26 | 0 | } |
| 27 | |
|
| 28 | |
public void setSource(MutableSource source) throws InvalidValueException{ |
| 29 | 0 | if (source == null) |
| 30 | 0 | getTransactionSplit().setSource(null); |
| 31 | |
else |
| 32 | 0 | getTransactionSplit().setSource(source.getSource()); |
| 33 | 0 | } |
| 34 | |
|
| 35 | |
public ImmutableSource getSource(){ |
| 36 | 0 | if (getTransactionSplit().getSource() instanceof Account) |
| 37 | 0 | return new MutableAccountImpl((Account) getTransactionSplit().getSource()); |
| 38 | 0 | if (getTransactionSplit().getSource() instanceof BudgetCategory) |
| 39 | 0 | return new MutableBudgetCategoryImpl((BudgetCategory) getTransactionSplit().getSource()); |
| 40 | 0 | return null; |
| 41 | |
} |
| 42 | |
public long getAmount(){ |
| 43 | 0 | return getTransactionSplit().getAmount(); |
| 44 | |
} |
| 45 | |
|
| 46 | |
@Override |
| 47 | |
public boolean equals(Object obj) { |
| 48 | 0 | if (obj instanceof MutableTransactionSplit) |
| 49 | 0 | return getUid().equals(((MutableTransactionSplit) obj).getUid()); |
| 50 | 0 | return false; |
| 51 | |
} |
| 52 | |
} |