Coverage Report - org.homeunix.thecave.buddi.model.impl.AccountTypeImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AccountTypeImpl
51%
17/33
31%
5/16
2.625
 
 1  
 /*
 2  
  * Created on Jul 29, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.model.impl;
 5  
 
 6  
 import java.util.Map;
 7  
 
 8  
 import org.homeunix.thecave.buddi.model.AccountType;
 9  
 import org.homeunix.thecave.buddi.model.Document;
 10  
 import org.homeunix.thecave.buddi.model.ModelObject;
 11  
 import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException;
 12  
 import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter;
 13  
 
 14  
 /**
 15  
  * Default implementation of an AccountType.  You should not create this object directly; 
 16  
  * instead, please use the ModelFactory to create it, as this will ensure that all
 17  
  * required fields are correctly set.
 18  
  * @author wyatt
 19  
  *
 20  
  */
 21  115292
 public class AccountTypeImpl extends ModelObjectImpl implements AccountType {
 22  
         private String name;
 23  
         private boolean credit;
 24  
         private boolean isExpanded;
 25  
 
 26  
         public boolean isCredit() {
 27  203278
                 return credit;
 28  
         }
 29  
         public void setCredit(boolean credit) {
 30  27306
                 this.credit = credit;
 31  27306
                 setChanged();
 32  27306
         }
 33  
         public String getName() {
 34  339808
                 return TextFormatter.getTranslation(name);
 35  
         }
 36  
         public void setName(String name) throws InvalidValueException {
 37  27306
                 if (getDocument() != null){
 38  0
                         for (AccountType at : ((Document) getDocument()).getAccountTypes()) {
 39  0
                                 if (at.getName().equals(name) && !at.equals(this))
 40  0
                                         throw new InvalidValueException("The budget category name must be unique");
 41  
                         }
 42  
                 }
 43  27306
                 this.name = name;
 44  27306
                 setChanged();
 45  27306
         }
 46  
         public boolean isExpanded() {
 47  136386
                 return isExpanded;
 48  
         }
 49  
         public void setExpanded(boolean isExpanded) {
 50  0
                 this.isExpanded = isExpanded;
 51  0
         }
 52  
         @Override
 53  
         public int compareTo(ModelObject o) {
 54  87986
                 if (o instanceof AccountTypeImpl){
 55  87986
                         AccountTypeImpl t = (AccountTypeImpl) o;
 56  87986
                         if (this.isCredit() != t.isCredit()){
 57  27306
                                 if (t.isCredit())
 58  27306
                                         return -1;
 59  0
                                 return 1;
 60  
                         }
 61  
                         
 62  60680
                         return this.getName().compareTo(t.getName());
 63  
                 }
 64  0
                 return super.compareTo(o);
 65  
         }
 66  
         
 67  
         AccountType clone(Map<ModelObject, ModelObject> originalToCloneMap)
 68  
                         throws CloneNotSupportedException {
 69  
 
 70  0
                 if (originalToCloneMap.get(this) != null)
 71  0
                         return (AccountType) originalToCloneMap.get(this);
 72  
                 
 73  0
                 AccountTypeImpl a = new AccountTypeImpl();
 74  0
                 a.document = (Document) originalToCloneMap.get(document);
 75  0
                 a.name = name;
 76  0
                 a.credit = credit;
 77  0
                 a.isExpanded = isExpanded;
 78  
                 
 79  0
                 originalToCloneMap.put(this, a);
 80  
                 
 81  0
                 return a;
 82  
         }
 83  
 }