use of org.cytoscape.filter.predicates.Predicate in project cytoscape-impl by cytoscape.
the class ColumnFilter method accepts.
@SuppressWarnings("unchecked")
@Override
public boolean accepts(CyNetwork context, CyIdentifiable element) {
if (columnName == null || rawCriterion == null || predicate == null) {
// This filter is incomplete.
return false;
}
Class<?> tableType = getTableType();
if (tableType != null && !tableType.isAssignableFrom(element.getClass())) {
return false;
}
CyRow row = context.getRow(element);
CyTable table = row.getTable();
CyColumn column = table.getColumn(columnName);
if (column == null) {
return false;
}
Class<?> columnType = column.getType();
if (columnType.equals(List.class)) {
Class<?> listElementType = column.getListElementType();
if (String.class.equals(listElementType)) {
List<String> list = row.getList(columnName, String.class);
return listMatch(anyMatch, list, item -> stringDelegate.accepts(stringCriterion, lowerCaseCriterion, item, caseSensitive));
} else if (Number.class.isAssignableFrom(listElementType)) {
List<Number> list = (List<Number>) row.getList(columnName, listElementType);
return listMatch(anyMatch, list, number -> numericDelegate.accepts(lowerBound, upperBound, number));
} else if (Boolean.class.equals(listElementType)) {
List<Boolean> list = (List<Boolean>) row.getList(columnName, listElementType);
if (list != null) {
for (Boolean value : list) {
if (value != null && booleanCriterion.equals(value)) {
return true;
}
}
}
}
} else if (columnType.equals(String.class)) {
String value = row.get(columnName, String.class);
return stringDelegate.accepts(stringCriterion, lowerCaseCriterion, value, caseSensitive);
} else if (Number.class.isAssignableFrom(columnType)) {
Number value = row.get(columnName, (Class<Number>) columnType);
return numericDelegate.accepts(lowerBound, upperBound, value);
} else if (Boolean.class.equals(columnType)) {
Boolean value = row.get(columnName, Boolean.class);
return booleanCriterion.equals(value);
}
return false;
}
Aggregations