Author: ruschein
Date: 2011-07-06 08:49:44 -0700 (Wed, 06 Jul 2011)
New Revision: 26059
Modified:
core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
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
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/FormulaBuilderDialog.java
core3/table-import-impl/trunk/src/main/java/org/cytoscape/tableimport/internal/reader/ontology/GeneAssociationReader.java
Log:
fixes #72 by speeding up CyTable.getMatchingRows()
Modified: core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
===================================================================
--- core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
2011-07-06 12:54:18 UTC (rev 26058)
+++ core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -30,7 +30,6 @@
import java.util.Collection;
import java.util.List;
-import java.util.Set;
/**
@@ -172,7 +171,7 @@
* @param value the value for which we want the rows that
contain it
* @return the rows, if any that contain the value "value" for the
column "columnName"
*/
- Set<CyRow> getMatchingRows(String columnName, Object value);
+ Collection<CyRow> getMatchingRows(String columnName, Object value);
/** Returns the number of rows in this table.
* @return The number if rows in the table.
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-07-06 12:54:18 UTC (rev 26058)
+++
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -400,7 +400,7 @@
row1.set("someLongs", 15L);
final CyRow row2 = table.getRow(2L);
row2.set("someLongs", -27L);
- Set<CyRow> matchingRows = table.getMatchingRows("someLongs",
15L);
+ Collection<CyRow> matchingRows =
table.getMatchingRows("someLongs", 15L);
assertTrue(matchingRows.size() == 1);
matchingRows = table.getMatchingRows("someLongs", -15L);
assertTrue(matchingRows.isEmpty());
@@ -630,7 +630,7 @@
table.addVirtualColumn("s1", "s", table2, "x2", "x", true);
assertFalse(row1.isSet("s1"));
row2.set("s", "abc");
- Set<CyRow> matchingRows = table.getMatchingRows("s1", "abc");
+ Collection<CyRow> matchingRows = table.getMatchingRows("s1",
"abc");
assertEquals(matchingRows.size(), 1);
CyRow matchingRow = matchingRows.iterator().next();
assertEquals(matchingRow.get("s1", String.class), "abc");
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-07-06 12:54:18 UTC (rev 26058)
+++
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -431,13 +431,13 @@
}
@Override
- synchronized public Set<CyRow> getMatchingRows(final String columnName,
final Object value) {
+ synchronized public Collection<CyRow> getMatchingRows(final String
columnName, final Object value) {
final VirtualColumn virtColumn =
virtualColumnMap.get(columnName);
if (virtColumn != null)
return virtColumn.getMatchingRows(value);
- final Set<CyRow> matchingRows = new HashSet<CyRow>();
if (columnName.equals(primaryKey)) {
+ final ArrayList<CyRow> matchingRows = new
ArrayList<CyRow>(1);
final CyRow matchingRow = rows.get(value);
if (matchingRow != null)
matchingRows.add(matchingRow);
@@ -448,8 +448,9 @@
final Set<Object> keys = valueToKeysMap.get(value);
if (keys == null)
- return new HashSet<CyRow>();
+ return new ArrayList<CyRow>();
+ final ArrayList<CyRow> matchingRows = new
ArrayList<CyRow>(rows.size());
for (final Object key : keys)
matchingRows.add(rows.get(key));
Modified:
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
===================================================================
---
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
2011-07-06 12:54:18 UTC (rev 26058)
+++
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -29,6 +29,7 @@
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -100,7 +101,7 @@
targetTable.getValue(targetKey,
targetJoinColumn.getName());
if (joinKey == null)
return null;
- final Set<CyRow> sourceRows =
+ final Collection<CyRow> sourceRows =
sourceTable.getMatchingRows(sourceJoinColumn.getName(),
joinKey);
if (sourceRows.size() != 1)
@@ -109,15 +110,15 @@
return sourceRows.iterator().next();
}
- Set<CyRow> getMatchingRows(final Object value) {
- final Set<CyRow> sourceRows =
+ Collection<CyRow> getMatchingRows(final Object value) {
+ final Collection<CyRow> sourceRows =
sourceTable.getMatchingRows(sourceColumn.getName(),
value);
final Set<CyRow> targetRows = new HashSet<CyRow>();
for (final CyRow sourceRow : sourceRows) {
final Object targetValue =
sourceRow.get(sourceJoinColumn.getName(),
sourceJoinColumn.getType());
if (targetValue != null) {
- final Set<CyRow> rows =
+ final Collection<CyRow> rows =
targetTable.getMatchingRows(targetJoinColumn.getName(),
targetValue);
targetRows.addAll(rows);
@@ -132,7 +133,7 @@
targetJoinColumn.getType());
List results = new ArrayList();
for (final Object targetJoinColumnValue :
targetJoinColumnValues) {
- final Set<CyRow> sourceRows =
+ final Collection<CyRow> sourceRows =
sourceTable.getMatchingRows(sourceJoinColumn.getName(),
targetJoinColumnValue);
if (sourceRows.size() == 1) {
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
===================================================================
---
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
2011-07-06 12:54:18 UTC (rev 26058)
+++
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/BrowserTableModel.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -341,7 +341,7 @@
if (!selected && rowIndex == -1)
return;
*/
- selectedRows = null;
+// selectedRows = null;
fireTableDataChanged();
} else {
final TableModelEvent event = new TableModelEvent(this,
rowIndex, rowIndex, columnIndex);
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
===================================================================
---
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
2011-07-06 12:54:18 UTC (rev 26058)
+++
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -241,8 +241,8 @@
* @param value the value for which we want the rows that
contain it
* @return the rows, if any that contain the value "value" for the
column "columnName"
*/
- public Set<CyRow> getMatchingRows(final String columnName, final Object
value) {
- final Set<CyRow> matchingRows = new HashSet<CyRow>();
+ public Collection<CyRow> getMatchingRows(final String columnName, final
Object value) {
+ final ArrayList<CyRow> matchingRows = new ArrayList<CyRow>();
final String primaryKey =
underlyingTable.getPrimaryKey().getName();
final Class<?> primaryKeyType =
underlyingTable.getPrimaryKey().getType();
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/FormulaBuilderDialog.java
===================================================================
---
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/FormulaBuilderDialog.java
2011-07-06 12:54:18 UTC (rev 26058)
+++
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/FormulaBuilderDialog.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -492,7 +492,7 @@
tableModel.setValueAt(formula, cellRow, cellColum);
break;
case CURRENT_SELECTION:
- final Set<CyRow> selectedRows =
+ final Collection<CyRow> selectedRows =
tableModel.getAttributes().getMatchingRows(CyNetwork.SELECTED, true);
for (final CyRow selectedRow : selectedRows) {
if (!setAttribute(selectedRow, attribName,
equation, errorMessage))
Modified:
core3/table-import-impl/trunk/src/main/java/org/cytoscape/tableimport/internal/reader/ontology/GeneAssociationReader.java
===================================================================
---
core3/table-import-impl/trunk/src/main/java/org/cytoscape/tableimport/internal/reader/ontology/GeneAssociationReader.java
2011-07-06 12:54:18 UTC (rev 26058)
+++
core3/table-import-impl/trunk/src/main/java/org/cytoscape/tableimport/internal/reader/ontology/GeneAssociationReader.java
2011-07-06 15:49:44 UTC (rev 26059)
@@ -1,5 +1,6 @@
package org.cytoscape.tableimport.internal.reader.ontology;
+
import static
org.cytoscape.tableimport.internal.reader.TextFileDelimiters.PIPE;
import static org.cytoscape.tableimport.internal.reader.TextFileDelimiters.TAB;
@@ -9,6 +10,7 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,14 +34,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
public class GeneAssociationReader extends AbstractTask implements
CyTableReader {
-
private static final Logger logger =
LoggerFactory.getLogger(GeneAssociationReader.class);
private static final String COMPATIBLE_VERSION = "gaf-version: 2.0";
-
private static final String TAXON_RESOURCE_FILE = "tax_report.txt";
-
private static final String LIST_DELIMITER = "\\|";
// The following columns should be handled as List in GA v2 spec.
@@ -499,8 +499,8 @@
}
private String convertToName(final String id) {
- final Set<CyRow> rows =
ontologyDAG.getDefaultNodeTable().getMatchingRows(CyTableEntry.NAME, id);
- if(rows != null) {
+ final Collection<CyRow> rows =
ontologyDAG.getDefaultNodeTable().getMatchingRows(CyTableEntry.NAME, id);
+ if (rows != null) {
final CyRow row = rows.iterator().next();
final String termName = row.get(OBOReader.TERM_NAME,
String.class);
if(termName != 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.