Search in sources :

Example 1 with Predicate

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;
}
Also used : Predicate(org.cytoscape.filter.predicates.Predicate) Transformers(org.cytoscape.filter.transformers.Transformers) StringPredicateDelegate(org.cytoscape.filter.internal.predicates.StringPredicateDelegate) AbstractTransformer(org.cytoscape.filter.model.AbstractTransformer) CyNode(org.cytoscape.model.CyNode) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) ValidatableTransformer(org.cytoscape.filter.model.ValidatableTransformer) CyRow(org.cytoscape.model.CyRow) ValidationWarning(org.cytoscape.filter.model.ValidationWarning) List(java.util.List) NumericPredicateDelegate(org.cytoscape.filter.internal.predicates.NumericPredicateDelegate) ValidationWarning.warn(org.cytoscape.filter.model.ValidationWarning.warn) CyIdentifiable(org.cytoscape.model.CyIdentifiable) PredicateDelegates(org.cytoscape.filter.internal.predicates.PredicateDelegates) Tunable(org.cytoscape.work.Tunable) ListChangeListener(org.cytoscape.work.util.ListChangeListener) CyNetwork(org.cytoscape.model.CyNetwork) CyColumn(org.cytoscape.model.CyColumn) Filter(org.cytoscape.filter.model.Filter) ListSelection(org.cytoscape.work.util.ListSelection) CyEdge(org.cytoscape.model.CyEdge) Collections(java.util.Collections) CyTable(org.cytoscape.model.CyTable) CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) List(java.util.List) CyRow(org.cytoscape.model.CyRow)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 NumericPredicateDelegate (org.cytoscape.filter.internal.predicates.NumericPredicateDelegate)1 PredicateDelegates (org.cytoscape.filter.internal.predicates.PredicateDelegates)1 StringPredicateDelegate (org.cytoscape.filter.internal.predicates.StringPredicateDelegate)1 AbstractTransformer (org.cytoscape.filter.model.AbstractTransformer)1 Filter (org.cytoscape.filter.model.Filter)1 ValidatableTransformer (org.cytoscape.filter.model.ValidatableTransformer)1 ValidationWarning (org.cytoscape.filter.model.ValidationWarning)1 ValidationWarning.warn (org.cytoscape.filter.model.ValidationWarning.warn)1 Predicate (org.cytoscape.filter.predicates.Predicate)1 Transformers (org.cytoscape.filter.transformers.Transformers)1 CyColumn (org.cytoscape.model.CyColumn)1 CyEdge (org.cytoscape.model.CyEdge)1 CyIdentifiable (org.cytoscape.model.CyIdentifiable)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyRow (org.cytoscape.model.CyRow)1 CyTable (org.cytoscape.model.CyTable)1 Tunable (org.cytoscape.work.Tunable)1