net.thucydides.core.requirements.RequirementsPath Maven / Gradle / Ivy
package net.thucydides.core.requirements;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.regex.Pattern;
import static org.apache.commons.collections.IteratorUtils.toList;
public class RequirementsPath {
private final static Pattern PATH_SEPARATORS = Pattern.compile("[\\\\/.]");
private final static Pattern FILE_SYSTEM_PATH_SEPARATORS = Pattern.compile("[\\\\/]");
public static List stripRootFromPath(String root, List storyPathElements) {
List rootElements = pathElements(root);
if (thePathIn(storyPathElements).startsWith(rootElements)) {
return storyPathElements.subList(rootElements.size(), storyPathElements.size());
} else {
return storyPathElements;
}
}
private static PathStartsWith thePathIn(List storyPathElements) {
return new PathStartsWith(storyPathElements);
}
public static List pathElements(String path) {
return toList(Splitter.on(PATH_SEPARATORS).omitEmptyStrings().trimResults().split(path).iterator());
}
public static List fileSystemPathElements(String path) {
return toList(Splitter.on(FILE_SYSTEM_PATH_SEPARATORS).omitEmptyStrings().trimResults().split(path).iterator());
}
}