Author: mes
Date: 2012-01-18 17:00:38 -0800 (Wed, 18 Jan 2012)
New Revision: 28047

Modified:
   
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/CyTableImpl.java
Log:
fixes #450 For missing columns, wrong columns, or bad type specification we 
return the default value which will be null if not specified

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-01-19 00:39:40 UTC (rev 28046)
+++ 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
        2012-01-19 01:00:38 UTC (rev 28047)
@@ -434,15 +434,15 @@
                assertTrue(table.getAllRows().size() == 3);
        }
 
-       @Test(expected=IllegalArgumentException.class)
+       @Test
        public void testGetListWithANonExistantColumn() {
-               attrs.getList("x", String.class);
+               assertNull(attrs.getList("x", String.class));
        }
 
-       @Test(expected=IllegalArgumentException.class)
+       @Test
        public void testGetListWithAnInvalidListElementType() {
                table.createListColumn("x", Long.class, false);
-               attrs.getList("x", String.class);
+               assertNull(attrs.getList("x", String.class));
        }
 
        @Test
@@ -901,6 +901,11 @@
        }
 
        @Test
+       public void testGetAttrBeforeListColumnExists() {
+               
assertNull(attrs.getList("nonexistentListColumnX",Integer.class));
+       }
+
+       @Test
        public void testVirtualColumns() {
                table2.createColumn("s", String.class, false);
                table2.createColumn("t", Integer.class, false);

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-01-19 00:39:40 UTC (rev 28046)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2012-01-19 01:00:38 UTC (rev 28047)
@@ -770,17 +770,25 @@
                                                           final Class<? 
extends T> listElementType, final List<T> defaultValue)
        {
                CyColumn type = types.get(columnName);
-               if (type == null)
-                       throw new IllegalArgumentException("'" + columnName + 
"' does not yet exist!");
+               if (type == null) {
+                       logger.warn("'" + columnName + "' does not yet exist!");
+                       return defaultValue;
+               }
+
                final Class<?> expectedListElementType = 
type.getListElementType();
-               if (expectedListElementType == null)
-                       throw new IllegalArgumentException("'" + columnName + 
"' is not a List!");
-               if (expectedListElementType != listElementType)
-                       throw new IllegalArgumentException("invalid list 
element type for column '"
-                                                          + columnName + ", 
found: " + listElementType.getName()
-                                                          + ", expected: " + 
expectedListElementType.getName()
-                                                          + "!");
+               if (expectedListElementType == null) {
+                       logger.warn("'" + columnName + "' is not a List!");
+                       return defaultValue;
+               }
 
+               if (expectedListElementType != listElementType) {
+                       logger.warn("invalid list element type for column '"
+                                    + columnName + ", found: " + 
listElementType.getName()
+                                    + ", expected: " + 
expectedListElementType.getName()
+                                    + "!");
+                       return defaultValue;
+               }
+
                lastInternalError = null;
 
                final VirtualColumn virtColumn = 
virtualColumnMap.get(columnName);

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