[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Apr 26 15:06:16 UTC 2007


gordonp
Thu Apr 26 11:06:15 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data
In directory dev.open-bio.org:/tmp/cvs-serv32682/src/main/org/biomoby/shared/data

Modified Files:
	MobyDataObjectSet.java 
Log Message:
Made the containing vector use a Generics construct (MobyDataObject) for type safety
moby-live/Java/src/main/org/biomoby/shared/data MobyDataObjectSet.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObjectSet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObjectSet.java	2006/12/11 18:59:36	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObjectSet.java	2007/04/26 15:06:15	1.7
@@ -29,7 +29,7 @@
  */
 public class MobyDataObjectSet extends MobyPrimaryDataSet implements MobyDataInstance, Collection<MobyDataObject>{
 
-    Vector bag;
+    Vector<MobyDataObject> bag;
     private int xmlMode = MobyDataInstance.CENTRAL_XML_MODE;
 
     public MobyDataObjectSet(org.w3c.dom.Element e) throws MobyException{
@@ -57,7 +57,7 @@
      */
     public MobyDataObjectSet(String name){
 	super(name);
-	bag = new Vector();
+	bag = new Vector<MobyDataObject>();
     }
 
     /**
@@ -95,8 +95,8 @@
 	boolean first = true;
 	synchronized (bag) {
 	    if (bag.size() > 0){
-		for (Enumeration en = bag.elements(); en.hasMoreElements(); ){
-		    MobyDataType objType = ((MobyPrimaryData) en.nextElement()).getDataType();
+		for(MobyDataObject member: bag){
+		    MobyDataType objType = member.getDataType();
 		    // Unknown datatype, break because we can't assume any common lineage for all elements anymore
 		    if(objType == null){
 			break;
@@ -149,8 +149,8 @@
 	Vector namespaces = new Vector();
 	boolean first = true;
 	synchronized (bag) {
-	    for (Enumeration en = bag.elements(); en.hasMoreElements(); ){
-		MobyNamespace[]	nsInstances = ((MobyPrimaryData) en.nextElement()).getNamespaces();
+	    for (MobyDataObject member: bag){
+		MobyNamespace[]	nsInstances = member.getNamespaces();
 		Vector newNames = new Vector();
 		for(int i = 0; nsInstances != null && i < nsInstances.length; i++){
 		    newNames.add(nsInstances[i]);
@@ -180,8 +180,9 @@
      *************************************************************************/
     public void setNamespaces (MobyNamespace[] values) {
 	synchronized (bag) {
-	    for (Enumeration en = bag.elements(); en.hasMoreElements(); )
-		((MobyPrimaryData) en.nextElement()).setNamespaces (values);
+	    for(MobyDataObject member: bag){
+		member.setNamespaces(values);
+	    }
 	}
     }
 
@@ -190,8 +191,9 @@
      *************************************************************************/
     public void addNamespace (MobyNamespace value) {
 	synchronized (bag) {
-	    for (Enumeration en = bag.elements(); en.hasMoreElements(); )
-		((MobyPrimaryData) en.nextElement()).addNamespace (value);
+	    for (MobyDataObject member: bag){
+		member.addNamespace(value);
+	    }
 	}
     }
 
@@ -201,8 +203,9 @@
      *************************************************************************/
     public void removeNamespace (String namespaceName) {
 	synchronized (bag) {
-	    for (Enumeration en = bag.elements(); en.hasMoreElements(); )
-		((MobyPrimaryData) en.nextElement()).removeNamespace (namespaceName);
+	    for (MobyDataObject member: bag){
+		member.removeNamespace(namespaceName);
+	    }
 	}
     }
 
@@ -211,8 +214,9 @@
      *************************************************************************/
     public void removeNamespace (MobyNamespace value) {
 	synchronized (bag) {
-	    for (Enumeration en = bag.elements(); en.hasMoreElements(); )
-		((MobyPrimaryData) en.nextElement()).removeNamespace (value);
+	    for(MobyDataObject member: bag){
+		member.removeNamespace(value);
+	    }
 	}
     }
 
@@ -409,7 +413,7 @@
     /**
      * @return an iterator over the non-null MobyDataObjects in this collection
      */
-    public Iterator iterator(){
+    public Iterator<MobyDataObject> iterator(){
 	return bag.iterator();
     }
 
@@ -511,15 +515,12 @@
     public String toXML(){
 	StringBuffer collectionXml = new StringBuffer();
 	
-	Iterator membersIterator = bag.iterator();
         if(xmlMode == MobyDataInstance.SERVICE_XML_MODE){
 	    collectionXml.append("<moby:Collection xmlns:moby=\""+MobyPrefixResolver.MOBY_XML_NAMESPACE+
 				 (getName() != null ? "\" moby:articleName=\"" + getName() : "") + 
 				 "\">\n");
 	    
-	    while(membersIterator.hasNext()){
-
-		MobyDataObject mdsi = (MobyDataObject) membersIterator.next();
+	    for(MobyDataObject mdsi: bag){
 		mdsi.setXmlMode(xmlMode);
 
 		collectionXml.append("<Simple>"+mdsi.toXML()+"</Simple>");
@@ -534,9 +535,7 @@
 	    collectionXml.append("<Collection>\n");
 	    Hashtable printed = new Hashtable();
 
-	    while(membersIterator.hasNext()){
-
-		MobyDataObject mdsi = (MobyDataObject) membersIterator.next();
+	    for(MobyDataObject mdsi: bag){
 		// Could the DataType be null?  I hope not!
 		String objectClass = mdsi.getDataType().getName();
 




More information about the MOBY-guts mailing list