Author: rozagh
Date: 2012-02-10 16:18:15 -0800 (Fri, 10 Feb 2012)
New Revision: 28239

Added:
   
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyColumnTest.java
   
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyColumnTest.java
Modified:
   core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyColumn.java
   core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
   
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
Log:
fixes #567 When creating a new column or renaming a column, it checks for case 
insensitive matching column names. Unit tests for this case insensitive name 
comparision is added for both CyColumn (setNaem method) and CyTable 
(createColumn and createListColumn methods) classes. 

Modified: 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyColumn.java
===================================================================
--- core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyColumn.java   
2012-02-10 23:59:39 UTC (rev 28238)
+++ core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyColumn.java   
2012-02-11 00:18:15 UTC (rev 28239)
@@ -41,7 +41,8 @@
         */
        String getName();
 
-       /** Change the name of this column.
+       /** Change the name of this column. If another column with a matching 
name already exists, IllegalArgumentException will be thrown.
+        * The check for matching column names is case insensitive. 
         *  @param newName  the new column name
         *  @throws IllegalArgumentException if the column is immutable
         */

Modified: 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
===================================================================
--- core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java    
2012-02-10 23:59:39 UTC (rev 28238)
+++ core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java    
2012-02-11 00:18:15 UTC (rev 28239)
@@ -140,7 +140,7 @@
        /**
         * Create a column of the specified name and the specified type. The 
column
         * type is limited to Integer, Long, Double, String, and Boolean. The
-        * default value for the column will be null. If the column already 
existed, IllegalArgumentException will be thrown.
+        * default value for the column will be null. If the column already 
exists, IllegalArgumentException will be thrown.
         * @param <T> The generic type of the column.
         * @param columnName The name identifying the attribute.
         * @param type The type of the column.
@@ -150,7 +150,8 @@
 
        /**
         * Create a column of the specified name and the specified type. The 
column
-        * type is limited to Integer, Long, Double, String, and Boolean. If 
the column already existed, IllegalArgumentException will be thrown.
+        * type is limited to Integer, Long, Double, String, and Boolean. If 
the column already exists, IllegalArgumentException will be thrown.
+        * The check for matching column names is case insensitive. 
         * @param <T> The generic type of the column.
         * @param columnName The name identifying the attribute.
         * @param type The type of the column.
@@ -163,7 +164,8 @@
        /**
         * Create a column of Lists with the specified name and the specified 
element type.
         * The column type is limited to Integer, Long, Double, String, and 
Boolean. The
-        * default value for the column will be null. If the column already 
existed, IllegalArgumentException will be thrown.
+        * default value for the column will be null. If the column already 
exists, IllegalArgumentException will be thrown.
+        * The check for matching column names is case insensitive. 
         * @param <T> The generic type of the elements of the list.
         * @param columnName The name identifying the attribute.
         * @param listElementType The type of the elements of the list.
@@ -173,7 +175,8 @@
 
        /**
         * Create a column of Lists with the specified name and the specified 
element type.
-        * The column type is limited to Integer, Long, Double, String, and 
Boolean. If the column already existed, IllegalArgumentException will be thrown.
+        * The column type is limited to Integer, Long, Double, String, and 
Boolean. If the column already exists, IllegalArgumentException will be thrown.
+        * The check for matching column names is case insensitive. 
         * @param <T> The generic type of the elements of the list.
         * @param columnName The name identifying the attribute.
         * @param listElementType The type of the elements of the list.
@@ -187,6 +190,7 @@
         * Returns the row specified by the primary key object and if a row
         * for the specified key does not yet exist in the table, a new row
         * will be created and the new row will be returned.
+        * The check for matching column names is case insensitive. 
         * @param primaryKey The primary key index of the row to return.
         * @return The {@link CyRow} identified by the specified key or a new
         * row identified by the key if one did not already exist.

Added: 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyColumnTest.java
===================================================================
--- 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyColumnTest.java
                               (rev 0)
+++ 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyColumnTest.java
       2012-02-11 00:18:15 UTC (rev 28239)
@@ -0,0 +1,91 @@
+package org.cytoscape.model;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.cytoscape.event.DummyCyEventHelper;
+import org.cytoscape.model.CyTable.Mutability;
+import org.cytoscape.model.events.ColumnCreatedEvent;
+import org.cytoscape.model.events.RowSetRecord;
+import org.junit.Test;
+
+
+public abstract class AbstractCyColumnTest {
+       protected CyTable table;
+       
+       @Test (expected=NullPointerException.class)
+       public void testSetNameNull(){
+               table.createColumn("test", String.class, false);
+               table.getColumn("test").setName(null);
+               
+       }
+       
+
+       @Test (expected=IllegalArgumentException.class)
+       public void testSetNameCaseMatchAll(){
+               
+               table.createColumn("test", String.class, false);
+               table.getColumn("test").setName("TEST1");
+               
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testSetNameCaseMatchAll2(){
+               
+               table.createColumn("TEST", String.class, false);
+               table.getColumn("TEST").setName("test1");
+               
+               
+       }
+       
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testSetNameCaseMatchFirst(){
+               
+               table.createColumn("test", String.class, false);
+               table.getColumn("test").setName("Test1");
+               
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testSetNameCaseMatchLast(){
+               
+               table.createColumn("test", String.class, false);
+               table.getColumn("test").setName("tesT1");
+               
+               
+       }
+
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testSetNameCaseMatchMiddle(){
+               
+               table.createColumn("test", String.class, false);
+               table.getColumn("test").setName("tEst1");
+               
+       }
+       
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testSetNameCaseMatchMultiple(){
+               
+               table.createColumn("test", String.class, false);
+               table.getColumn("test").setName("tESt1");
+               
+       }
+       
+}
\ No newline at end of file

Modified: 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
--- 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
        2012-02-10 23:59:39 UTC (rev 28238)
+++ 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
        2012-02-11 00:18:15 UTC (rev 28239)
@@ -980,4 +980,78 @@
                        assertNull(npkcol);
                }
        }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testColumnNameMatchFirst(){
+               
+               table.createColumn("test", String.class, false);
+               table.createColumn("Test", Integer.class, false);
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testColumnNameMatchFirst2(){
+               
+               table.createColumn("Test", String.class, false);
+               table.createColumn("test", Integer.class, false);
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testColumnNameMatchMiddle(){
+               
+               table.createColumn("test", String.class, false);
+               table.createColumn("teSt", Integer.class, false);
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testColumnNameMatchEnd(){
+               
+               table.createColumn("test", String.class, false);
+               table.createColumn("tesT", Integer.class, false);
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testColumnNameMatchAllCases(){
+               
+               table.createColumn("test", String.class, false);
+               table.createColumn("TEST", Integer.class, false);
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testColumnNameMatchSomeCases(){
+               
+               table.createColumn("test", String.class, false);
+               table.createColumn("tESt", Integer.class, false);
+               
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testCreatColumnDefaultCaseMatch(){
+               
+               table.createColumn("test", String.class, false);
+               table.createColumn("Test", String.class, false, "");
+       }
+       
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testCreatListColumnsCaseMatch(){
+               
+               table.createColumn("test", String.class, false);
+               table.createListColumn("Test", String.class, false);
+       }
+       
+       @Test (expected=IllegalArgumentException.class)
+       public void testCreatListColumnsCaseMatch2(){
+               
+               table.createColumn("test", String.class, false);
+               table.createListColumn("Test", String.class, false, null );
+       }
+       
+       
+       
 }
+

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
       2012-02-10 23:59:39 UTC (rev 28238)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
       2012-02-11 00:18:15 UTC (rev 28239)
@@ -81,9 +81,12 @@
                if (isImmutable)
                        throw new IllegalArgumentException("can't rename an 
immutable column!");
 
+                       
                final String oldName = columnName;
+               table.updateColumnName(oldName, newName);
                columnName = newName;
-               table.updateColumnName(oldName, newName);
+               
+
        }
 
        /** @return the data type of the column. */

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2012-02-10 23:59:39 UTC (rev 28238)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2012-02-11 00:18:15 UTC (rev 28239)
@@ -197,9 +197,16 @@
        }
 
        void updateColumnName(final String oldColumnName, final String 
newColumnName) {
-               if (oldColumnName.equals(newColumnName))
+               
+               if (oldColumnName.equalsIgnoreCase(newColumnName))
                        return;
 
+               for(String curColumnName : types.keySet())
+                       if (curColumnName.equalsIgnoreCase(newColumnName))
+                               throw new IllegalArgumentException("attribute 
already exists for name: '"
+                                          + curColumnName + "' with type: "
+                                          + 
types.get(curColumnName).getType());
+               
                synchronized(this) {
                        if (currentlyActiveAttributes.contains(oldColumnName)) {
                                currentlyActiveAttributes.remove(oldColumnName);
@@ -350,15 +357,16 @@
                synchronized(this) {
                        if (columnName == null)
                                throw new NullPointerException("attribute name 
is null");
-
+                       
+                       for(String curColumnName : types.keySet())
+                               if (curColumnName.equalsIgnoreCase(columnName))
+                                       throw new 
IllegalArgumentException("attribute already exists for name: '"
+                                                  + curColumnName + "' with 
type: "
+                                                  + 
types.get(curColumnName).getType());
+                       
                        if (type == null)
                                throw new NullPointerException("type is null");
 
-                       if (types.get(columnName) != null)
-                               throw new IllegalArgumentException("attribute 
already exists for name: '"
-                                                                  + columnName 
+ "' with type: "
-                                                                  + 
types.get(columnName).getType());
-
                        if (type == List.class)
                                throw new IllegalArgumentException(
                                                "use createListColumn() to 
create List columns instead of createColumn for attribute '"
@@ -375,10 +383,11 @@
                                                                   
defaultValue));
                        attributes.put(columnName, new HashMap<Object, 
Object>(defaultInitSize));
                        reverse.put(columnName, HashMultimap.create());
+               
                }
-
                eventHelper.fireEvent(new ColumnCreatedEvent(this, columnName));
        }
+       
 
        @Override
        public <T> void createListColumn(final String columnName, final 
Class<T> listElementType,
@@ -396,6 +405,12 @@
                        if (columnName == null)
                                throw new NullPointerException("attribute name 
is null");
 
+                       for(String curColumnName : types.keySet())
+                               if (curColumnName.equalsIgnoreCase(columnName))
+                                       throw new 
IllegalArgumentException("attribute already exists for name: '"
+                                                  + curColumnName + "' with 
type: "
+                                                  + 
types.get(curColumnName).getType());
+                       
                        if (listElementType == null)
                                throw new NullPointerException("listElementType 
is null");
 

Added: 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyColumnTest.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyColumnTest.java
                                (rev 0)
+++ 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyColumnTest.java
        2012-02-11 00:18:15 UTC (rev 28239)
@@ -0,0 +1,26 @@
+package org.cytoscape.model;
+
+import org.cytoscape.equations.Interpreter;
+import org.cytoscape.equations.internal.interpreter.InterpreterImpl;
+import org.cytoscape.event.DummyCyEventHelper;
+import org.cytoscape.model.CyTable.SavePolicy;
+import org.cytoscape.model.internal.CyTableImpl;
+import org.junit.Before;
+
+public class CyColumnTest extends AbstractCyColumnTest{
+       protected DummyCyEventHelper eventHelper; 
+       protected final Interpreter interpreter;
+       
+       public CyColumnTest(){
+               eventHelper = new DummyCyEventHelper();
+               interpreter = new InterpreterImpl();
+               
+       }
+       @Before
+       public void setUp (){
+               this.table = new CyTableImpl("homer", CyTableEntry.SUID, 
Long.class, false, true, SavePolicy.SESSION_FILE,
+                               eventHelper, interpreter, 1000);
+               table.createColumn("test1", String.class, false);
+       }
+       
+}
\ No newline at end of file

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