Search in sources :

Example 6 with Equation

use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.

the class ClearErrorsEdit method run.

@Override
public void run(final TaskMonitor tm) throws Exception {
    final CyTable table = column.getTable();
    final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
    final List<ErrorEquation> errorEquations = new ArrayList<>();
    for (CyRow row : table.getAllRows()) {
        if (cancelled)
            return;
        final Object raw = row.getRaw(column.getName());
        if (raw instanceof Equation) {
            final Equation eq = (Equation) raw;
            final boolean success = compiler.compile(eq.toString(), TableBrowserUtil.getAttNameToTypeMap(table, null));
            // TODO: success is incorrectly set to yes on broken equations [=ABS(String)]
            if (!success || row.get(column.getName(), column.getType()) == null)
                errorEquations.add(new ErrorEquation(row, column.getName(), eq));
        }
    }
    for (ErrorEquation err : errorEquations) {
        if (cancelled) {
            restoreDeletedEquations();
            return;
        }
        deletedEquations.add(err);
        err.clear();
    }
    if (!deletedEquations.isEmpty()) {
        final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
        undoSupport.postEdit(new ClearErrorsEdit(column.getName(), deletedEquations));
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) Equation(org.cytoscape.equations.Equation) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyRow(org.cytoscape.model.CyRow) UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 7 with Equation

use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.

the class ClearAllErrorsTaskFactory method isReady.

@Override
public boolean isReady(final CyColumn column) {
    final CyTable table = column.getTable();
    final EquationCompiler compiler = serviceRegistrar.getService(EquationCompiler.class);
    for (CyRow row : table.getAllRows()) {
        final Object raw = row.getRaw(column.getName());
        if (raw instanceof Equation) {
            final Equation eq = (Equation) raw;
            final boolean success = compiler.compile(eq.toString(), TableBrowserUtil.getAttNameToTypeMap(table, null));
            // TODO: success is incorrectly set to yes on broken equations [=ABS(String)]
            if (!success || row.get(column.getName(), column.getType()) == null)
                return true;
        }
    }
    return false;
}
Also used : CyTable(org.cytoscape.model.CyTable) Equation(org.cytoscape.equations.Equation) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyRow(org.cytoscape.model.CyRow)

Example 8 with Equation

use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.

the class CyTableTest method testGetColumnValuesWithEquations.

@Test
public void testGetColumnValuesWithEquations() {
    table.createColumn("someLongs", Long.class, false);
    final CyRow row1 = table.getRow(1L);
    compiler.compile("=LEN(\"one\")", new HashMap<String, Class<?>>());
    final Equation eqn = compiler.getEquation();
    row1.set("someLongs", eqn);
    final CyRow row2 = table.getRow(2L);
    row2.set("someLongs", -27L);
    final List<Long> values = table.getColumn("someLongs").getValues(Long.class);
    assertTrue(values.size() == 2);
    assertTrue(values.contains(3L));
    assertTrue(values.contains(-27L));
}
Also used : Equation(org.cytoscape.equations.Equation) Test(org.junit.Test)

Example 9 with Equation

use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.

the class CyTableTest method testSetListWithACompatibleEquation.

// @Test : TODO: We removed support for strongly typed lists so this test is
// now broken.
public void testSetListWithACompatibleEquation() {
    table.createListColumn("stringList", String.class, false);
    attrs.set("stringList", new StringList());
    compiler.compile("=SLIST(\"one\",\"two\")", new HashMap<String, Class<?>>());
    final Equation eqn = compiler.getEquation();
    attrs.set("stringList", eqn);
    final StringList expectedList = new StringList("one", "two");
    assertEquals(attrs.getList("stringList", String.class), expectedList);
}
Also used : StringList(org.cytoscape.equations.internal.StringList) Equation(org.cytoscape.equations.Equation)

Example 10 with Equation

use of org.cytoscape.equations.Equation in project cytoscape-impl by cytoscape.

the class CyTableTest method testSetWithANonEvaluableCompatibleEquation.

@Test
public void testSetWithANonEvaluableCompatibleEquation() {
    table.createColumn("strings", String.class, false);
    final Map<String, Class<?>> varnameToTypeMap = new HashMap<String, Class<?>>();
    varnameToTypeMap.put("a", String.class);
    compiler.compile("=$a&\"one\"", varnameToTypeMap);
    final Equation eqn = compiler.getEquation();
    attrs.set("strings", eqn);
    Object last = eventHelper.getLastPayload();
    assertNotNull(last);
    assertTrue(last instanceof RowSetRecord);
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) Test(org.junit.Test)

Aggregations

Equation (org.cytoscape.equations.Equation)29 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 CyRow (org.cytoscape.model.CyRow)8 ArrayList (java.util.ArrayList)6 IdentDescriptor (org.cytoscape.equations.IdentDescriptor)5 Interpreter (org.cytoscape.equations.Interpreter)5 EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)5 EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)5 InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)5 CyColumn (org.cytoscape.model.CyColumn)5 CyTable (org.cytoscape.model.CyTable)5 EquationCompiler (org.cytoscape.equations.EquationCompiler)4 List (java.util.List)3 RowSetRecord (org.cytoscape.model.events.RowSetRecord)3 Map (java.util.Map)2 ValidatedObjectAndEditString (org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)2 ColumnData (org.cytoscape.model.internal.column.ColumnData)2 IOException (java.io.IOException)1 Hashtable (java.util.Hashtable)1