Coverage Report - org.homeunix.thecave.buddi.model.impl.ModelObjectImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ModelObjectImpl
83%
20/24
87%
7/8
1.455
 
 1  
 /*
 2  
  * Created on Jul 29, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.model.impl;
 5  
 
 6  
 import java.util.Date;
 7  
 import java.util.Map;
 8  
 
 9  
 import org.homeunix.thecave.buddi.model.Document;
 10  
 import org.homeunix.thecave.buddi.model.ModelObject;
 11  
 
 12  
 import ca.digitalcave.moss.application.document.AbstractDocument;
 13  
 
 14  
 /**
 15  
  * The class from which most other model objects descend from.  You should not 
 16  
  * instantiate this class directly.
 17  
  * 
 18  
  * @author wyatt
 19  
  *
 20  
  */
 21  60735
 public abstract class ModelObjectImpl implements ModelObject {
 22  
         
 23  
         protected Time modifiedTime;
 24  
         protected String uid;
 25  
         protected Document document;
 26  
                 
 27  
         public void setChanged(){
 28  261227
                 setModified(new Time());
 29  261227
                 if (document != null)
 30  115292
                         document.setChanged();
 31  261227
         }
 32  
         public Time getModified() {
 33  0
                 return modifiedTime;
 34  
         }
 35  
         public void setModified(Time modifiedTime){
 36  261227
                 this.modifiedTime = modifiedTime;
 37  261227
         }
 38  
         public void setModified(Date modifiedDate) {
 39  0
                 this.modifiedTime = new Time(modifiedDate);
 40  0
         }
 41  
         public String getUid() {
 42  207708
                 if (uid == null || uid.length() == 0){
 43  57655
                         setUid(AbstractDocument.getGeneratedUid(this));
 44  
                 }
 45  207708
                 return uid;
 46  
         }
 47  
         public void setUid(String uid) {
 48  57655
                 this.uid = uid;
 49  57655
                 setChanged();
 50  57655
         }
 51  
         public Document getDocument() {
 52  1158415
                 return document;
 53  
         }
 54  
         public void setDocument(Document document) {
 55  57646
                 this.document = document;
 56  57646
                 setChanged();
 57  57646
         }
 58  
         
 59  
         @Override
 60  
         public boolean equals(Object obj) {
 61  69348
                 if (obj instanceof ModelObjectImpl)
 62  9
                         return this.getUid().equals(((ModelObjectImpl) obj).getUid());
 63  69339
                 return false;
 64  
         }
 65  
         
 66  
         public int compareTo(ModelObject o) {
 67  0
                 return (getUid().compareTo(o.getUid()));
 68  
         }
 69  
         
 70  
         
 71  
         /**
 72  
          * Clones the object.  A cloned object will contain the same values as the original, but will 
 73  
          * not have identical (i.e., same reference) to these values.  The originalToCloneMap allows
 74  
          * references to other original objects to carry over to the new cloned object.  For instance, 
 75  
          * when cloning a transaction, you must also have references to the new cloned sources.
 76  
          * 
 77  
          * When you clone this given object, you must also put a reference to the new object
 78  
          * into the map, to allow future objects to refer to the newly cloned object.
 79  
          * 
 80  
          * If you try to clone an object twice using the same map, it will return the same
 81  
          * object which it originally did.  This allows you to indiscriminantly use the clone
 82  
          * method, even if converting trees or graphs of objects.
 83  
          * 
 84  
          * @param originalToCloneMap
 85  
          * @return
 86  
          * @throws CloneNotSupportedException
 87  
          */
 88  
         abstract ModelObject clone(Map<ModelObject, ModelObject> originalToCloneMap) throws CloneNotSupportedException;
 89  
 }