Author: clopes
Date: 2012-07-26 13:01:53 -0700 (Thu, 26 Jul 2012)
New Revision: 30000

Modified:
   
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyNetworkFactory.java
   
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
   
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/subnetwork/CyRootNetworkTest.java
Log:
CyRootNetwork.addSubNetwork(SavePolicy) throws an exception if the root 
network's save policy is "DO_NOT_SAVE" and the policy for the new subnetwork is 
not the same.
Updated the javadoc.

Modified: 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyNetworkFactory.java
===================================================================
--- 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyNetworkFactory.java
   2012-07-26 18:02:24 UTC (rev 29999)
+++ 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyNetworkFactory.java
   2012-07-26 20:01:53 UTC (rev 30000)
@@ -38,6 +38,8 @@
        /**
         * Returns a new, empty {@link CyNetwork} object.
         * The new network's save policy is {@link SavePolicy#SESSION_FILE} by 
default.
+        * If you want to create a network that should not be saved in session 
files, use
+        * the {@link #createNetwork(SavePolicy)} method instead, and set the 
save policy to {@link SavePolicy#DO_NOT_SAVE}.
         * @return A new, empty {@link CyNetwork} object. 
         */
        CyNetwork createNetwork();
@@ -54,6 +56,8 @@
         * This method should only be used in special cases where the network 
created is not intended to
         * be used or shared like a normal network within the system.
         * The new network's save policy is {@link SavePolicy#SESSION_FILE} by 
default.
+        * If you want to create a network that should not be saved in session 
files, use
+        * the {@link #createNetwork(SavePolicy)} method instead, and set the 
save policy to {@link SavePolicy#DO_NOT_SAVE}.
         * @return A new, empty {@link CyNetwork} object. 
         */
        CyNetwork createNetworkWithPrivateTables();

Modified: 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
===================================================================
--- 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
   2012-07-26 18:02:24 UTC (rev 29999)
+++ 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
   2012-07-26 20:01:53 UTC (rev 30000)
@@ -90,15 +90,19 @@
 
        /**
         * Create an empty {@link CySubNetwork}.
-        * The new subnetwork is created with the same save policy of its 
CyRootNetwork.
+        * The new subnetwork is created with the same save policy of its root 
network. If you want to set a different 
+        * save policy to the new subnetwork, just use {@link 
#addSubNetwork(SavePolicy)}.
         * @return  The created {@link CySubNetwork}.
         */
        CySubNetwork addSubNetwork();
        
        /**
-        * Create an empty {@link CySubNetwork} which can have a different save 
policy from that of this CyRootNetwork.
+        * Create an empty {@link CySubNetwork} which can have a different save 
policy from that of this root network,
+        * as long as the root network's policy is not {@link 
SavePolicy#DO_NOT_SAVE}.
         * @param policy the save policy to follow during the life-cycle of the 
CyNetwork.
-        * @return  The created {@link CySubNetwork}.
+        * @return The created {@link CySubNetwork}.
+        * @throws IllegalArgumentException if the save policy of this root 
network is
+        *         {@link SavePolicy#DO_NOT_SAVE}, and the policy argument is 
not the same.
         */
        CySubNetwork addSubNetwork(SavePolicy policy);
 
@@ -107,7 +111,8 @@
         * {@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.
-        * The new subnetwork is created with the same save policy of its 
CyRootNetwork.
+        * The new subnetwork is created with the same save policy of its root 
network. If you want to set a different 
+        * save policy to the new subnetwork, just use {@link 
#addSubNetwork(Iterable, Iterable, SavePolicy)}.
         * @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}.
@@ -119,10 +124,14 @@
         * {@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.
+        * The new {@link CySubNetwork} can have a different save policy from 
that of this root network, as long as the
+        * root network's policy is not {@link SavePolicy#DO_NOT_SAVE}.
         * @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.
         * @param policy the save policy to follow during the life-cycle of the 
CyNetwork.
         * @return  The created {@link CySubNetwork}.
+        * @throws IllegalArgumentException if the save policy of this root 
network is
+        *         {@link SavePolicy#DO_NOT_SAVE}, and the policy argument is 
not the same.
         */
        CySubNetwork addSubNetwork(Iterable<CyNode> nodes, Iterable<CyEdge> 
edges, SavePolicy policy);
 

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
  2012-07-26 18:02:24 UTC (rev 29999)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
  2012-07-26 20:01:53 UTC (rev 30000)
@@ -264,7 +264,14 @@
        }
        
        @Override
-       public synchronized CySubNetwork addSubNetwork(final SavePolicy policy) 
{
+       public synchronized CySubNetwork addSubNetwork(SavePolicy policy) {
+               if (policy == null)
+                       policy = savePolicy;
+               
+               if (savePolicy == SavePolicy.DO_NOT_SAVE && policy != 
savePolicy)
+                       throw new IllegalArgumentException("Cannot create 
subnetwork with \"" + policy
+                                       + "\" save policy, because this root 
network's policy is \"DO_NOT_SAVE\".");
+               
                // Subnetwork's ID
                final long newSUID = SUIDFactory.getNextSUID();
                

Modified: 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/subnetwork/CyRootNetworkTest.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/subnetwork/CyRootNetworkTest.java
        2012-07-26 18:02:24 UTC (rev 29999)
+++ 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/subnetwork/CyRootNetworkTest.java
        2012-07-26 20:01:53 UTC (rev 30000)
@@ -28,7 +28,6 @@
 package org.cytoscape.model.subnetwork;
 
 
-
 import static org.junit.Assert.*;
 
 import org.cytoscape.model.SavePolicy;
@@ -62,9 +61,20 @@
        
        @Test
        public void testAddSubNetworkWithDifferentSavePolicy() {
-               CySubNetwork sn1 = 
TestCyNetworkFactory.getPublicRootInstance(SavePolicy.SESSION_FILE).addSubNetwork(SavePolicy.DO_NOT_SAVE);
-               CySubNetwork sn2 = 
TestCyNetworkFactory.getPublicRootInstance(SavePolicy.DO_NOT_SAVE).addSubNetwork(SavePolicy.SESSION_FILE);
-               assertEquals("New subnetwork can have a different save policy", 
SavePolicy.DO_NOT_SAVE, sn1.getSavePolicy());
-               assertEquals("New subnetwork can have a different save policy", 
SavePolicy.SESSION_FILE, sn2.getSavePolicy());
+               CySubNetwork sn = 
TestCyNetworkFactory.getPublicRootInstance(SavePolicy.SESSION_FILE).addSubNetwork(SavePolicy.DO_NOT_SAVE);
+               assertEquals("New subnetwork can have a different save policy", 
SavePolicy.DO_NOT_SAVE, sn.getSavePolicy());
        }
+       
+       @Test(expected=IllegalArgumentException.class)
+       public void testAddSubNetworkWithDifferentSavePolicyThrowsException() {
+               
TestCyNetworkFactory.getPublicRootInstance(SavePolicy.DO_NOT_SAVE).addSubNetwork(SavePolicy.SESSION_FILE);
+       }
+       
+       @Test
+       public void testAddSubNetworkWithNullSavePolicy() {
+               CySubNetwork sn1 = 
TestCyNetworkFactory.getPublicRootInstance(SavePolicy.DO_NOT_SAVE).addSubNetwork(null);
+               assertEquals(SavePolicy.DO_NOT_SAVE, sn1.getSavePolicy());
+               CySubNetwork sn2 = 
TestCyNetworkFactory.getPublicRootInstance(SavePolicy.SESSION_FILE).addSubNetwork(null);
+               assertEquals(SavePolicy.SESSION_FILE, sn2.getSavePolicy());
+       }
 }

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