Search in sources :

Example 1 with TopoGraphNode

use of org.cytoscape.model.internal.tsort.TopoGraphNode in project cytoscape-impl by cytoscape.

the class EqnSupport method topoSortAttribReferences.

/**
 *  @return an in-order list of attribute names that will have to be evaluated before "columnName" can be evaluated
 */
private List<String> topoSortAttribReferences(final Object key, final String columnName, final CyTableImpl tableImpl) {
    final Object equationCandidate = tableImpl.getValueOrEquation(key, columnName);
    if (!(equationCandidate instanceof Equation))
        return new ArrayList<String>();
    final Equation equation = (Equation) equationCandidate;
    final Set<String> attribReferences = equation.getVariableReferences();
    if (attribReferences.size() == 0)
        return new ArrayList<String>();
    final Set<String> alreadyProcessed = new TreeSet<String>();
    alreadyProcessed.add(columnName);
    final List<TopoGraphNode> dependencies = new ArrayList<TopoGraphNode>();
    for (final String attribReference : attribReferences) followReferences(key, attribReference, alreadyProcessed, dependencies, tableImpl);
    final List<TopoGraphNode> topoOrder = TopologicalSort.sort(dependencies);
    final List<String> retVal = new ArrayList<String>();
    for (final TopoGraphNode node : topoOrder) {
        final AttribTopoGraphNode attribTopoGraphNode = (AttribTopoGraphNode) node;
        final String nodeName = attribTopoGraphNode.getNodeName();
        if (nodeName.equals(columnName))
            return retVal;
        else
            retVal.add(nodeName);
    }
    // We should never get here because "columnName" should have been found in the for-loop above!
    throw new IllegalStateException("\"" + columnName + "\" was not found in the toplogical order, which should be impossible.");
}
Also used : TopoGraphNode(org.cytoscape.model.internal.tsort.TopoGraphNode) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Equation(org.cytoscape.equations.Equation)

Aggregations

ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Equation (org.cytoscape.equations.Equation)1 TopoGraphNode (org.cytoscape.model.internal.tsort.TopoGraphNode)1