use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method countMatchingRows.
@Override
public int countMatchingRows(final String columnName, final Object value) {
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null)
return virtColumn.countMatchingRows(value);
final ColumnData keyToValueMap = attributes.get(normalizedColName);
return keyToValueMap.countMatchingRows(value);
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method swap.
@Override
public void swap(final CyTable otherTable) {
synchronized (lock) {
final CyTableImpl other = (CyTableImpl) otherTable;
final Set<String> tempCurrentlyActiveAttributes = currentlyActiveAttributes;
currentlyActiveAttributes = other.currentlyActiveAttributes;
other.currentlyActiveAttributes = tempCurrentlyActiveAttributes;
final Map<String, ColumnData> tempAttributes = attributes;
attributes = other.attributes;
other.attributes = tempAttributes;
final Map<Object, CyRow> tempRows = rows;
rows = other.rows;
other.rows = tempRows;
final Map<String, CyColumn> tempTypes = types;
types = other.types;
other.types = tempTypes;
final ArrayList<CyColumn> tempListCol = colList;
colList = other.colList;
other.colList = tempListCol;
final ArrayList<CyRow> tempListRow = rowList;
rowList = other.rowList;
other.rowList = tempListRow;
final Map<String, String> tempNormalizedColNames = normalizedColumnNames;
normalizedColumnNames = other.normalizedColumnNames;
other.normalizedColumnNames = tempNormalizedColNames;
final String tempTitle = title;
title = other.title;
other.title = tempTitle;
final boolean tempPub = pub;
pub = other.pub;
other.pub = tempPub;
final boolean tempIsImmutable = isImmutable;
isImmutable = other.isImmutable;
other.isImmutable = tempIsImmutable;
final String tempPrimaryKey = primaryKey;
primaryKey = other.primaryKey;
other.primaryKey = tempPrimaryKey;
final String tempLastInternalError = lastInternalError;
lastInternalError = other.lastInternalError;
other.lastInternalError = tempLastInternalError;
final Map<String, VirtualColumn> tempVirtualColumnMap = virtualColumnMap;
virtualColumnMap = other.virtualColumnMap;
other.virtualColumnMap = tempVirtualColumnMap;
final Map<String, Set<CyColumn>> tempDependents = dependents;
dependents = other.dependents;
other.dependents = tempDependents;
final SavePolicy tempSavePolicy = savePolicy;
savePolicy = other.savePolicy;
other.savePolicy = tempSavePolicy;
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method getValueOrEquation.
private final Object getValueOrEquation(final Object key, final String columnName, final VirtualColumn virtColumn) {
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
if (primaryKey.equalsIgnoreCase(normalizedColName))
return key;
if (virtColumn != null)
return virtColumn.getRawValue(key);
final ColumnData keyToValueMap = attributes.get(normalizedColName);
if (keyToValueMap == null)
return null;
return keyToValueMap.get(key);
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method setX.
private final void setX(final Object key, final String columnName, final Object value) {
if (columnName == null)
throw new NullPointerException("columnName must not be null.");
if (value == null)
throw new NullPointerException("value must not be null.");
final Object newValue;
final Object newRawValue;
final VirtualColumn virtColumn;
synchronized (lock) {
final String normalizedColName = normalizeColumnName(columnName);
if (types.get(normalizedColName) == null)
throw new IllegalArgumentException("column: '" + columnName + "' does not yet exist.");
final Class<?> columnType = types.get(normalizedColName).getType();
if (columnType == List.class) {
setListX(key, columnName, value);
return;
}
if (!(value instanceof Equation))
checkType(value);
virtColumn = virtualColumnMap.get(normalizedColName);
if (virtColumn != null) {
virtColumn.setValue(key, value);
newValue = virtColumn.getValue(key);
newRawValue = virtColumn.getRawValue(key);
} else {
ColumnData keyToValueMap = attributes.get(normalizedColName);
if (!columnType.isAssignableFrom(value.getClass()) && !EqnSupport.scalarEquationIsCompatible(value, columnType))
throw new IllegalArgumentException("value of \"" + columnName + "\" is not of type " + columnType);
if (value instanceof Equation) {
newRawValue = value;
final Equation equation = (Equation) value;
// TODO this is an implicit addRow - not sure if we want to refactor this or not
keyToValueMap.put(key, equation);
final StringBuilder errorMsg = new StringBuilder();
newValue = EqnSupport.evalEquation(equation, key, interpreter, currentlyActiveAttributes, columnName, errorMsg, this);
lastInternalError = errorMsg.toString();
if (newValue == null)
logger.warn("attempted premature evaluation evaluation for " + equation);
} else {
// TODO this is an implicit addRow - not sure if we want to refactor this or not
newRawValue = newValue = columnType.cast(value);
keyToValueMap.put(key, newValue);
}
}
}
if (fireEvents && virtColumn == null) {
// Fire an event for each table in the virtual column chain
fireVirtualColumnRowSetEvent(this, key, columnName, newValue, newRawValue, Collections.newSetFromMap(new IdentityHashMap<VirtualColumnInfo, Boolean>()));
}
}
use of org.cytoscape.model.internal.column.ColumnData in project cytoscape-impl by cytoscape.
the class CyTableImpl method deleteRows.
@Override
public boolean deleteRows(final Collection<?> primaryKeys) {
boolean changed = false;
synchronized (lock) {
// collect the attribute maps for the columns, faster to normalize column names outside the main loop
Collection<CyColumn> columns = getColumns();
List<ColumnData> attributeMaps = new ArrayList<>(columns.size());
for (CyColumn col : columns) {
final String normalizedColName = normalizeColumnName(col.getName());
final ColumnData keyToValueMap = attributes.get(normalizedColName);
if (keyToValueMap != null) {
attributeMaps.add(keyToValueMap);
}
}
// batch remove from rowList for performance
Set<CyRow> rowsToRemoveFromList = new HashSet<>();
// main loop
for (Object key : primaryKeys) {
checkKey(key);
CyRow row = rows.remove(key);
if (row != null) {
rowsToRemoveFromList.add(row);
for (ColumnData keyToValueMap : attributeMaps) {
keyToValueMap.remove(key);
}
changed = true;
}
}
rowList.removeAll(rowsToRemoveFromList);
}
if (changed)
eventHelper.fireEvent(new RowsDeletedEvent(this, (Collection<Object>) primaryKeys));
return changed;
}
Aggregations