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

cucumber.runtime.model.PathWithLines Maven / Gradle / Ivy

There is a newer version: 7.18.1
Show newest version
package cucumber.runtime.model;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PathWithLines {
    private static final Pattern FILE_COLON_LINE_PATTERN = Pattern.compile("^([\\w\\W]*?):([\\d:]+)$");

    public final String path;
    public final List lines = new ArrayList();

    public static boolean hasLineFilters(String pathName) {
        return FILE_COLON_LINE_PATTERN.matcher(pathName).matches();
    }

    public static String stripLineFilters(String pathName) {
        Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName);
        if (matcher.matches()) {
            return matcher.group(1);
        } else {
            return pathName;
        }
    }

    public PathWithLines(String pathName) {
        Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName);
        if (matcher.matches()) {
            path = matcher.group(1);
            lines.addAll(toLongs(matcher.group(2).split(":")));
        } else {
            path = pathName;
        }
    }

    private static List toLongs(String[] strings) {
        List result = new ArrayList();
        for (String string : strings) {
            result.add(Long.parseLong(string));
        }
        return result;
    }

    public String toString() {
        return path + ":" + lines;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy