Author: jm
Date: 2012-09-18 12:42:17 -0700 (Tue, 18 Sep 2012)
New Revision: 30379
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyRow.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/CyTableImpl.java
Log:
References #1426: Updated Javadoc to explain behaviour of list attributes.
Changed implementation to be more strict about illegal arguments.
Modified: core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyRow.java
===================================================================
--- core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyRow.java
2012-09-18 19:12:21 UTC (rev 30378)
+++ core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyRow.java
2012-09-18 19:42:17 UTC (rev 30379)
@@ -63,33 +63,37 @@
<T> T get(String columnName, Class<?extends T> type, T defaultValue);
/**
- * Returns the value found for this row in the specified column
- * with the specified type.
+ * Returns a list which is a view on the underlying column value for
this row. This means
+ * updates made to the list are reflected in the column, and
vice-versa.
* @param <T> the generic type of the elements of the list we wish to
retrieve.
* @param columnName The name identifying the attribute.
* @param listElementType The type of the elements of the list that we
wish to retrieve.
- * @return The value found for this row in the specified column and
+ * @return Returns a list which is a view on the underlying column
value for this row, or
* null if the column does not exist.
* Please note that this method can only be used to retrieve values
that are Lists!
*/
<T> List<T> getList(String columnName, Class<T> listElementType);
/**
- * Returns the value found for this row in the specified column
- * with the specified type.
+ * Returns a list which is a view on the underlying column value for
this row. This means
+ * updates made to the list are reflected in the column, and
vice-versa.
* @param <T> the generic type of the elements of the list we wish to
retrieve.
* @param columnName The name identifying the attribute.
* @param listElementType The type of the elements of the list that we
wish to retrieve.
* @param defaultValue The List to return if the column has not
previously been set.
- * @return The value found for this row in the specified column, the
default value
+ * @return Returns a list which is a view on the underlying column
value for this row, the default value
* if the row has not yet been set, and null if the column does not
exist.
* Please note that this method can only be used to retrieve values
that are Lists!
*/
<T> List<T> getList(String columnName, Class<T> listElementType,
List<T> defaultValue);
/**
- * Set the specified column for this row to the specified value.
- * To unset a column entry use null for value.
+ * Sets the specified column for this row to the specified value.
+ * To unset a column entry use null for value. When setting a list
value
+ * to this row, the list is copied. Any further updates to the original
+ * list are not reflected in the row. To update the row call
+ * {@link #getList(String, Class) getList()} and update the resulting
list.
+ *
* @param <T> The generic type of the value to assign the specified
column in this row.
* @param columnName The name identifying the attribute.
* @param value The value to assign the specified column in this row
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-09-18 19:12:21 UTC (rev 30378)
+++
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2012-09-18 19:42:17 UTC (rev 30379)
@@ -424,10 +424,10 @@
assertNull(attrs.getList("x", String.class));
}
- @Test
+ @Test(expected=IllegalArgumentException.class)
public void testGetListWithAnInvalidListElementType() {
table.createListColumn("x", Long.class, false);
- assertNull(attrs.getList("x", String.class));
+ attrs.getList("x", String.class);
}
@Test
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-09-18 19:12:21 UTC (rev 30378)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2012-09-18 19:42:17 UTC (rev 30379)
@@ -858,16 +858,14 @@
final Class<?> expectedListElementType =
type.getListElementType();
if (expectedListElementType == null) {
- logger.warn("'" + columnName + "' is not a List.");
- return defaultValue;
+ throw new IllegalArgumentException("'" + columnName +
"' is not a List.");
}
if (expectedListElementType != listElementType) {
- logger.warn("invalid list element type for column '"
+ throw new IllegalArgumentException("invalid list
element type for column '"
+ columnName + ", found: " +
listElementType.getName()
+ ", expected: " +
expectedListElementType.getName()
+ ".");
- return defaultValue;
}
lastInternalError = null;
--
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.