0 to unbounded Dataset/Sequence/DbRef/Map elements. Allows alternate mappings between...
[vamsas.git] / src / uk / ac / vamsas / objects / core / DbRef.java
index 54dfa2c..7206791 100644 (file)
@@ -73,7 +73,7 @@ implements java.io.Serializable
      *  However, it may be used to avoid ambiguity.
      *  
      */
-    private uk.ac.vamsas.objects.core.Map _map;
+    private java.util.Vector _mapList;
 
     /**
      * Field _linkList.
@@ -92,6 +92,7 @@ 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();
     }
@@ -132,6 +133,34 @@ 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
@@ -169,6 +198,17 @@ 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
@@ -286,27 +326,27 @@ implements java.io.Serializable
                 }
             } else if (temp._id != null)
                 return false;
-            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 (this._mapList != null) {
+                if (temp._mapList == null) return false;
+                if (this._mapList != temp._mapList) {
+                    thcycle=org.castor.util.CycleBreaker.startingToCycle(this._mapList);
+                    tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._mapList);
                     if (thcycle!=tmcycle) {
-                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._map); };
-                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._map); };
+                        if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._mapList); };
+                        if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapList); };
                         return false;
                     }
                     if (!thcycle) {
-                        if (!this._map.equals(temp._map)) {
-                            org.castor.util.CycleBreaker.releaseCycleHandle(this._map);
-                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._map);
+                        if (!this._mapList.equals(temp._mapList)) {
+                            org.castor.util.CycleBreaker.releaseCycleHandle(this._mapList);
+                            org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapList);
                             return false;
                         }
-                        org.castor.util.CycleBreaker.releaseCycleHandle(this._map);
-                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._map);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(this._mapList);
+                        org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapList);
                     }
                 }
-            } else if (temp._map != null)
+            } else if (temp._mapList != null)
                 return false;
             if (this._linkList != null) {
                 if (temp._linkList == null) return false;
@@ -443,25 +483,60 @@ implements java.io.Serializable
     }
 
     /**
-     * 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.
-     *  
+     * Method getMap.
      * 
-     * @return the value of field 'Map'.
+     * @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
      */
     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(
     ) {
-        return this._map;
+        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();
     }
 
     /**
@@ -581,10 +656,10 @@ implements java.io.Serializable
            result = 37 * result + _id.hashCode();
            org.castor.util.CycleBreaker.releaseCycleHandle(_id);
         }
-        if (_map != null
-            && !org.castor.util.CycleBreaker.startingToCycle(_map)) {
-           result = 37 * result + _map.hashCode();
-           org.castor.util.CycleBreaker.releaseCycleHandle(_map);
+        if (_mapList != null
+            && !org.castor.util.CycleBreaker.startingToCycle(_mapList)) {
+           result = 37 * result + _mapList.hashCode();
+           org.castor.util.CycleBreaker.releaseCycleHandle(_mapList);
         }
         if (_linkList != null
             && !org.castor.util.CycleBreaker.startingToCycle(_linkList)) {
@@ -656,6 +731,13 @@ implements java.io.Serializable
 
     /**
      */
+    public void removeAllMap(
+    ) {
+        this._mapList.clear();
+    }
+
+    /**
+     */
     public void removeAllProperty(
     ) {
         this._propertyList.clear();
@@ -686,6 +768,30 @@ 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
@@ -799,25 +905,64 @@ 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 map the value of field 'map'.
+     * 
+     * @param index
+     * @param vMap
+     * @throws java.lang.IndexOutOfBoundsException if the index
+     * given is outside the bounds of the collection
      */
     public void setMap(
-            final uk.ac.vamsas.objects.core.Map map) {
-        this._map = map;
+            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.
+     */
+    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;
     }
 
     /**