use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class CompositeFilterTest method testCompositeFilterAlwaysFalse.
@Test
public void testCompositeFilterAlwaysFalse() {
CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
ColumnFilter filterForA = new ColumnFilter();
ColumnFilter filterForB = new ColumnFilter();
ColumnFilter filterForC = new ColumnFilter();
composite.append(filterForA);
composite.append(filterForB);
composite.append(filterForC);
assertTrue(filterForA.isAlwaysFalse());
assertTrue(filterForB.isAlwaysFalse());
assertTrue(filterForC.isAlwaysFalse());
composite.setType(Type.ALL);
assertTrue(composite.isAlwaysFalse());
composite.setType(Type.ANY);
assertTrue(composite.isAlwaysFalse());
filterForA.setColumnName("s");
filterForA.setPredicateAndCriterion(Predicate.CONTAINS, "a");
assertFalse(filterForA.isAlwaysFalse());
composite.setType(Type.ALL);
assertTrue(composite.isAlwaysFalse());
composite.setType(Type.ANY);
assertFalse(composite.isAlwaysFalse());
filterForB.setColumnName("s");
filterForB.setPredicateAndCriterion(Predicate.CONTAINS, "a");
filterForC.setColumnName("s");
filterForC.setPredicateAndCriterion(Predicate.CONTAINS, "a");
composite.setType(Type.ALL);
assertFalse(composite.isAlwaysFalse());
composite.setType(Type.ANY);
assertFalse(composite.isAlwaysFalse());
}
use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.
the class FilterIOTest method testLoadOldTopologyFilter.
/**
* The topology filter was made a composite filter in 3.3. Older versions of cytoscape
* will export a topology filter without the "transformers" field that is part of
* composite filters. The filter json parser was enhanced to support this.
*/
@SuppressWarnings("rawtypes")
@Test
public void testLoadOldTopologyFilter() throws IOException {
TransformerManagerImpl transformerManager = new TransformerManagerImpl();
Map<String, String> properties = Collections.emptyMap();
transformerManager.registerFilterFactory(new CompositeFilterFactory<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class), properties);
transformerManager.registerFilterFactory(new TopologyFilterFactory(), properties);
transformerManager.registerFilterFactory(new ColumnFilterFactory(), properties);
String path = "./src/test/resources/testData/filter/topology-filter-3.2.json";
byte[] encoded = Files.readAllBytes(Paths.get(path));
// String contents = new String(encoded);
// System.out.println(contents);
CyTransformerReaderImpl reader = new CyTransformerReaderImpl();
reader.registerTransformerManager(transformerManager, null);
ByteArrayInputStream inputStream = new ByteArrayInputStream(encoded);
NamedTransformer<?, ?>[] transformers = reader.read(inputStream);
Assert.assertNotNull(transformers);
Assert.assertEquals(1, transformers.length);
NamedTransformer<?, ?> namedTransformer = transformers[0];
Assert.assertNotNull(namedTransformer);
Assert.assertEquals("Default filter", namedTransformer.getName());
List children = namedTransformer.getTransformers();
Assert.assertEquals(1, children.size());
Transformer child = (Transformer) children.get(0);
Assert.assertNotNull(child);
Assert.assertTrue(child instanceof CompositeFilter);
CompositeFilter composite = (CompositeFilter) child;
Assert.assertEquals(2, composite.getLength());
Assert.assertTrue(composite.get(0) instanceof TopologyFilter);
Assert.assertTrue(composite.get(1) instanceof ColumnFilter);
TopologyFilter topology = (TopologyFilter) composite.get(0);
Assert.assertEquals(0, topology.getLength());
Assert.assertEquals(Integer.valueOf(4), topology.getDistance());
Assert.assertEquals(Integer.valueOf(5), topology.getThreshold());
ColumnFilter column = (ColumnFilter) composite.get(1);
Assert.assertEquals("name", column.getColumnName());
}
Aggregations