Author: mes
Date: 2010-10-26 11:06:51 -0700 (Tue, 26 Oct 2010)
New Revision: 22441

Modified:
   
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
   
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableManagerImpl.java
   core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
   
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
   
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
Log:
Moved management duties from CyTableFactory into CyTableManager

Modified: 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
===================================================================
--- 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
   2010-10-26 18:04:39 UTC (rev 22440)
+++ 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableFactoryImpl.java
   2010-10-26 18:06:51 UTC (rev 22441)
@@ -52,45 +52,17 @@
  */
 public class CyTableFactoryImpl implements CyTableFactory {
 
-       private final Map<Long,CyTable> tables;
        private final CyEventHelper help;
+       private final CyTableManagerImpl tm;
 
-       public CyTableFactoryImpl(CyEventHelper help) {
+       public CyTableFactoryImpl(CyEventHelper help, CyTableManagerImpl tm) {
                this.help = help;
-               tables = new HashMap<Long,CyTable>();
+               this.tm = tm;
        }
 
        public CyTable createTable(String name, String primaryKey, Class<?> 
primaryKeyType, boolean pub) {
                CyTable cdt = new 
CyTableImpl(name,primaryKey,primaryKeyType,pub,help);
-               tables.put( cdt.getSUID(), cdt );
+               tm.addTable(cdt);
                return cdt;
        }
-
-       /**
-     * @param includePrivate Whether to include private CyDataTables
-     * in the list (i.e. all possible CyDataTables) or not.
-     * @return A list containing CyTable SUIDs either
-     * including private CyDataTables (i.e. meaning all possible
-     * CyDataTables) or just public CyDataTables.
-     */
-       public List<Long> getAllTableSUIDs(boolean includePrivate) {
-               List<Long> suids = new ArrayList<Long>(tables.keySet().size());
-               for ( Long key : tables.keySet() ) {
-                       if ( includePrivate )
-                               suids.add(key);
-                       else if ( tables.get(key).isPublic() )
-                               suids.add(key);
-               }
-               return suids;
-       }
-
-       /**
-        * @param suid The SUID identifying the CyTable.
-        *
-        * @return The CyTable identified by the suid. Will return null if a 
CyTable doesn't
-        *         exist for the  specified SUID.
-        */
-       public CyTable getTable(long suid) {
-               return tables.get(suid);
-       }
 }

Modified: 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableManagerImpl.java
===================================================================
--- 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableManagerImpl.java
   2010-10-26 18:04:39 UTC (rev 22440)
+++ 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyTableManagerImpl.java
   2010-10-26 18:06:51 UTC (rev 22441)
@@ -38,10 +38,13 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 import org.cytoscape.model.CyTable;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.CyTableEntry;
 
 /**
  * An interface describing a factory used for managing 
@@ -50,13 +53,16 @@
  */
 public class CyTableManagerImpl implements CyTableManager {
 
-       private final Map<String, Map<CyNetwork, Map<String,CyTable>>> map;
+       private final Map<String, Map<CyNetwork, Map<String,CyTable>>> 
networkTableMap;
+       private final Map<Long,CyTable> tables;
 
        public CyTableManagerImpl() {
-               map = new HashMap<String, Map<CyNetwork, 
Map<String,CyTable>>>();       
-               map.put( "NETWORK", new HashMap<CyNetwork, 
Map<String,CyTable>>() );
-               map.put( "NODE", new HashMap<CyNetwork, Map<String,CyTable>>() 
);
-               map.put( "EDGE", new HashMap<CyNetwork, Map<String,CyTable>>() 
);
+               networkTableMap = new HashMap<String, Map<CyNetwork, 
Map<String,CyTable>>>();   
+               networkTableMap.put( CyTableEntry.NETWORK, new 
HashMap<CyNetwork, Map<String,CyTable>>() );
+               networkTableMap.put( CyTableEntry.NODE, new HashMap<CyNetwork, 
Map<String,CyTable>>() );
+               networkTableMap.put( CyTableEntry.EDGE, new HashMap<CyNetwork, 
Map<String,CyTable>>() );
+
+               tables = new HashMap<Long,CyTable>();
        }
        
 
@@ -64,12 +70,12 @@
                if ( network == null || graphObjectType == null )
                        return null;
 
-               Map<CyNetwork, Map<String,CyTable>> tmap = 
map.get(graphObjectType);
+               Map<CyNetwork, Map<String,CyTable>> tmap = 
networkTableMap.get(graphObjectType);
 
                if ( tmap == null )
                        throw new IllegalArgumentException("no data tables of 
type: " + graphObjectType + " exist");
 
-               return map.get(graphObjectType).get(network);
+               return networkTableMap.get(graphObjectType).get(network);
        }
 
        
@@ -79,10 +85,10 @@
                if ( graphObjectType == null )
                        throw new NullPointerException("Type is null");
 
-               if ( !map.containsKey(graphObjectType) )
-                       map.put(graphObjectType, new HashMap<CyNetwork, 
Map<String,CyTable>>());
+               if ( !networkTableMap.containsKey(graphObjectType) )
+                       networkTableMap.put(graphObjectType, new 
HashMap<CyNetwork, Map<String,CyTable>>());
 
-               Map<CyNetwork, Map<String,CyTable>> tmap = 
map.get(graphObjectType);
+               Map<CyNetwork, Map<String,CyTable>> tmap = 
networkTableMap.get(graphObjectType);
 
                if ( tm == null )
                        tmap.remove(network);
@@ -90,4 +96,24 @@
                        tmap.put(network,tm);
        }
 
+       public void addTable(CyTable t) {
+               if ( t == null )
+                       throw new NullPointerException("added table is null");
+               tables.put( t.getSUID(), t );
+       }
+
+       public Set<CyTable> getAllTables(boolean includePrivate) {
+               Set<CyTable> res = new HashSet<CyTable>();
+               for ( CyTable t : tables.values() ) {
+                       if ( includePrivate )
+                               res.add(t);
+                       else if ( tables.get(t).isPublic() )
+                               res.add(t);
+               }
+               return res;
+       }
+
+       public CyTable getTable(long suid) {
+               return tables.get(suid);
+       }
 }

Modified: 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml    
    2010-10-26 18:04:39 UTC (rev 22440)
+++ 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml    
    2010-10-26 18:06:51 UTC (rev 22441)
@@ -20,6 +20,7 @@
 
        <bean id="cyDataTableFactory" 
class="org.cytoscape.model.internal.CyTableFactoryImpl">
                <constructor-arg ref="cyEventHelperServiceRef" />
+               <constructor-arg ref="cyTableManager" />
        </bean>
 
        <bean id="cyNetworkFactory" 
class="org.cytoscape.model.internal.CyNetworkFactoryImpl">

Modified: 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
===================================================================
--- 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
    2010-10-26 18:04:39 UTC (rev 22440)
+++ 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
    2010-10-26 18:06:51 UTC (rev 22441)
@@ -48,7 +48,7 @@
                CyTableManagerImpl mgrImpl = new CyTableManagerImpl();
                mgr = mgrImpl; 
                CyEventHelper eh = new DummyCyEventHelper(); 
-               goodNetwork = new ArrayGraph(eh,mgrImpl,new 
CyTableFactoryImpl(eh)).getBaseNetwork();
+               goodNetwork = new ArrayGraph(eh,mgrImpl,new 
CyTableFactoryImpl(eh,mgrImpl)).getBaseNetwork();
        }
 
        public void tearDown() {

Modified: 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
===================================================================
--- 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
  2010-10-26 18:04:39 UTC (rev 22440)
+++ 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
  2010-10-26 18:06:51 UTC (rev 22441)
@@ -51,16 +51,13 @@
        public TestCyNetworkFactory() {};
 
        public static CyNetwork getInstance() {
-               DummyCyEventHelper deh = new DummyCyEventHelper();
-               ArrayGraph ar = new ArrayGraph(deh, new 
CyTableManagerImpl(),new CyTableFactoryImpl(deh));
-               return ar.getBaseNetwork();
+               return getRootInstance().getBaseNetwork();
        }
 
        public static CyRootNetwork getRootInstance() { 
-               // This only works because we know that ArrayGraph (returned 
from 
-               // getInstance) is also a root network!
                DummyCyEventHelper deh = new DummyCyEventHelper();
-               ArrayGraph ar = new ArrayGraph(deh, new 
CyTableManagerImpl(),new CyTableFactoryImpl(deh));
+               CyTableManagerImpl tm = new CyTableManagerImpl();
+               ArrayGraph ar = new ArrayGraph(deh, tm,new 
CyTableFactoryImpl(deh,tm));
                return ar; 
        }
        

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to