class ScenarioExtractorUtil {

    public static List<Scenario> extractScenarios(Source source, List<Feature> features) {
        List<Scenario> scenarios = new ArrayList<>();
        Scenario lastBackground = null;
        for (Feature feature : features) {
            for (Element element : feature.getElements()) {
                if (element.isBackground()) {
                    lastBackground = extractBackground(element);
                } else if (element.isScenario() && element.isSingleScenarioOrFirstOfOutline()) {
                    scenarios.add(extractScenario(source, feature, element, lastBackground));
                    lastBackground = null;
                }
            }
            lastBackground = null;
        }
        return scenarios;
    }

}