sequence mappings and DbRef mapping objects unified and source binding for castor...
[vamsas.git] / src / uk / ac / vamsas / objects / core / AlignmentSequence.java
index a476961..8192795 100644 (file)
@@ -117,26 +117,73 @@ implements java.io.Serializable
         if (obj instanceof AlignmentSequence) {
         
             AlignmentSequence temp = (AlignmentSequence)obj;
+            boolean thcycle;
+            boolean tmcycle;
             if (this._id != null) {
                 if (temp._id == null) return false;
-                else if (!(this._id.equals(temp._id))) 
-                    return false;
-            }
-            else if (temp._id != null)
+                if (this._id != temp._id) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._id);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._id);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._id); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._id); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._id.equals(temp._id)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
+                    }
+                }
+            } else if (temp._id != null)
                 return false;
             if (this._refid != null) {
                 if (temp._refid == null) return false;
-                else if (!(this._refid.equals(temp._refid))) 
-                    return false;
-            }
-            else if (temp._refid != null)
+                if (this._refid != temp._refid) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._refid);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._refid);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._refid); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._refid.equals(temp._refid)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
+                    }
+                }
+            } else if (temp._refid != null)
                 return false;
             if (this._alignmentSequenceAnnotationList != null) {
                 if (temp._alignmentSequenceAnnotationList == null) return false;
-                else if (!(this._alignmentSequenceAnnotationList.equals(temp._alignmentSequenceAnnotationList))) 
-                    return false;
-            }
-            else if (temp._alignmentSequenceAnnotationList != null)
+                if (this._alignmentSequenceAnnotationList != temp._alignmentSequenceAnnotationList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._alignmentSequenceAnnotationList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._alignmentSequenceAnnotationList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._alignmentSequenceAnnotationList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._alignmentSequenceAnnotationList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._alignmentSequenceAnnotationList.equals(temp._alignmentSequenceAnnotationList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._alignmentSequenceAnnotationList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._alignmentSequenceAnnotationList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._alignmentSequenceAnnotationList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._alignmentSequenceAnnotationList);
+                    }
+                }
+            } else if (temp._alignmentSequenceAnnotationList != null)
                 return false;
             return true;
         }
@@ -240,14 +287,20 @@ implements java.io.Serializable
         int result = super.hashCode();
         
         long tmp;
-        if (_id != null) {
+        if (_id != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
            result = 37 * result + _id.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_id);
         }
-        if (_refid != null) {
+        if (_refid != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_refid)) {
            result = 37 * result + _refid.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_refid);
         }
-        if (_alignmentSequenceAnnotationList != null) {
+        if (_alignmentSequenceAnnotationList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_alignmentSequenceAnnotationList)) {
            result = 37 * result + _alignmentSequenceAnnotationList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_alignmentSequenceAnnotationList);
         }
         
         return result;