Author: ruschein
Date: 2011-06-07 09:09:17 -0700 (Tue, 07 Jun 2011)
New Revision: 25661
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyRowProjection.java
Log:
Table and Row projection classes that allow a view of a rectangular subset.
Modified:
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyRowProjection.java
===================================================================
---
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyRowProjection.java
2011-06-07 14:56:57 UTC (rev 25660)
+++
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/CyRowProjection.java
2011-06-07 16:09:17 UTC (rev 25661)
@@ -33,23 +33,18 @@
import java.util.Map;
import java.util.Set;
-import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
-/**
- * This class represents one row in a CyTableProjection.
- */
-public final class CyRowProjection implements CyRow {
- private final CyTableProjection table;
- private final CyRow row;
+final class CyRowProjection implements CyRow {
+ private final CyTableProjection tableProjection;
+ private final CyRow underlyingRow;
- public CyRowProjection(final CyTableProjection table, final CyRow row) {
- this.table = table;
- this.row = row;
+ CyRowProjection(final CyTableProjection tableProjection, final CyRow
underlyingRow) {
+ this.tableProjection = tableProjection;
+ this.underlyingRow = underlyingRow;
}
-
/**
* Returns the value found for this row in the specified column
* with the specified type.
@@ -59,9 +54,17 @@
* Please not that this method cannot be used to retrieve values that
are Lists!
*/
public <T> T get(final String columnName, final Class<?extends T> type)
{
- return table.getColumn(columnName) == null ? null :
row.get(columnName, type);
+ checkColumnName(columnName);
+ return underlyingRow.get(columnName, type);
}
+ private void checkColumnName(final String columnName) {
+ if (!tableProjection.getColumnNames().contains(columnName))
+ throw new IllegalArgumentException("\"" + columnName
+ + "\" is not a valid
column in the \""
+ +
tableProjection.getTitle() + "\" table!");
+ }
+
/**
* Returns the value found for this row in the specified column
* with the specified type.
@@ -71,7 +74,8 @@
* Please not that this method can only be used to retrieve values that
are Lists!
*/
public <T> List<T> getList(final String columnName, final Class<T>
listElementType) {
- return table.getColumn(columnName) == null ? null :
row.getList(columnName, listElementType);
+ checkColumnName(columnName);
+ return underlyingRow.getList(columnName, listElementType);
}
/**
@@ -84,7 +88,8 @@
* {@link CyTable#createListColumn}!
*/
public <T> void set(final String columnName, final T value) {
- throw new UnsupportedOperationException("set() not supported in
CyRowProjection!");
+ checkColumnName(columnName);
+ underlyingRow.set(columnName, value);
}
/**
@@ -95,7 +100,8 @@
* of the specified type is not null.
*/
public boolean isSet(final String columnName) {
- return table.getColumn(columnName) == null ? false :
row.isSet(columnName);
+ checkColumnName(columnName);
+ return underlyingRow.isSet(columnName);
}
/**
@@ -105,14 +111,14 @@
* contained in this Row.
*/
public Map<String, Object> getAllValues() {
- final Map<String, Object> values = new HashMap<String,
Object>();
- final Set<String> validColumnNames = table.getColumnNames();
- for (final Map.Entry<String, Object> nameAndValue :
row.getAllValues().entrySet()) {
- if (validColumnNames.contains(nameAndValue.getKey()))
- values.put(nameAndValue.getKey(),
nameAndValue.getValue());
+ final Map<String, Object> nameToValueMap = new HashMap<String,
Object>();
+ final Set<String> validNames = tableProjection.getColumnNames();
+ for (final Map.Entry<String, Object> nameAndValue :
underlyingRow.getAllValues().entrySet()) {
+ if (validNames.contains(nameAndValue.getKey()))
+ nameToValueMap.put(nameAndValue.getKey(),
nameAndValue.getValue());
}
- return values;
+ return nameToValueMap;
}
/**
@@ -121,7 +127,8 @@
* @return The row Object that represents the value in a column.
*/
public Object getRaw(final String columnName) {
- return table.getColumn(columnName) == null ? false :
row.getRaw(columnName);
+ checkColumnName(columnName);
+ return underlyingRow.getRaw(columnName);
}
/**
@@ -129,6 +136,6 @@
* @return the {@link CyTable} that this row belongs to.
*/
public CyTable getTable() {
- return table;
+ return tableProjection;
}
-}
+}
\ 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.