[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Mon Mar 12 17:00:33 UTC 2007


gordonp
Mon Mar 12 13:00:33 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv4410/src/main/org/biomoby/shared

Modified Files:
	MobyService.java 
Log Message:
Added ability to delete inputs and outputs, also made get method for outputs downcasted
moby-live/Java/src/main/org/biomoby/shared MobyService.java,1.15,1.16
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java	2006/11/11 23:04:34	1.15
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java	2007/03/12 17:00:33	1.16
@@ -297,6 +297,11 @@
 	rdf = (value == null ? "" : value);
     }
 
+    /**
+     * Adds an array of input parameter to the service.  
+     * NOTE: the "set" is a bit of a misnomer: parameters will be added to the existing list.
+     * To clear the existing list of parameters, call this finction with 'null' first.
+     */
     public void setInputs (MobyData[] value) {
 	if (value == null) {
 	    primaryInputs.clear();
@@ -304,35 +309,83 @@
 	} else {
 	    for (int i = 0 ; i < value.length; i++) {
 		if (value[i].isPrimary())
-		    primaryInputs.addElement (value[i]);
+		    addOrReplaceData(primaryInputs, value[i]);
 		else
-		    secondaryInputs.addElement (value[i]);
+		    addOrReplaceData(secondaryInputs, value[i]);
 	    }
 	}
     }
     public void addInput (MobyData value) {
 	if (value != null) {
 	    if (value.isPrimary())
-		primaryInputs.addElement (value);
+		addOrReplaceData(primaryInputs, value);
 	    else
-		secondaryInputs.addElement (value);
+		addOrReplaceData(secondaryInputs, value);
 	}
     }
 
+    public void removeInput(MobyData value) {
+	if (value != null) {
+	    if (value.isPrimary())
+		removeData(primaryInputs, value);
+	    else
+		removeData(secondaryInputs, value);
+	}
+    }
+
+    private void addOrReplaceData(Vector<MobyData> vector, MobyData value){
+	for(int i = 0; i < vector.size(); i++){
+	    // Replace an existing parameter with the same name
+	    if(vector.elementAt(i).getName().equals(value.getName())){
+		vector.removeElementAt(i);
+		vector.insertElementAt(value, i);
+		return;
+	    }
+	}
+	// Isn't a replacement, add to the end
+	vector.addElement(value);
+    }
+
+    private void removeData(Vector<MobyData> vector, MobyData value){
+	for(int i = 0; i < vector.size(); i++){
+	    // Remove an existing parameter with the same name
+	    if(vector.elementAt(i).getName().equals(value.getName())){
+		vector.removeElementAt(i--);
+	    }
+	}
+    }
+
+    /**
+     * Adds an array of output parameter to the service.  
+     * NOTE: Unless the parameter is Primary, it will be ignored.
+     * ALSO NOTE: the "set" is a bit of a misnomer: parameters will be added to the existing list.
+     * To clear the existing list of parameters, call this finction with 'null' first.
+     */
     public void setOutputs (MobyData[] value) {
 	if (value == null) {
 	    primaryOutputs.clear();
 	} else {
 	    for (int i = 0 ; i < value.length; i++) {
 		if (value[i].isPrimary())
-		    primaryOutputs.addElement (value[i]);
+		    addOrReplaceData(primaryOutputs, value[i]);
 	    }
 	}
     }
+
+    /**
+     * Adds an output parameter to the service.  NOTE: Unless the parameter is Primary, it will be ignored.
+     */
     public void addOutput (MobyData value) {
 	if (value != null) {
 	    if (value.isPrimary())
-		primaryOutputs.addElement (value);
+		addOrReplaceData(primaryOutputs, value);
+	}
+    }
+
+    public void removeOutput (MobyData value) {
+	if (value != null) {
+	    if (value.isPrimary())
+		removeData(primaryOutputs, value);
 	}
     }
 
@@ -352,9 +405,9 @@
 	}
     }
 
-    public MobyData[] getPrimaryOutputs() {
+    public MobyPrimaryData[] getPrimaryOutputs() {
 	synchronized (primaryOutputs) {
-	    MobyData[] results = new MobyData [primaryOutputs.size()];
+	    MobyPrimaryData[] results = new MobyPrimaryData [primaryOutputs.size()];
 	    primaryOutputs.copyInto (results);
 	    return results;
 	}




More information about the MOBY-guts mailing list