sequence mappings and DbRef mapping objects unified and source binding for castor...
[vamsas.git] / src / uk / ac / vamsas / objects / core / DbRef.java
index a228591..54dfa2c 100644 (file)
@@ -61,19 +61,19 @@ implements java.io.Serializable
     private java.lang.String _id;
 
     /**
-     * From: Offset to first
-     *  position in dataset sequence record that
-     *  this database entry maps to To: Offset
-     *  to last position in dataset sequence
-     *  record that this database entry maps to
-     *  Start: Offset to first last position in
-     *  database entry that first (or offset)
-     *  position in sequence maps to End: Offset
-     *  to last position in database entry that
-     *  last (offset) position in sequence maps
-     *  to 
+     * the local mapType maps from the parent
+     *  sequence coordinate frame to the reference
+     *  frame defined by the dbRef element.
+     *  The mapped mapType is the mapped range defined
+     *  on the dbRef element's reference frame.
+     *  Conventionally, the unit attribute defaults to 1, or
+     *  will be inferred from the local sequence's
+     *  dictionary type and any dictionary type associated
+     *  with the database being mapped to. 
+     *  However, it may be used to avoid ambiguity.
+     *  
      */
-    private java.util.Vector _mapList;
+    private uk.ac.vamsas.objects.core.Map _map;
 
     /**
      * Field _linkList.
@@ -92,7 +92,6 @@ implements java.io.Serializable
 
     public DbRef() {
         super();
-        this._mapList = new java.util.Vector();
         this._linkList = new java.util.Vector();
         this._propertyList = new java.util.Vector();
     }
@@ -133,34 +132,6 @@ implements java.io.Serializable
     /**
      * 
      * 
-     * @param vMap
-     * @throws java.lang.IndexOutOfBoundsException if the index
-     * given is outside the bounds of the collection
-     */
-    public void addMap(
-            final uk.ac.vamsas.objects.core.Map vMap)
-    throws java.lang.IndexOutOfBoundsException {
-        this._mapList.addElement(vMap);
-    }
-
-    /**
-     * 
-     * 
-     * @param index
-     * @param vMap
-     * @throws java.lang.IndexOutOfBoundsException if the index
-     * given is outside the bounds of the collection
-     */
-    public void addMap(
-            final int index,
-            final uk.ac.vamsas.objects.core.Map vMap)
-    throws java.lang.IndexOutOfBoundsException {
-        this._mapList.add(index, vMap);
-    }
-
-    /**
-     * 
-     * 
      * @param vProperty
      * @throws java.lang.IndexOutOfBoundsException if the index
      * given is outside the bounds of the collection
@@ -198,17 +169,6 @@ implements java.io.Serializable
     }
 
     /**
-     * Method enumerateMap.
-     * 
-     * @return an Enumeration over all
-     * uk.ac.vamsas.objects.core.Map elements
-     */
-    public java.util.Enumeration enumerateMap(
-    ) {
-        return this._mapList.elements();
-    }
-
-    /**
      * Method enumerateProperty.
      * 
      * @return an Enumeration over all
@@ -236,54 +196,161 @@ implements java.io.Serializable
         if (obj instanceof DbRef) {
         
             DbRef temp = (DbRef)obj;
+            boolean thcycle;
+            boolean tmcycle;
             if (this._source != null) {
                 if (temp._source == null) return false;
-                else if (!(this._source.equals(temp._source))) 
-                    return false;
-            }
-            else if (temp._source != null)
+                if (this._source != temp._source) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._source);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._source);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._source); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._source); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._source.equals(temp._source)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._source);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._source);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._source);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._source);
+                    }
+                }
+            } else if (temp._source != null)
                 return false;
             if (this._version != null) {
                 if (temp._version == null) return false;
-                else if (!(this._version.equals(temp._version))) 
-                    return false;
-            }
-            else if (temp._version != null)
+                if (this._version != temp._version) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._version);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._version);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._version); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._version); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._version.equals(temp._version)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._version);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._version);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._version);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._version);
+                    }
+                }
+            } else if (temp._version != null)
                 return false;
             if (this._accessionId != null) {
                 if (temp._accessionId == null) return false;
-                else if (!(this._accessionId.equals(temp._accessionId))) 
-                    return false;
-            }
-            else if (temp._accessionId != null)
+                if (this._accessionId != temp._accessionId) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._accessionId);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._accessionId);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._accessionId); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._accessionId); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._accessionId.equals(temp._accessionId)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._accessionId);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._accessionId);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._accessionId);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._accessionId);
+                    }
+                }
+            } else if (temp._accessionId != null)
                 return false;
             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._mapList != null) {
-                if (temp._mapList == null) return false;
-                else if (!(this._mapList.equals(temp._mapList))) 
-                    return false;
-            }
-            else if (temp._mapList != null)
+            if (this._map != null) {
+                if (temp._map == null) return false;
+                if (this._map != temp._map) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._map);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._map);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._map); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._map); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._map.equals(temp._map)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._map);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._map);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._map);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._map);
+                    }
+                }
+            } else if (temp._map != null)
                 return false;
             if (this._linkList != null) {
                 if (temp._linkList == null) return false;
-                else if (!(this._linkList.equals(temp._linkList))) 
-                    return false;
-            }
-            else if (temp._linkList != null)
+                if (this._linkList != temp._linkList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._linkList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._linkList);
+                    if (thcycle!=tmcycle) {
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._linkList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._linkList); };
+                        return false;
+                    }
+                    if (!thcycle) {
+                        if (!this._linkList.equals(temp._linkList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._linkList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._linkList);
+                            return false;
+                        }
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._linkList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._linkList);
+                    }
+                }
+            } else if (temp._linkList != 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;
             return true;
         }
@@ -376,60 +443,25 @@ implements java.io.Serializable
     }
 
     /**
-     * Method getMap.
+     * Returns the value of field 'map'. The field 'map' has the
+     * following description: the local mapType maps from the
+     * parent
+     *  sequence coordinate frame to the reference
+     *  frame defined by the dbRef element.
+     *  The mapped mapType is the mapped range defined
+     *  on the dbRef element's reference frame.
+     *  Conventionally, the unit attribute defaults to 1, or
+     *  will be inferred from the local sequence's
+     *  dictionary type and any dictionary type associated
+     *  with the database being mapped to. 
+     *  However, it may be used to avoid ambiguity.
+     *  
      * 
-     * @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.Map at
-     * the given index
+     * @return the value of field 'Map'.
      */
     public uk.ac.vamsas.objects.core.Map getMap(
-            final int index)
-    throws java.lang.IndexOutOfBoundsException {
-        // check bounds for index
-        if (index < 0 || index >= this._mapList.size()) {
-            throw new IndexOutOfBoundsException("getMap: Index value '" + index + "' not in range [0.." + (this._mapList.size() - 1) + "]");
-        }
-        
-        return (uk.ac.vamsas.objects.core.Map) _mapList.get(index);
-    }
-
-    /**
-     * Method getMap.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.Map[] getMap(
-    ) {
-        uk.ac.vamsas.objects.core.Map[] array = new uk.ac.vamsas.objects.core.Map[0];
-        return (uk.ac.vamsas.objects.core.Map[]) this._mapList.toArray(array);
-    }
-
-    /**
-     * Method getMapAsReference.Returns a reference to '_mapList'.
-     * No type checking is performed on any modifications to the
-     * Vector.
-     * 
-     * @return a reference to the Vector backing this class
-     */
-    public java.util.Vector getMapAsReference(
-    ) {
-        return this._mapList;
-    }
-
-    /**
-     * Method getMapCount.
-     * 
-     * @return the size of this collection
-     */
-    public int getMapCount(
     ) {
-        return this._mapList.size();
+        return this._map;
     }
 
     /**
@@ -529,26 +561,40 @@ implements java.io.Serializable
         int result = super.hashCode();
         
         long tmp;
-        if (_source != null) {
+        if (_source != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_source)) {
            result = 37 * result + _source.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_source);
         }
-        if (_version != null) {
+        if (_version != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_version)) {
            result = 37 * result + _version.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_version);
         }
-        if (_accessionId != null) {
+        if (_accessionId != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_accessionId)) {
            result = 37 * result + _accessionId.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_accessionId);
         }
-        if (_id != null) {
+        if (_id != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
            result = 37 * result + _id.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_id);
         }
-        if (_mapList != null) {
-           result = 37 * result + _mapList.hashCode();
+        if (_map != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_map)) {
+           result = 37 * result + _map.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_map);
         }
-        if (_linkList != null) {
+        if (_linkList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_linkList)) {
            result = 37 * result + _linkList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_linkList);
         }
-        if (_propertyList != null) {
+        if (_propertyList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_propertyList)) {
            result = 37 * result + _propertyList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_propertyList);
         }
         
         return result;
@@ -610,13 +656,6 @@ implements java.io.Serializable
 
     /**
      */
-    public void removeAllMap(
-    ) {
-        this._mapList.clear();
-    }
-
-    /**
-     */
     public void removeAllProperty(
     ) {
         this._propertyList.clear();
@@ -647,30 +686,6 @@ implements java.io.Serializable
     }
 
     /**
-     * Method removeMap.
-     * 
-     * @param vMap
-     * @return true if the object was removed from the collection.
-     */
-    public boolean removeMap(
-            final uk.ac.vamsas.objects.core.Map vMap) {
-        boolean removed = _mapList.remove(vMap);
-        return removed;
-    }
-
-    /**
-     * Method removeMapAt.
-     * 
-     * @param index
-     * @return the element removed from the collection
-     */
-    public uk.ac.vamsas.objects.core.Map removeMapAt(
-            final int index) {
-        java.lang.Object obj = this._mapList.remove(index);
-        return (uk.ac.vamsas.objects.core.Map) obj;
-    }
-
-    /**
      * Method removeProperty.
      * 
      * @param vProperty
@@ -784,64 +799,25 @@ implements java.io.Serializable
     }
 
     /**
+     * Sets the value of field 'map'. The field 'map' has the
+     * following description: the local mapType maps from the
+     * parent
+     *  sequence coordinate frame to the reference
+     *  frame defined by the dbRef element.
+     *  The mapped mapType is the mapped range defined
+     *  on the dbRef element's reference frame.
+     *  Conventionally, the unit attribute defaults to 1, or
+     *  will be inferred from the local sequence's
+     *  dictionary type and any dictionary type associated
+     *  with the database being mapped to. 
+     *  However, it may be used to avoid ambiguity.
+     *  
      * 
-     * 
-     * @param index
-     * @param vMap
-     * @throws java.lang.IndexOutOfBoundsException if the index
-     * given is outside the bounds of the collection
-     */
-    public void setMap(
-            final int index,
-            final uk.ac.vamsas.objects.core.Map vMap)
-    throws java.lang.IndexOutOfBoundsException {
-        // check bounds for index
-        if (index < 0 || index >= this._mapList.size()) {
-            throw new IndexOutOfBoundsException("setMap: Index value '" + index + "' not in range [0.." + (this._mapList.size() - 1) + "]");
-        }
-        
-        this._mapList.set(index, vMap);
-    }
-
-    /**
-     * 
-     * 
-     * @param vMapArray
-     */
-    public void setMap(
-            final uk.ac.vamsas.objects.core.Map[] vMapArray) {
-        //-- copy array
-        _mapList.clear();
-        
-        for (int i = 0; i < vMapArray.length; i++) {
-                this._mapList.add(vMapArray[i]);
-        }
-    }
-
-    /**
-     * Sets the value of '_mapList' by copying the given Vector.
-     * All elements will be checked for type safety.
-     * 
-     * @param vMapList the Vector to copy.
+     * @param map the value of field 'map'.
      */
     public void setMap(
-            final java.util.Vector vMapList) {
-        // copy vector
-        this._mapList.clear();
-        
-        this._mapList.addAll(vMapList);
-    }
-
-    /**
-     * Sets the value of '_mapList' by setting it to the given
-     * Vector. No type checking is performed.
-     * @deprecated
-     * 
-     * @param mapVector the Vector to set.
-     */
-    public void setMapAsReference(
-            final java.util.Vector mapVector) {
-        this._mapList = mapVector;
+            final uk.ac.vamsas.objects.core.Map map) {
+        this._map = map;
     }
 
     /**