Author: apico
Date: 2012-09-25 18:34:26 -0700 (Tue, 25 Sep 2012)
New Revision: 30484

Modified:
   
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CyNetworkNamingImpl.java
Log:
completed fix to naming convention for duplicate networks via import or 
new-from-selected

Modified: 
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CyNetworkNamingImpl.java
===================================================================
--- 
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CyNetworkNamingImpl.java
    2012-09-25 23:49:07 UTC (rev 30483)
+++ 
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CyNetworkNamingImpl.java
    2012-09-26 01:34:26 UTC (rev 30484)
@@ -36,6 +36,8 @@
 import org.cytoscape.session.CyNetworkNaming;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 
 public class CyNetworkNamingImpl implements CyNetworkNaming {
@@ -53,8 +55,18 @@
        
        @Override
        public String getSuggestedSubnetworkTitle(final CyNetwork 
parentNetwork) {
-               for (int i = 0; true; i++) {
-                       final String parentName = 
parentNetwork.getRow(parentNetwork).get(CyNetwork.NAME, String.class);
+                String parentName = 
parentNetwork.getRow(parentNetwork).get(CyNetwork.NAME, String.class);
+
+                Pattern p = Pattern.compile(".*\\((\\d*)\\)$"); //capture just 
the digits
+                Matcher m = p.matcher(parentName);
+                int start = 0;
+
+                if (m.matches()){
+                        parentName = parentName.substring(0, m.start(1)-1);
+                        start = Integer.decode(m.group(1));
+                }
+
+                for (int i = start; true; i++) {
                        final String nameCandidate = parentName + "(" + (i+1) + 
")";
 
                        if (!isNetworkTitleTaken(nameCandidate))
@@ -70,9 +82,18 @@
                        logger.warn("getSuggestedNetworkTitle: desiredTitle " + 
"was '" + desiredTitle + "'");
                }
                
-               for (int i = 0; true; i++) {
-                       String titleCandidate = desiredTitle + ((i == 0) ? "" : 
(" <" + i + ">"));
+               Pattern p = Pattern.compile(".*_(\\d*)$"); //capture just the 
digits
+               Matcher m = p.matcher(desiredTitle);
+               int start = 0;
 
+               if (m.matches()){
+                       desiredTitle = desiredTitle.substring(0, m.start(1)-1);
+                       start = Integer.decode(m.group(1)) + 1;
+               }
+
+               for (int i = start; true; i++) {
+                       final String titleCandidate = desiredTitle + ((i == 0) 
? "" : ("_" + i ));
+
                        if (!isNetworkTitleTaken(titleCandidate))
                                return titleCandidate;
                }

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