com.softicar.platform.common.core.java.classes.name.matcher.InternalGlobPatternToRegexConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.java.classes.name.matcher;
/**
* Converts a Java class name glob pattern into a regular expression.
*
* @see JavaClassNameGlobPatternMatcher
* @author Oliver Richers
*/
class InternalGlobPatternToRegexConverter {
private final String globPattern;
public InternalGlobPatternToRegexConverter(String globPattern) {
if (!globPattern.matches("[a-zA-Z0-9*_$\\.]+")) {
throw new IllegalArgumentException(String.format("Illegal glob pattern: '%s'", globPattern));
}
this.globPattern = globPattern;
}
public String convert() {
return globPattern//
.replace(".", "\\.")
.replaceAll("\\*\\*", "@")
.replaceAll("\\*", "[^\\\\.]*")
.replaceAll("@", ".*");
}
}