All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cucumber.core.plugin.FeaturePathFormatter Maven / Gradle / Ivy

There is a newer version: 4.2.8
Show newest version
package io.cucumber.core.plugin;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class FeaturePathFormatter {

    private LineFilters lineFilters;

    public FeaturePathFormatter() {
        this.lineFilters = LineFilters.forCurrentContext();
    }

    public URI featurePathWithPrefixIfNecessary(final URI featurePath) {
        return lineFilters
                .getURIForFeaturePath(featurePath)
                .map(matchingURI -> featurePathWithPrefix(matchingURI, featurePath))
                .orElse(featurePath);
    }

    private URI featurePathWithPrefix(URI featurePathUri, URI featurePath) {
        Set allLineNumbersSet = lineFilters.getLineNumbersFor(featurePathUri);
        List allLineNumbersList = new ArrayList<>(allLineNumbersSet);
        long featurePathPrefix = allLineNumbersList.get(0);
        URI featureURIWithPrefix = featurePathUri;
        try {
            featureURIWithPrefix =  new URI(featurePath.toString() + ":" + featurePathPrefix);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        return featureURIWithPrefix;

    }

    private URI getURIForFeaturePath(Map> map, URI featurePath) {
        for (URI currentURI : map.keySet()) {
            if (featurePath.equals(currentURI)) {
                return currentURI;
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy