import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
import eu.etaxonomy.cdm.jaxb.UUIDAdapter;
import eu.etaxonomy.cdm.model.NewEntityListener;
+import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
+import eu.etaxonomy.cdm.strategy.match.IMatchable;
import eu.etaxonomy.cdm.strategy.match.Match;
import eu.etaxonomy.cdm.strategy.match.MatchMode;
// ************* Object overrides *************************/
/**
- * Is true if UUID is the same for the passed Object and this one.
+ * Is <code>true</code> if UUID and created timestamp (is this really needed/make sense?)
+ * is the same for the passed Object and this one.
+ * This method is final as subclasses should not override it.
+ * The contract should be the same for all persistable entities.
+ * 2 instances are equal if they represent the same entity in a given
+ * database.
+ * <BR><BR>
+ *
+ * If one wants to compare 2 CdmBase entities content wise you may use e.g. a
+ * {@link IMatchStrategy match strategy} and make sure
+ * {@link IMatchable matching} is implemented for the respective CdmBase subclass.
+ * You may adapt your match strategy to your own needs.
+ *
* @see java.lang.Object#equals(java.lang.Object)
* See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
* or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
* for more information about equals and hashcode.
*/
@Override
- public boolean equals(Object obj) {
+ public final boolean equals(Object obj) {
if (obj == this){
return true;
}
return false;
}
ICdmBase cdmObj = (ICdmBase)obj;
- boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
- boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
+ UUID objUuid = cdmObj.getUuid();
+ if (objUuid == null){
+ throw new NullPointerException("CdmBase is missing UUID");
+ }
+ boolean uuidEqual = objUuid.equals(this.getUuid());
+ //TODO is this still needed?
+ boolean createdEqual = CdmUtils.nullSafeEqual(cdmObj.getCreated(), this.getCreated());
if (! uuidEqual || !createdEqual){
return false;
}
}
+
/** Overrides {@link java.lang.Object#hashCode()}
* See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
* or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
import java.util.HashMap;
import java.util.Map;
-import java.util.UUID;
import javax.persistence.Basic;
import javax.persistence.FetchType;
import org.hibernate.search.annotations.FieldBridge;
import org.joda.time.DateTime;
-import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
import eu.etaxonomy.cdm.strategy.match.Match;
this.updated = updated;
}
- /**
- * Is true if UUID and created timestamp are the same for the passed Object and this one.
- * @see eu.etaxonomy.cdm.model.common.CdmBase#equals(java.lang.Object)
- * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
- * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
- * for more information about equals and hashcode.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this){
- return true;
- }
- if (obj == null){
- return false;
- }
- if (!CdmBase.class.isAssignableFrom(obj.getClass())){
- return false;
- }
- ICdmBase cdmObj = (ICdmBase)obj;
- boolean uuidEqual;
- UUID objUuid = cdmObj.getUuid();
- if (objUuid == null){
- throw new NullPointerException("CdmBase is missing UUID");
- }
- uuidEqual = objUuid.equals(this.getUuid());
- //TODO is this still needed?
- boolean createdEqual = CdmUtils.nullSafeEqual(cdmObj.getCreated(), this.getCreated());
- if (! uuidEqual || !createdEqual){
- return false;
- }
- return true;
- }
//********************** CLONE *****************************************/