Author: ruschein
Date: 2011-01-21 11:00:07 -0800 (Fri, 21 Jan 2011)
New Revision: 23543
Modified:
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
Log:
Improved virtual table column support.
Modified:
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
---
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2011-01-21 18:55:30 UTC (rev 23542)
+++
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2011-01-21 19:00:07 UTC (rev 23543)
@@ -661,6 +661,23 @@
@Test
public void testVirtualColumnListElementType() {
+ table.createColumn("x", Integer.class);
+ CyRow row1 = table.getRow(1L);
+ row1.set("x", 33);
+ table2.createColumn("x2", Integer.class);
+ CyRow row2 = table2.getRow(1L);
+ row2.set("x2", 33);
+ table2.createColumn("s", String.class);
+ table.addVirtualColumn("s1", "s", table2, "x2", "x");
+ assertFalse(row1.isSet("s1", String.class));
+ row2.set("s", "abc");
+ List<String> columnValues = table.getColumnValues("s1",
String.class);
+ assertEquals(1, columnValues.size());
+ assertEquals("abc", columnValues.get(0));
+ }
+
+ @Test
+ public void testVirtualColumnGetColumnValues() {
table.createColumn("x", Long.class);
table2.createColumn("x2", Long.class);
table2.createListColumn("b", Boolean.class);
Modified:
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
---
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-01-21 18:55:30 UTC (rev 23542)
+++
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-01-21 19:00:07 UTC (rev 23543)
@@ -63,6 +63,7 @@
private final String sourceJoinColumn;
private final Class<?> sourceJoinColumnType;
private final String targetJoinColumn;
+ private final Class<?> targetJoinColumnType;
VirtualColumn(final CyTable sourceTable, final String
sourceColumn,
final CyTableImpl targetTable, final String
sourceJoinColumn,
@@ -77,6 +78,7 @@
this.sourceJoinColumn = sourceJoinColumn;
this.sourceJoinColumnType =
sourceTable.getType(sourceJoinColumn);
this.targetJoinColumn = targetJoinColumn;
+ this.targetJoinColumnType =
targetTable.getType(targetJoinColumn);
}
Object getRawValue(final Object targetKey) {
@@ -137,6 +139,26 @@
}
return targetRows;
}
+
+ List getColumnValues() {
+ final List targetJoinColumnValues =
+ targetTable.getColumnValues(targetJoinColumn,
targetJoinColumnType);
+ List results = new ArrayList();
+ for (final Object targetJoinColumnValue :
targetJoinColumnValues) {
+ final Set<CyRow> sourceRows =
+
sourceTable.getMatchingRows(sourceJoinColumn,
+
targetJoinColumnValue);
+ if (sourceRows.size() == 1) {
+ final CyRow sourceRow =
sourceRows.iterator().next();
+ final Object value =
+ sourceRow.get(sourceColumn,
sourceColumnType);
+ if (value != null)
+ results.add(value);
+ }
+ }
+
+ return results;
+ }
}
private static final Logger logger =
LoggerFactory.getLogger(CyTableImpl.class);
@@ -376,9 +398,14 @@
return primaryKeys;
}
+ final VirtualColumn virtColumn =
virtualColumnMap.get(columnName);
+ if (virtColumn != null)
+ return (List<T>)virtColumn.getColumnValues();
+
Map<Object, Object> vals = attributes.get(columnName);
if (vals == null)
- throw new IllegalArgumentException("attribute does not
exist");
+ throw new IllegalArgumentException("attribute \"" +
columnName
+ + "\" does not
exist!");
List<T> l = new ArrayList<T>(vals.size());
for (final Object suid : vals.keySet()) {
--
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.