sequence mappings and DbRef mapping objects unified and source binding for castor...
[vamsas.git] / src / uk / ac / vamsas / objects / core / Tree.java
index 5c0e72a..39eb763 100644 (file)
@@ -49,9 +49,8 @@ implements java.io.Serializable
     private java.util.Vector _newickList;
 
     /**
-     * node identity and mapping data between tree representations
-     * and vamsas document objects
-     *  
+     * node identity and mapping data between tree
+     *  representations and vamsas document objects 
      */
     private java.util.Vector _treenodeList;
 
@@ -216,54 +215,161 @@ implements java.io.Serializable
         if (obj instanceof Tree) {
         
             Tree temp = (Tree)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._modifiable != null) {
                 if (temp._modifiable == null) return false;
-                else if (!(this._modifiable.equals(temp._modifiable))) 
-                    return false;
-            }
-            else if (temp._modifiable != null)
+                if (this._modifiable != temp._modifiable) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._modifiable);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._modifiable);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._modifiable.equals(temp._modifiable)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
+                    }
+                }
+            } else if (temp._modifiable != null)
                 return false;
             if (this._title != null) {
                 if (temp._title == null) return false;
-                else if (!(this._title.equals(temp._title))) 
-                    return false;
-            }
-            else if (temp._title != null)
+                if (this._title != temp._title) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._title);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._title);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._title); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._title); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._title.equals(temp._title)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._title);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._title);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._title);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._title);
+                    }
+                }
+            } else if (temp._title != null)
                 return false;
             if (this._newickList != null) {
                 if (temp._newickList == null) return false;
-                else if (!(this._newickList.equals(temp._newickList))) 
-                    return false;
-            }
-            else if (temp._newickList != null)
+                if (this._newickList != temp._newickList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._newickList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._newickList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._newickList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._newickList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._newickList.equals(temp._newickList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._newickList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._newickList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._newickList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._newickList);
+                    }
+                }
+            } else if (temp._newickList != null)
                 return false;
             if (this._treenodeList != null) {
                 if (temp._treenodeList == null) return false;
-                else if (!(this._treenodeList.equals(temp._treenodeList))) 
-                    return false;
-            }
-            else if (temp._treenodeList != null)
+                if (this._treenodeList != temp._treenodeList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._treenodeList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._treenodeList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._treenodeList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._treenodeList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._treenodeList.equals(temp._treenodeList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._treenodeList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._treenodeList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._treenodeList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._treenodeList);
+                    }
+                }
+            } else if (temp._treenodeList != null)
                 return false;
             if (this._propertyList != null) {
                 if (temp._propertyList == null) return false;
-                else if (!(this._propertyList.equals(temp._propertyList))) 
-                    return false;
-            }
-            else if (temp._propertyList != null)
+                if (this._propertyList != temp._propertyList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._propertyList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._propertyList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._propertyList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._propertyList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._propertyList.equals(temp._propertyList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._propertyList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._propertyList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._propertyList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._propertyList);
+                    }
+                }
+            } else if (temp._propertyList != null)
                 return false;
             if (this._provenance != null) {
                 if (temp._provenance == null) return false;
-                else if (!(this._provenance.equals(temp._provenance))) 
-                    return false;
-            }
-            else if (temp._provenance != null)
+                if (this._provenance != temp._provenance) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._provenance);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._provenance);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._provenance.equals(temp._provenance)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
+                    }
+                }
+            } else if (temp._provenance != null)
                 return false;
             return true;
         }
@@ -496,26 +602,40 @@ 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 (_modifiable != null) {
+        if (_modifiable != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_modifiable)) {
            result = 37 * result + _modifiable.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_modifiable);
         }
-        if (_title != null) {
+        if (_title != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_title)) {
            result = 37 * result + _title.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_title);
         }
-        if (_newickList != null) {
+        if (_newickList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_newickList)) {
            result = 37 * result + _newickList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_newickList);
         }
-        if (_treenodeList != null) {
+        if (_treenodeList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_treenodeList)) {
            result = 37 * result + _treenodeList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_treenodeList);
         }
-        if (_propertyList != null) {
+        if (_propertyList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_propertyList)) {
            result = 37 * result + _propertyList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_propertyList);
         }
-        if (_provenance != null) {
+        if (_provenance != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_provenance)) {
            result = 37 * result + _provenance.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_provenance);
         }
         
         return result;