Coverage Report - org.jtheque.primary.od.impl.PersonImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PersonImpl
0 %
0/37
0 %
0/8
1.2
 
 1  
 package org.jtheque.primary.od.impl;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *            
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License. 
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.properties.IPropertiesManager;
 21  
 import org.jtheque.core.utils.db.Note;
 22  
 import org.jtheque.primary.od.able.Person;
 23  
 import org.jtheque.primary.od.able.SimpleData;
 24  
 import org.jtheque.primary.od.impl.abstraction.AbstractPrimaryData;
 25  
 import org.jtheque.primary.od.impl.temp.PersonTemporaryContext;
 26  
 import org.jtheque.primary.utils.TempUtils;
 27  
 
 28  
 /**
 29  
  * A borrower implementation.
 30  
  *
 31  
  * @author Baptiste Wicht
 32  
  */
 33  0
 public final class PersonImpl extends AbstractPrimaryData implements Person {
 34  
         private String name;
 35  
         private String firstName;
 36  
         private SimpleData theCountry;
 37  
         private Note note;
 38  
         private String type;
 39  
         private String email;
 40  
 
 41  
         private Person memento;
 42  
         private boolean mementoState;
 43  
 
 44  0
         private final PersonTemporaryContext temporaryContext = new PersonTemporaryContext();
 45  
 
 46  
         //Data methods
 47  
 
 48  
         @Override
 49  
         public void setName(String name){
 50  0
                 this.name = name;
 51  0
         }
 52  
 
 53  
         @Override
 54  
         public void setFirstName(String firstName){
 55  0
                 this.firstName = firstName;
 56  0
         }
 57  
 
 58  
         @Override
 59  
         public void setTheCountry(SimpleData country){
 60  0
                 theCountry = country;
 61  0
         }
 62  
 
 63  
         @Override
 64  
         public SimpleData getTheCountry(){
 65  0
                 return theCountry;
 66  
         }
 67  
 
 68  
         @Override
 69  
         public String getName(){
 70  0
                 return name;
 71  
         }
 72  
 
 73  
         @Override
 74  
         public String getFirstName(){
 75  0
                 return firstName;
 76  
         }
 77  
 
 78  
         @Override
 79  
         public void setNote(Note note){
 80  0
                 this.note = note;
 81  0
         }
 82  
 
 83  
         @Override
 84  
         public Note getNote(){
 85  0
                 return note;
 86  
         }
 87  
 
 88  
         @Override
 89  
         public String getType(){
 90  0
                 return type;
 91  
         }
 92  
 
 93  
         @Override
 94  
         public void setType(String type){
 95  0
                 this.type = type;
 96  0
         }
 97  
 
 98  
         @Override
 99  
         public void setEmail(String email){
 100  0
                 this.email = email;
 101  0
         }
 102  
 
 103  
         @Override
 104  
         public String getEmail(){
 105  0
                 return email;
 106  
         }
 107  
 
 108  
         //Utility methods
 109  
 
 110  
         @Override
 111  
         public PersonTemporaryContext getTemporaryContext(){
 112  0
                 return temporaryContext;
 113  
         }
 114  
 
 115  
         @Override
 116  
         public boolean hasCountry(){
 117  0
                 return theCountry != null;
 118  
         }
 119  
 
 120  
         @Override
 121  
         public String getDisplayableText(){
 122  0
                 return firstName + ' ' + name;
 123  
         }
 124  
 
 125  
         @Override
 126  
         public String toString(){
 127  0
                 return getDisplayableText();
 128  
         }
 129  
 
 130  
         @Override
 131  
         public int hashCode(){
 132  0
                 return TempUtils.hashCodeDirect(this, getId(), name, note, theCountry, firstName, email, type);
 133  
         }
 134  
 
 135  
         @Override
 136  
         public boolean equals(Object obj){
 137  0
         if(obj == null){
 138  0
             return false;
 139  
         }
 140  
 
 141  0
                 Person other = (Person) obj;
 142  
 
 143  0
                 return TempUtils.areEqualsDirect(
 144  
                                 this, obj,
 145  
                                 name, note, theCountry, firstName, email, type,
 146  
                                 other.getName(), other.getNote(), other.getTheCountry(), other.getFirstName(), other.getEmail(), other.getType());
 147  
         }
 148  
 
 149  
         @Override
 150  
         public void saveToMemento(){
 151  0
                 mementoState = true;
 152  
 
 153  0
                 memento = Managers.getManager(IPropertiesManager.class).createMemento(this);
 154  
 
 155  0
                 if (memento == null){
 156  0
                         mementoState = false;
 157  
                 }
 158  0
         }
 159  
 
 160  
         @Override
 161  
         public void restoreMemento(){
 162  0
                 if (mementoState){
 163  0
                         Managers.getManager(IPropertiesManager.class).restoreMemento(this, memento);
 164  
                 }
 165  0
         }
 166  
 }