Search in sources :

Example 1 with EndpointPair

use of com.google.common.graph.EndpointPair in project page-factory-2 by sbtqa.

the class FragmentReplacer method replace.

/**
 * In the graph, terminal fragments are searched and substituted cyclically.
 * The cycle will be completed when all fragments are substituted and there are no edges left in the graph.
 *
 * @throws IllegalAccessException if it was not possible to replace a step with a fragment
 * @throws FragmentException if fragments replacing is in an infinite loop
 */
public void replace() throws IllegalAccessException, FragmentException, DataException {
    while (!fragmentsGraph.edges().isEmpty()) {
        int fragmentsGraphSize = fragmentsGraph.edges().size();
        for (EndpointPair edge : new ArrayList<>(fragmentsGraph.edges())) {
            ScenarioDefinition fragment = (ScenarioDefinition) edge.nodeV();
            ScenarioDefinition scenario = (ScenarioDefinition) edge.nodeU();
            String data = fragmentsGraph.edgeValue(edge.nodeU(), edge.nodeV()).get();
            if (isTerminal(fragment)) {
                replaceFragmentInScenario(scenario, fragment, data);
                fragmentsGraph.removeEdge(scenario, fragment);
            }
        }
        if (fragmentsGraphSize == fragmentsGraph.edges().size()) {
            throw new FragmentException("Fragments replacing is no longer performed, it will lead to an infinite loop. Interrupting...");
        }
    }
}
Also used : ScenarioDefinition(gherkin.ast.ScenarioDefinition) ArrayList(java.util.ArrayList) EndpointPair(com.google.common.graph.EndpointPair) FragmentException(ru.sbtqa.tag.pagefactory.exceptions.FragmentException)

Aggregations

EndpointPair (com.google.common.graph.EndpointPair)1 ScenarioDefinition (gherkin.ast.ScenarioDefinition)1 ArrayList (java.util.ArrayList)1 FragmentException (ru.sbtqa.tag.pagefactory.exceptions.FragmentException)1