Revision: 17611
          http://sourceforge.net/p/gate/code/17611
Author:   markagreenwood
Date:     2014-03-10 08:38:23 +0000 (Mon, 10 Mar 2014)
Log Message:
-----------
cleaned up the generics in the persistance manager, which was an interesting 
task given how the objects get converted between diffierent transient and 
serializable forms

Modified Paths:
--------------
    gate/trunk/src/main/gate/util/persistence/CollectionPersistence.java
    
gate/trunk/src/main/gate/util/persistence/ConditionalControllerPersistence.java
    gate/trunk/src/main/gate/util/persistence/ControllerPersistence.java
    gate/trunk/src/main/gate/util/persistence/CorpusPersistence.java
    gate/trunk/src/main/gate/util/persistence/DSPersistence.java
    gate/trunk/src/main/gate/util/persistence/LRPersistence.java
    gate/trunk/src/main/gate/util/persistence/MapPersistence.java
    gate/trunk/src/main/gate/util/persistence/PRPersistence.java
    gate/trunk/src/main/gate/util/persistence/PersistenceManager.java
    gate/trunk/src/main/gate/util/persistence/ResourcePersistence.java

Modified: gate/trunk/src/main/gate/util/persistence/CollectionPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/CollectionPersistence.java        
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/CollectionPersistence.java        
2014-03-10 08:38:23 UTC (rev 17611)
@@ -14,13 +14,18 @@
  */
 package gate.util.persistence;
 
-import java.util.*;
-
 import gate.creole.ResourceInstantiationException;
 import gate.persist.PersistenceException;
 import gate.util.Err;
 
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
 
+
 public class CollectionPersistence implements Persistence {
 
   /**
@@ -38,11 +43,11 @@
     }
     collectionType = source.getClass();
 
-    Collection coll = (Collection)source;
+    Collection<?> coll = (Collection<?>)source;
 
     //get the values in the iterator's order
-    localList = new ArrayList(coll.size());
-    Iterator elemIter = coll.iterator();
+    localList = new ArrayList<Serializable>(coll.size());
+    Iterator<?> elemIter = coll.iterator();
     while(elemIter.hasNext()){
       localList.add(PersistenceManager.
                     getPersistentRepresentation(elemIter.next()));
@@ -53,14 +58,15 @@
    * Creates a new object from the data contained. This new object is supposed
    * to be a copy for the original object used as source for data extraction.
    */
+  @SuppressWarnings("unchecked")
   @Override
   public Object createObject()throws PersistenceException,
                                      ResourceInstantiationException{
     List<String> exceptionsOccurred = new ArrayList<String>();
     //let's try to create a collection of the same type as the original
-    Collection result = null;
+    Collection<Object> result = null;
     try{
-      result = (Collection)collectionType.newInstance();
+      result = (Collection<Object>)collectionType.newInstance();
     }catch(Exception e){
       // ignore - if we can't create a collection of the original type
       // for any reason, just create an ArrayList as a fallback.  The
@@ -68,7 +74,7 @@
       // GATE resources, and GATE can convert an ArrayList to any type
       // required by a resource parameter.
     }
-    if(result == null) result = new ArrayList(localList.size());
+    if(result == null) result = new ArrayList<Object>(localList.size());
 
     //now we have the collection let's populate it
     for(Object local : localList) {
@@ -96,7 +102,7 @@
   }
 
 
-  protected List localList;
-  protected Class collectionType;
+  protected List<Serializable> localList;
+  protected Class<?> collectionType;
   static final long serialVersionUID = 7908364068699089834L;
 }
\ No newline at end of file

Modified: 
gate/trunk/src/main/gate/util/persistence/ConditionalControllerPersistence.java
===================================================================
--- 
gate/trunk/src/main/gate/util/persistence/ConditionalControllerPersistence.java 
    2014-03-10 08:37:37 UTC (rev 17610)
+++ 
gate/trunk/src/main/gate/util/persistence/ConditionalControllerPersistence.java 
    2014-03-10 08:38:23 UTC (rev 17611)
@@ -1,10 +1,13 @@
 package gate.util.persistence;
 
-import java.util.*;
-
 import gate.creole.ConditionalController;
 import gate.creole.ResourceInstantiationException;
+import gate.creole.RunningStrategy;
 import gate.persist.PersistenceException;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
 /**
  * Persistence handler for {@link gate.creole.ConditionalController}s
  */
@@ -27,10 +30,11 @@
 
     ConditionalController controller = (ConditionalController)source;
 
-    strategiesList = new ArrayList(controller.getRunningStrategies().size());
+    /*strategiesList = new 
ArrayList<RunningStrategy>(controller.getRunningStrategies().size());
 
-    Iterator stratIter = controller.getRunningStrategies().iterator();
-    while(stratIter.hasNext()) ((List)strategiesList).add(stratIter.next());
+    Iterator<RunningStrategy> stratIter = 
controller.getRunningStrategies().iterator();
+    while(stratIter.hasNext()) ((List)strategiesList).add(stratIter.next());*/
+    strategiesList = new 
ArrayList<RunningStrategy>(controller.getRunningStrategies());
 
     strategiesList = PersistenceManager.
                      getPersistentRepresentation(strategiesList);
@@ -40,6 +44,7 @@
    * Creates a new object from the data contained. This new object is supposed
    * to be a copy for the original object used as source for data extraction.
    */
+  @SuppressWarnings("unchecked")
   @Override
   public Object createObject()throws PersistenceException,
                                      ResourceInstantiationException{
@@ -47,12 +52,12 @@
         (ConditionalController)super.createObject();
 //    if(controller.getRunningStrategies().isEmpty()){
     controller.setRunningStrategies(
-          (Collection)PersistenceManager.
+          (Collection<RunningStrategy>)PersistenceManager.
           getTransientRepresentation(strategiesList));
 //    }
     return controller;
   }
-  protected Object strategiesList;
+  protected Serializable strategiesList;
 
   /**
    * Serialisation ID

Modified: gate/trunk/src/main/gate/util/persistence/ControllerPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/ControllerPersistence.java        
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/ControllerPersistence.java        
2014-03-10 08:38:23 UTC (rev 17611)
@@ -14,12 +14,14 @@
  */
 package gate.util.persistence;
 
-import java.util.*;
-
 import gate.Controller;
+import gate.ProcessingResource;
 import gate.creole.ResourceInstantiationException;
 import gate.persist.PersistenceException;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 public class ControllerPersistence extends ResourcePersistence {
   /**
    * Populates this Persistence with the data that needs to be stored from the
@@ -37,12 +39,15 @@
     Controller controller = (Controller)source;
 
     super.extractDataFromSource(source);
-    prList = new ArrayList(controller.getPRs().size());
+    /*prList = new ArrayList(controller.getPRs().size());
     Iterator prIter = controller.getPRs().iterator();
 
     while(prIter.hasNext()){
       ((List)prList).add(prIter.next());
-    }
+    }*/
+    
+    prList = new ArrayList<ProcessingResource>(controller.getPRs());
+    
     prList = PersistenceManager.getPersistentRepresentation(prList);
   }
 
@@ -50,6 +55,7 @@
    * Creates a new object from the data contained. This new object is supposed
    * to be a copy for the original object used as source for data extraction.
    */
+  @SuppressWarnings("unchecked")
   @Override
   public Object createObject()throws PersistenceException,
                                      ResourceInstantiationException{
@@ -58,7 +64,7 @@
 
     if(controller.getPRs().isEmpty()){
       prList = PersistenceManager.getTransientRepresentation(prList);
-      controller.setPRs((Collection)prList);
+      controller.setPRs((Collection<ProcessingResource>)prList);
     }
 
     return controller;

Modified: gate/trunk/src/main/gate/util/persistence/CorpusPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/CorpusPersistence.java    
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/CorpusPersistence.java    
2014-03-10 08:38:23 UTC (rev 17611)
@@ -16,15 +16,17 @@
 package gate.util.persistence;
 
 
-import java.util.ArrayList;
-import java.util.Iterator;
-
 import gate.Corpus;
 import gate.Document;
 import gate.creole.ResourceInstantiationException;
 import gate.persist.PersistenceException;
 
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
+
 public class CorpusPersistence extends LRPersistence {
   /**
    * Populates this Persistence with the data that needs to be stored from the
@@ -45,8 +47,8 @@
     super.extractDataFromSource(source);
     if(dsData == null){
       //transient corpus; we still need to save the docs
-      docList = new ArrayList();
-      Iterator docIter = corpus.iterator();
+      docList = new ArrayList<Serializable>();
+      Iterator<Document> docIter = corpus.iterator();
       while(docIter.hasNext()){
         docList.add(PersistenceManager.
                     getPersistentRepresentation(docIter.next()));
@@ -70,7 +72,7 @@
     if(docList != null){
       //transient corpus; we need to recreate the docs
       if(!docList.isEmpty() && corpus.isEmpty()){
-        Iterator docIter = docList.iterator();
+        Iterator<Serializable> docIter = docList.iterator();
         while(docIter.hasNext()){
           corpus.add((Document) PersistenceManager.
                      getTransientRepresentation(docIter.next()));
@@ -82,6 +84,6 @@
   }
 
 
-  protected ArrayList docList;
+  protected List<Serializable> docList;
   static final long serialVersionUID = 6181534551802883626L;
 }
\ No newline at end of file

Modified: gate/trunk/src/main/gate/util/persistence/DSPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/DSPersistence.java        
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/DSPersistence.java        
2014-03-10 08:38:23 UTC (rev 17611)
@@ -65,9 +65,9 @@
     }
 
     //check if the same datastore is not already open
-    Iterator dsIter = Gate.getDataStoreRegister().iterator();
+    Iterator<DataStore> dsIter = Gate.getDataStoreRegister().iterator();
     while(dsIter.hasNext()){
-      DataStore aDS = (DataStore)dsIter.next();
+      DataStore aDS = dsIter.next();
       if(aDS.getStorageUrl().equals(storageUrlString)) {
         return aDS;
       }

Modified: gate/trunk/src/main/gate/util/persistence/LRPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/LRPersistence.java        
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/LRPersistence.java        
2014-03-10 08:38:23 UTC (rev 17611)
@@ -58,6 +58,7 @@
    * Creates a new object from the data contained. This new object is supposed
    * to be a copy for the original object used as source for data extraction.
    */
+  @SuppressWarnings("unchecked")
   @Override
   public Object createObject()throws PersistenceException,
                                      ResourceInstantiationException{
@@ -68,8 +69,8 @@
 
       DataStore ds = (DataStore)PersistenceManager.
                      getTransientRepresentation(dsData);
-      ((Map)initParams).put(DataStore.DATASTORE_FEATURE_NAME, ds);
-      ((Map)initParams).put(DataStore.LR_ID_FEATURE_NAME, persistenceID);
+      ((Map<Object,Object>)initParams).put(DataStore.DATASTORE_FEATURE_NAME, 
ds);
+      ((Map<Object,Object>)initParams).put(DataStore.LR_ID_FEATURE_NAME, 
persistenceID);
       return super.createObject();
     }
   }

Modified: gate/trunk/src/main/gate/util/persistence/MapPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/MapPersistence.java       
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/MapPersistence.java       
2014-03-10 08:38:23 UTC (rev 17611)
@@ -14,11 +14,14 @@
  */
 package gate.util.persistence;
 
-import java.util.*;
-
 import gate.creole.ResourceInstantiationException;
 import gate.persist.PersistenceException;
 
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
 public class MapPersistence implements Persistence {
   /**
    * Populates this Persistence with the data that needs to be stored from the
@@ -35,18 +38,17 @@
     }
     mapType = source.getClass();
 
-    Map map = (Map)source;
+    Map<?,?> map = (Map<?,?>)source;
     
-    localMap = new HashMap(map.size());
+    localMap = new HashMap<Serializable,Serializable>(map.size());
     //collect the keys in the order given by the entrySet().iterator();
-    Iterator keyIter = map.keySet().iterator();
+    Iterator<?> keyIter = map.keySet().iterator();
     while(keyIter.hasNext()){
       Object key = keyIter.next();
       Object value = map.get(key);
 
-      key = PersistenceManager.getPersistentRepresentation(key);
-      value = PersistenceManager.getPersistentRepresentation(value);
-      localMap.put(key, value);
+      localMap.put(PersistenceManager.getPersistentRepresentation(key),
+              PersistenceManager.getPersistentRepresentation(value));
     }
   }
 
@@ -54,19 +56,20 @@
    * Creates a new object from the data contained. This new object is supposed
    * to be a copy for the original object used as source for data extraction.
    */
+  @SuppressWarnings("unchecked")
   @Override
   public Object createObject()throws PersistenceException,
                                      ResourceInstantiationException{
     //let's try to create a map of the same type as the original
-    Map result = null;
+    Map<Object,Object> result = null;
     try{
-      result = (Map)mapType.newInstance();
+      result = (Map<Object,Object>)mapType.newInstance();
     }catch(Exception e){
     }
-    if(result == null) result = new HashMap(localMap.size());
+    if(result == null) result = new HashMap<Object,Object>(localMap.size());
 
     //now we have a map let's populate it
-    Iterator keyIter = localMap.keySet().iterator();
+    Iterator<Serializable> keyIter = localMap.keySet().iterator();
     while(keyIter.hasNext()){
       Object key = keyIter.next();
       Object value = localMap.get(key);
@@ -79,7 +82,7 @@
     return result;
   }
 
-  protected Class mapType;
-  protected HashMap localMap;
+  protected Class<?> mapType;
+  protected Map<Serializable,Serializable> localMap;
   static final long serialVersionUID = 1835776085941379996L;
 }
\ No newline at end of file

Modified: gate/trunk/src/main/gate/util/persistence/PRPersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/PRPersistence.java        
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/PRPersistence.java        
2014-03-10 08:38:23 UTC (rev 17611)
@@ -14,13 +14,21 @@
  */
 package gate.util.persistence;
 
-import java.util.*;
-
-import gate.*;
-import gate.creole.*;
+import gate.Factory;
+import gate.FeatureMap;
+import gate.Gate;
+import gate.ProcessingResource;
+import gate.Resource;
+import gate.creole.Parameter;
+import gate.creole.ParameterList;
+import gate.creole.ResourceData;
+import gate.creole.ResourceInstantiationException;
 import gate.persist.PersistenceException;
 
+import java.util.Iterator;
+import java.util.List;
 
+
 public class PRPersistence extends ResourcePersistence {
   /**
    * Populates this Persistence with the data that needs to be stored from the
@@ -50,14 +58,14 @@
       //get the values for the init time parameters
       runtimeParams = Factory.newFeatureMap();
       //this is a list of lists
-      Iterator parDisjIter = ((List)params.getRuntimeParameters()).iterator();
+      Iterator<List<Parameter>> parDisjIter = 
params.getRuntimeParameters().iterator();
       while(parDisjIter.hasNext()){
-        Iterator parIter = ((List)parDisjIter.next()).iterator();
+        Iterator<Parameter> parIter = parDisjIter.next().iterator();
         while(parIter.hasNext()){
-          Parameter parameter = (Parameter)parIter.next();
+          Parameter parameter = parIter.next();
           String parName = parameter.getName();
           Object parValue = res.getParameterValue(parName);
-          ((Map)runtimeParams).put(parName,parValue);
+          ((FeatureMap)runtimeParams).put(parName,parValue);
         }
       }
       runtimeParams = PersistenceManager.

Modified: gate/trunk/src/main/gate/util/persistence/PersistenceManager.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/PersistenceManager.java   
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/PersistenceManager.java   
2014-03-10 08:38:23 UTC (rev 17611)
@@ -734,7 +734,6 @@
       }
 
       // always write the list of creole URLs first
-      @SuppressWarnings("unchecked")
       List<URL> urlList = new 
ArrayList<URL>(Gate.getCreoleRegister().getDirectories());
       Object persistentList = getPersistentRepresentation(urlList);
 

Modified: gate/trunk/src/main/gate/util/persistence/ResourcePersistence.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/ResourcePersistence.java  
2014-03-10 08:37:37 UTC (rev 17610)
+++ gate/trunk/src/main/gate/util/persistence/ResourcePersistence.java  
2014-03-10 08:38:23 UTC (rev 17611)
@@ -14,13 +14,20 @@
  */
 package gate.util.persistence;
 
-import java.util.*;
-
-import gate.*;
-import gate.creole.*;
+import gate.Factory;
+import gate.FeatureMap;
+import gate.Gate;
+import gate.Resource;
+import gate.creole.Parameter;
+import gate.creole.ParameterList;
+import gate.creole.ResourceData;
+import gate.creole.ResourceInstantiationException;
 import gate.persist.PersistenceException;
 import gate.util.NameBearer;
 
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * Holds the data needed to serialise and recreate a {@link Resource}.
  * This data is considered to be: the resource class name, the resource name,
@@ -50,14 +57,14 @@
       //get the values for the init time parameters
       initParams = Factory.newFeatureMap();
       //this is a list of lists
-      Iterator parDisjIter = ((List)params.getInitimeParameters()).iterator();
+      Iterator<List<Parameter>> parDisjIter = 
params.getInitimeParameters().iterator();
       while(parDisjIter.hasNext()){
-        Iterator parIter = ((List)parDisjIter.next()).iterator();
+        Iterator<Parameter> parIter = parDisjIter.next().iterator();
         while(parIter.hasNext()){
-          Parameter parameter = (Parameter)parIter.next();
+          Parameter parameter = parIter.next();
           String parName = parameter.getName();
           Object parValue = res.getParameterValue(parName);
-          ((Map)initParams).put(parName, parValue);
+          ((FeatureMap)initParams).put(parName, parValue);
         }
       }
       initParams = PersistenceManager.getPersistentRepresentation(initParams);
@@ -65,7 +72,7 @@
       //get the features
       if(res.getFeatures() != null){
         features = Factory.newFeatureMap();
-        ((Map)features).putAll(res.getFeatures());
+        ((FeatureMap)features).putAll(res.getFeatures());
         features = PersistenceManager.getPersistentRepresentation(features);
       }
     }catch(ResourceInstantiationException rie){

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to