sequence mappings and DbRef mapping objects unified and source binding for castor...
[vamsas.git] / src / uk / ac / vamsas / objects / core / Sequence.java
index d4ff049..519f57a 100644 (file)
@@ -47,6 +47,12 @@ implements java.io.Serializable
      */
     private java.util.Vector _dbRefList;
 
+    /**
+     * explicitly named cross reference to
+     *  other objects in the document. 
+     */
+    private java.util.Vector _vxrefList;
+
 
       //----------------/
      //- Constructors -/
@@ -55,6 +61,7 @@ implements java.io.Serializable
     public Sequence() {
         super();
         this._dbRefList = new java.util.Vector();
+        this._vxrefList = new java.util.Vector();
     }
 
 
@@ -91,6 +98,34 @@ implements java.io.Serializable
     }
 
     /**
+     * 
+     * 
+     * @param vVxref
+     * @throws java.lang.IndexOutOfBoundsException if the index
+     * given is outside the bounds of the collection
+     */
+    public void addVxref(
+            final uk.ac.vamsas.objects.core.Vxref vVxref)
+    throws java.lang.IndexOutOfBoundsException {
+        this._vxrefList.addElement(vVxref);
+    }
+
+    /**
+     * 
+     * 
+     * @param index
+     * @param vVxref
+     * @throws java.lang.IndexOutOfBoundsException if the index
+     * given is outside the bounds of the collection
+     */
+    public void addVxref(
+            final int index,
+            final uk.ac.vamsas.objects.core.Vxref vVxref)
+    throws java.lang.IndexOutOfBoundsException {
+        this._vxrefList.add(index, vVxref);
+    }
+
+    /**
      * Method enumerateDbRef.
      * 
      * @return an Enumeration over all
@@ -102,6 +137,17 @@ implements java.io.Serializable
     }
 
     /**
+     * Method enumerateVxref.
+     * 
+     * @return an Enumeration over all
+     * uk.ac.vamsas.objects.core.Vxref elements
+     */
+    public java.util.Enumeration enumerateVxref(
+    ) {
+        return this._vxrefList.elements();
+    }
+
+    /**
      * Overrides the java.lang.Object.equals method.
      * 
      * @param obj
@@ -118,26 +164,95 @@ implements java.io.Serializable
         if (obj instanceof Sequence) {
         
             Sequence temp = (Sequence)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._dictionary != null) {
                 if (temp._dictionary == null) return false;
-                else if (!(this._dictionary.equals(temp._dictionary))) 
-                    return false;
-            }
-            else if (temp._dictionary != null)
+                if (this._dictionary != temp._dictionary) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._dictionary);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._dictionary);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._dictionary); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._dictionary); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._dictionary.equals(temp._dictionary)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._dictionary);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._dictionary);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._dictionary);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._dictionary);
+                    }
+                }
+            } else if (temp._dictionary != null)
                 return false;
             if (this._dbRefList != null) {
                 if (temp._dbRefList == null) return false;
-                else if (!(this._dbRefList.equals(temp._dbRefList))) 
-                    return false;
-            }
-            else if (temp._dbRefList != null)
+                if (this._dbRefList != temp._dbRefList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._dbRefList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._dbRefList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._dbRefList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._dbRefList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._dbRefList.equals(temp._dbRefList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._dbRefList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._dbRefList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._dbRefList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._dbRefList);
+                    }
+                }
+            } else if (temp._dbRefList != null)
+                return false;
+            if (this._vxrefList != null) {
+                if (temp._vxrefList == null) return false;
+                if (this._vxrefList != temp._vxrefList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._vxrefList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._vxrefList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._vxrefList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._vxrefList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._vxrefList.equals(temp._vxrefList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._vxrefList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._vxrefList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._vxrefList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._vxrefList);
+                    }
+                }
+            } else if (temp._vxrefList != null)
                 return false;
             return true;
         }
@@ -228,6 +343,63 @@ implements java.io.Serializable
     }
 
     /**
+     * Method getVxref.
+     * 
+     * @param index
+     * @throws java.lang.IndexOutOfBoundsException if the index
+     * given is outside the bounds of the collection
+     * @return the value of the uk.ac.vamsas.objects.core.Vxref at
+     * the given index
+     */
+    public uk.ac.vamsas.objects.core.Vxref getVxref(
+            final int index)
+    throws java.lang.IndexOutOfBoundsException {
+        // check bounds for index
+        if (index < 0 || index >= this._vxrefList.size()) {
+            throw new IndexOutOfBoundsException("getVxref: Index value '" + index + "' not in range [0.." + (this._vxrefList.size() - 1) + "]");
+        }
+        
+        return (uk.ac.vamsas.objects.core.Vxref) _vxrefList.get(index);
+    }
+
+    /**
+     * Method getVxref.Returns the contents of the collection in an
+     * Array.  <p>Note:  Just in case the collection contents are
+     * changing in another thread, we pass a 0-length Array of the
+     * correct type into the API call.  This way we <i>know</i>
+     * that the Array returned is of exactly the correct length.
+     * 
+     * @return this collection as an Array
+     */
+    public uk.ac.vamsas.objects.core.Vxref[] getVxref(
+    ) {
+        uk.ac.vamsas.objects.core.Vxref[] array = new uk.ac.vamsas.objects.core.Vxref[0];
+        return (uk.ac.vamsas.objects.core.Vxref[]) this._vxrefList.toArray(array);
+    }
+
+    /**
+     * Method getVxrefAsReference.Returns a reference to
+     * '_vxrefList'. No type checking is performed on any
+     * modifications to the Vector.
+     * 
+     * @return a reference to the Vector backing this class
+     */
+    public java.util.Vector getVxrefAsReference(
+    ) {
+        return this._vxrefList;
+    }
+
+    /**
+     * Method getVxrefCount.
+     * 
+     * @return the size of this collection
+     */
+    public int getVxrefCount(
+    ) {
+        return this._vxrefList.size();
+    }
+
+    /**
      * Overrides the java.lang.Object.hashCode method.
      * <p>
      * The following steps came from <b>Effective Java Programming
@@ -240,14 +412,25 @@ 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 (_dictionary != null) {
+        if (_dictionary != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_dictionary)) {
            result = 37 * result + _dictionary.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_dictionary);
         }
-        if (_dbRefList != null) {
+        if (_dbRefList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_dbRefList)) {
            result = 37 * result + _dbRefList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_dbRefList);
+        }
+        if (_vxrefList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_vxrefList)) {
+           result = 37 * result + _vxrefList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_vxrefList);
         }
         
         return result;
@@ -308,6 +491,13 @@ implements java.io.Serializable
     }
 
     /**
+     */
+    public void removeAllVxref(
+    ) {
+        this._vxrefList.clear();
+    }
+
+    /**
      * Method removeDbRef.
      * 
      * @param vDbRef
@@ -332,6 +522,30 @@ implements java.io.Serializable
     }
 
     /**
+     * Method removeVxref.
+     * 
+     * @param vVxref
+     * @return true if the object was removed from the collection.
+     */
+    public boolean removeVxref(
+            final uk.ac.vamsas.objects.core.Vxref vVxref) {
+        boolean removed = _vxrefList.remove(vVxref);
+        return removed;
+    }
+
+    /**
+     * Method removeVxrefAt.
+     * 
+     * @param index
+     * @return the element removed from the collection
+     */
+    public uk.ac.vamsas.objects.core.Vxref removeVxrefAt(
+            final int index) {
+        java.lang.Object obj = this._vxrefList.remove(index);
+        return (uk.ac.vamsas.objects.core.Vxref) obj;
+    }
+
+    /**
      * 
      * 
      * @param index
@@ -418,6 +632,67 @@ implements java.io.Serializable
     }
 
     /**
+     * 
+     * 
+     * @param index
+     * @param vVxref
+     * @throws java.lang.IndexOutOfBoundsException if the index
+     * given is outside the bounds of the collection
+     */
+    public void setVxref(
+            final int index,
+            final uk.ac.vamsas.objects.core.Vxref vVxref)
+    throws java.lang.IndexOutOfBoundsException {
+        // check bounds for index
+        if (index < 0 || index >= this._vxrefList.size()) {
+            throw new IndexOutOfBoundsException("setVxref: Index value '" + index + "' not in range [0.." + (this._vxrefList.size() - 1) + "]");
+        }
+        
+        this._vxrefList.set(index, vVxref);
+    }
+
+    /**
+     * 
+     * 
+     * @param vVxrefArray
+     */
+    public void setVxref(
+            final uk.ac.vamsas.objects.core.Vxref[] vVxrefArray) {
+        //-- copy array
+        _vxrefList.clear();
+        
+        for (int i = 0; i < vVxrefArray.length; i++) {
+                this._vxrefList.add(vVxrefArray[i]);
+        }
+    }
+
+    /**
+     * Sets the value of '_vxrefList' by copying the given Vector.
+     * All elements will be checked for type safety.
+     * 
+     * @param vVxrefList the Vector to copy.
+     */
+    public void setVxref(
+            final java.util.Vector vVxrefList) {
+        // copy vector
+        this._vxrefList.clear();
+        
+        this._vxrefList.addAll(vVxrefList);
+    }
+
+    /**
+     * Sets the value of '_vxrefList' by setting it to the given
+     * Vector. No type checking is performed.
+     * @deprecated
+     * 
+     * @param vxrefVector the Vector to set.
+     */
+    public void setVxrefAsReference(
+            final java.util.Vector vxrefVector) {
+        this._vxrefList = vxrefVector;
+    }
+
+    /**
      * Method unmarshal.
      * 
      * @param reader