Author: mes
Date: 2011-03-08 15:26:51 -0800 (Tue, 08 Mar 2011)
New Revision: 24341

Modified:
   core3/model-api/trunk/src/main/java/org/cytoscape/model/CyNode.java
   
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
   
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CySubNetwork.java
   
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyNodeTest.java
   core3/model-api/trunk/src/test/java/org/cytoscape/model/DummyCyNode.java
   
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCyRootNetworkTest.java
   
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
Log:
added better support for groups/metanodes based on mini retreat discussion

Modified: core3/model-api/trunk/src/main/java/org/cytoscape/model/CyNode.java
===================================================================
--- core3/model-api/trunk/src/main/java/org/cytoscape/model/CyNode.java 
2011-03-08 23:16:32 UTC (rev 24340)
+++ core3/model-api/trunk/src/main/java/org/cytoscape/model/CyNode.java 
2011-03-08 23:26:51 UTC (rev 24341)
@@ -38,13 +38,6 @@
  */
 public interface CyNode extends CyTableEntry {
        
-       /** The column name for the nested network associated with a 
<code>CyNode</code> in the user table. */
-       final static String NESTED_NETWORK_ATTR = "NestedNetwork";
-
-       /** The column name for the attribute that allows testing of whether a 
<code>CyNode</code>
-           has an associated nested network or not.  (Found in the user 
table.) */
-       final static String HAS_NESTED_NETWORK_ATTR = "hasNestedNetwork";
-
        /**
         * An index of this node within this network.  The index is guaranteed 
to
         * be between 0 and (the number of nodes in the network) - 1. This index
@@ -55,28 +48,27 @@
        int getIndex();
 
        /**
-        * Returns the nested network associated with this node.  If no nested
+        * Returns the network referenced by this node.  If no 
         * network has been specified this method will return null.
         * 
-        * @return A reference to the nested CyNetwork if one exists, 
+        * @return A reference to a CyNetwork if one exists, 
         * returns null otherwise.
         */
-       CyNetwork getNestedNetwork();
+       CyNetwork getNetwork();
 
        /**
-        * Allows the nested network for this network to be set. Only one
-        * nested network may be set for a given node. Any CyNetwork may
-        * be used (the network does not need to be a subnetwork of the 
-        * network that contains this node). To unset a nested network, use
+        * Allows a network reference for this node to be set. Only one
+        * network may be set for a given node. Any CyNetwork may
+        * be used (the network may be a subnetwork of the network that
+        * contains this node, but it is not mandatory). To unset a network, use
         * null as an argument. 
         *
-        * @param nestedNetwork The network that is to be referenced by this 
node. If
+        * @param network The network that is to be referenced by this node. If
         * this value is null, any existing reference will be removed.
         *
-        * Note that this if a previous nested network is being replaced or 
nulled out, an
-        * {@link UnsetNestedNetworkEvent} will be fired and if a new nested 
network will be set a
-        * {@link SetNestedNetworkEvent} will be fired.  Furthermore the (@link 
NESTED_NETWORK_ATTR}
-        * and {@link HAS_NESTED_NETWORK_ATTR} columns in the user table will 
be updated.
+        * Note that this if a previous referenced network is being replaced or 
nulled out, an
+        * {@link UnsetNestedNetworkEvent} will be fired and if a new network 
will be set a
+        * {@link SetNestedNetworkEvent} will be fired.  
         */
-       void setNestedNetwork(CyNetwork nestedNetwork);
+       void setNetwork(CyNetwork network);
 }

Modified: 
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
===================================================================
--- 
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
       2011-03-08 23:16:32 UTC (rev 24340)
+++ 
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
       2011-03-08 23:26:51 UTC (rev 24341)
@@ -72,6 +72,17 @@
        CySubNetwork addSubNetwork();
 
        /**
+        * Create a {@link CySubNetwork} containing the specified {@link 
CyNode}s and
+        * {@link CyEdge}s. The nodes and edges must already exist in this root 
network.
+        * Nodes defining the source and target of edges that have not yet been 
added
+        * to the subnetwork will be added.
+        * @param nodes The nodes to be added to the network. May be null or 
empty.
+        * @param edges The edges to be added to the network. May be null or 
empty.
+        * @return  The created {@link CySubNetwork}.
+        */
+       CySubNetwork addSubNetwork(Iterable<CyNode> nodes, Iterable<CyEdge> 
edges);
+
+       /**
         * Removes the subnetwork from the root network, but not the nodes and 
edges contained 
         * in the subnetwork.
         * @param sub  the {@link CySubNetwork} to remove.
@@ -89,4 +100,11 @@
         * began with something, and this network is that something.
         */
        CySubNetwork getBaseNetwork();
+
+       /**
+        * Returns true if the network to be checked is a subnetwork of this 
root network and
+        * returns false otherwise. Will return false if the network is null.
+        * @param n The network to be checked.
+        */
+       boolean containsNetwork(CyNetwork n);
 }

Modified: 
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CySubNetwork.java
===================================================================
--- 
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CySubNetwork.java
        2011-03-08 23:16:32 UTC (rev 24340)
+++ 
core3/model-api/trunk/src/main/java/org/cytoscape/model/subnetwork/CySubNetwork.java
        2011-03-08 23:26:51 UTC (rev 24341)
@@ -54,7 +54,7 @@
 
        /**
         * Adds a node to this {@link CySubNetwork}.  Note that the added node
-        * is not a new node, and must already exist in the {@link 
CyRootNetwork}.
+        * is not a new node and must already exist in the {@link 
CyRootNetwork}.
         * @param node  CyNode to add to this subnetwork
         * @return true if the node was successfully added to the subnetwork, 
         * false otherwise.
@@ -63,7 +63,10 @@
 
        /**
         * Adds an edge to this {@link CySubNetwork}.  Note that the added edge
-        * is not a new edge, and must already exist in the {@link 
CyRootNetwork}.
+        * is not a new edge and must already exist in the {@link 
CyRootNetwork}.
+        * If the nodes that define the source and target of the edge are not 
yet
+        * contained in the subnetwork, they will be added. The nodes must also
+        * already exist in the {@link CyRootNetwork}.
         * @param edge  CyEdge to add to this subnetwork
         * @return true if the edge was successfully added to the subnetwork, 
         * false otherwise.

Modified: 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyNodeTest.java
===================================================================
--- 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyNodeTest.java 
    2011-03-08 23:16:32 UTC (rev 24340)
+++ 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyNodeTest.java 
    2011-03-08 23:26:51 UTC (rev 24341)
@@ -71,23 +71,23 @@
        // by default a node should have a null nested network
        public void testInitGetNestedNetwork() {
                CyNode n1 = net.addNode();
-               assertNull(n1.getNestedNetwork());
+               assertNull(n1.getNetwork());
        }
 
        public void testSetNestedNetwork() {
                CyNode n1 = net.addNode();
                CyNetwork net2 = mock(CyNetwork.class);
-               n1.setNestedNetwork( net2 );
-               assertNotNull(n1.getNestedNetwork());
-               assertEquals(net2, n1.getNestedNetwork());
+               n1.setNetwork( net2 );
+               assertNotNull(n1.getNetwork());
+               assertEquals(net2, n1.getNetwork());
        }
 
        // self nested networks are allowed
        public void testSetSelfNestedNetwork() {
                CyNode n1 = net.addNode();
-               n1.setNestedNetwork( net );
-               assertNotNull(n1.getNestedNetwork());
-               assertEquals(net, n1.getNestedNetwork());
+               n1.setNetwork( net );
+               assertNotNull(n1.getNetwork());
+               assertEquals(net, n1.getNetwork());
        }
 
        // null nested networks are allowed
@@ -96,13 +96,13 @@
 
                // put a real network here first 
                CyNetwork net2 = mock(CyNetwork.class);
-               n1.setNestedNetwork( net2 );
-               assertNotNull(n1.getNestedNetwork());
-               assertEquals(net2, n1.getNestedNetwork());
+               n1.setNetwork( net2 );
+               assertNotNull(n1.getNetwork());
+               assertEquals(net2, n1.getNetwork());
        
                // now put a null network to verify that we've "unset" things
-               n1.setNestedNetwork( null );
-               assertNull(n1.getNestedNetwork());
+               n1.setNetwork( null );
+               assertNull(n1.getNetwork());
        }
 
        public void testRemoveNodeIndexStaysConstant() {
@@ -131,20 +131,4 @@
                assertNull(net.getNode(0));
                assertEquals(n1,net.getNode(1));
        }
-
-       public void testNestedNetworkUserTableUpdates() {
-               CyNode n1 = net.addNode();
-               CyNetwork net2 = mock(CyNetwork.class);
-               when(net2.getSUID()).thenReturn(223L);
-               final CyRow row = n1.getCyRow();
-               assertFalse(row.isSet(CyNode.NESTED_NETWORK_ATTR));
-               assertFalse(row.get(CyNode.HAS_NESTED_NETWORK_ATTR, 
Boolean.class));
-               n1.setNestedNetwork(net2);
-               assertTrue(row.isSet(CyNode.NESTED_NETWORK_ATTR));
-               assertTrue(row.get(CyNode.HAS_NESTED_NETWORK_ATTR, 
Boolean.class));
-               assertEquals("223", row.get(CyNode.NESTED_NETWORK_ATTR, 
String.class));
-               n1.setNestedNetwork(null);
-               assertFalse(row.isSet(CyNode.NESTED_NETWORK_ATTR));
-               assertFalse(row.get(CyNode.HAS_NESTED_NETWORK_ATTR, 
Boolean.class));
-       }
 }

Modified: 
core3/model-api/trunk/src/test/java/org/cytoscape/model/DummyCyNode.java
===================================================================
--- core3/model-api/trunk/src/test/java/org/cytoscape/model/DummyCyNode.java    
2011-03-08 23:16:32 UTC (rev 24340)
+++ core3/model-api/trunk/src/test/java/org/cytoscape/model/DummyCyNode.java    
2011-03-08 23:26:51 UTC (rev 24341)
@@ -65,11 +65,11 @@
                return new ArrayList<CyEdge>();
        }
 
-       public CyNetwork getNestedNetwork() {
+       public CyNetwork getNetwork() {
                return nested;
        }
 
-       public void setNestedNetwork(CyNetwork n) {
+       public void setNetwork(CyNetwork n) {
                nested = n;
        }
 }

Modified: 
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCyRootNetworkTest.java
===================================================================
--- 
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCyRootNetworkTest.java
   2011-03-08 23:16:32 UTC (rev 24340)
+++ 
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCyRootNetworkTest.java
   2011-03-08 23:26:51 UTC (rev 24341)
@@ -48,6 +48,8 @@
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.DummyCyNode;
+import org.cytoscape.model.DummyCyEdge;
 
 import java.lang.RuntimeException;
 
@@ -55,6 +57,7 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Map;
+import java.util.Arrays;
 
 
 /**
@@ -530,4 +533,130 @@
                        fail("shouldn't throw exception for trying to remove 
null network");
                }
        }
+
+       public void testContainsNetwork() {
+               CySubNetwork s1 = root.addSubNetwork();
+               assertTrue(root.containsNetwork(s1));
+       }
+
+       public void testNotContainsNetwork() {
+               CySubNetwork s2 = root2.addSubNetwork();
+               assertFalse(root.containsNetwork(s2));
+       }
+
+       public void testNullContainsNetwork() {
+               assertFalse(root.containsNetwork(null));
+       }
+
+       public void testAddSubNetworkWithGoodNodesAndGoodEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyNode n3 = root.addNode();
+               CyEdge e1 = root.addEdge(n1,n2,false);
+
+               List<CyNode> nodes = Arrays.asList(n1, n2, n3 );
+               List<CyEdge> edges = Arrays.asList( e1 );
+
+               CySubNetwork n = root.addSubNetwork(nodes, edges);
+
+               assertTrue( n.containsNode(n1) );
+               assertTrue( n.containsNode(n2) );
+               assertTrue( n.containsNode(n3) );
+               assertTrue( n.containsEdge(e1) );
+       }
+
+       public void testAddSubNetworkWithNullNodesAndGoodEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyEdge e1 = root.addEdge(n1,n2,false);
+
+               List<CyEdge> edges = Arrays.asList( e1 );
+
+               CySubNetwork n = root.addSubNetwork(null, edges);
+
+               assertTrue(n.containsNode(n1) );
+               assertTrue(n.containsNode(n2) );
+               assertTrue(n.containsEdge(e1) );
+       }
+
+       public void testAddSubNetworkWithGoodNodesAndNullEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyNode n3 = root.addNode();
+
+               List<CyNode> nodes = Arrays.asList( n1, n2, n3 );
+
+               CySubNetwork n = root.addSubNetwork(nodes, null);
+
+               assertTrue( n.containsNode(n1) );
+               assertTrue( n.containsNode(n2) );
+               assertTrue( n.containsNode(n3) );
+       }
+
+       public void testAddSubNetworkWithEmptyNodesAndGoodEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyEdge e1 = root.addEdge(n1,n2,false);
+
+               List<CyNode> nodes = new ArrayList<CyNode>(); 
+               List<CyEdge> edges = Arrays.asList( e1 );
+
+               CySubNetwork n = root.addSubNetwork(nodes, edges);
+
+               assertTrue( n.containsNode(n1) );
+               assertTrue( n.containsNode(n2) );
+               assertTrue( n.containsEdge(e1) );
+       }
+
+       public void testAddSubNetworkWithGoodNodesAndEmptyEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyNode n3 = root.addNode();
+
+               List<CyNode> nodes = Arrays.asList( n1, n2, n3 );
+               List<CyEdge> edges = new ArrayList<CyEdge>(); 
+
+               CySubNetwork n = root.addSubNetwork(nodes, edges);
+
+               assertTrue( n.containsNode(n1) );
+               assertTrue( n.containsNode(n2) );
+               assertTrue( n.containsNode(n3) );
+       }
+
+       public void testAddSubNetworkWithInvalidNodesAndGoodEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyEdge e1 = root.addEdge(n1,n2,false);
+
+               CyNode b1 = new DummyCyNode(74);
+               CyNode b2 = new DummyCyNode(75);
+               List<CyNode> nodes = Arrays.asList( b1, b2 );
+               List<CyEdge> edges = Arrays.asList( e1 );
+
+               try {
+                       CySubNetwork n = root.addSubNetwork(nodes, edges);
+               } catch (IllegalArgumentException iae) {
+                       return;
+               }
+
+               fail("shouldn't allow nodes not in root network to be used");
+       }
+
+       public void testAddSubNetworkWithGoodNodesAndInvalidEdges() {
+               CyNode n1 = root.addNode();
+               CyNode n2 = root.addNode();
+               CyNode n3 = root.addNode();
+               
+               CyEdge ex = new DummyCyEdge(null,null,false,50);
+               List<CyNode> nodes = Arrays.asList( n1, n2, n3 );
+               List<CyEdge> edges = Arrays.asList( ex );
+
+               try {
+                       CySubNetwork n = root.addSubNetwork(nodes, edges);
+               } catch (IllegalArgumentException iae) {
+                       return;
+               }
+
+               fail("shouldn't allow edges not in root network to be used");
+       }
 }

Modified: 
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
===================================================================
--- 
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
    2011-03-08 23:16:32 UTC (rev 24340)
+++ 
core3/model-api/trunk/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
    2011-03-08 23:26:51 UTC (rev 24341)
@@ -50,6 +50,7 @@
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyRow;
+import org.cytoscape.model.DummyCyEdge;
 
 import java.lang.RuntimeException;
 
@@ -301,32 +302,26 @@
                assertEquals("edge list 
size",r2.getEdgeList().size(),root.getEdgeList().size());
        }
 
-       public void testAddEdgeBadSource() {
+       public void testAddEdgeNotYetAddedSource() {
                defaultSetup();
-
-               try {
-                       sub.addEdge(e3);
-               } catch (Exception e) {
-                       noChangeChecks();
-                       return;
-               }
-
-               // if we don't get an exception
-               fail();
+               assertTrue(sub.addEdge(e3));
        }
 
-       public void testAddEdgeBadTarget() {
+       public void testAddEdgeNotYetAddedTarget() {
                defaultSetup();
+               CyEdge e4 = root.addEdge(n4,n1,true);
+               assertTrue(sub.addEdge(e4));
+       }
 
+       public void testAddEdgeBadEdge() {
+               defaultSetup();
+               CyEdge ex = new DummyCyEdge(null,null,true,100);
                try {
-                       CyEdge e4 = root.addEdge(n4,n1,true);
-                       sub.addEdge(e4);
-               } catch (Exception e) {
+                       sub.addEdge(ex);
+               } catch (IllegalArgumentException e) {
+                       noChangeChecks();
                        return;
                }
-
-               // if we don't get an exception
-               fail();
        }
 
        public void testAddNodeInSubNetwork() {

-- 
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