本文整理了Java中jodd.util.Wildcard
类的一些代码示例,展示了Wildcard
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wildcard
类的具体详情如下:
包路径:jodd.util.Wildcard
类名称:Wildcard
[英]Checks whether a string or path matches a given wildcard pattern. Possible patterns allow to match single characters ('?') or any count of characters ('*'). Wildcard characters can be escaped (by an ''). When matching path, deep tree wildcard also can be used ('**').
This method uses recursive matching, as in linux or windows. regexp works the same. This method is very fast, comparing to similar implementations.
[中]检查字符串或路径是否与给定的通配符模式匹配。可能的模式允许匹配单个字符(“?”)或任意数量的字符(“*”)。通配符可以转义(通过“\”)。匹配路径时,还可以使用深树通配符(“**”)。
这种方法使用递归匹配,就像在linux或windows中一样。regexp的工作原理也是一样的。与类似的实现相比,这种方法速度非常快。
代码示例来源:origin: redisson/redisson
/**
* Checks whether a string matches a given wildcard pattern.
*
* @param string input string
* @param pattern pattern to match
* @return <code>true</code> if string matches the pattern, otherwise <code>false</code>
*/
public static boolean match(CharSequence string, CharSequence pattern) {
return match(string, pattern, 0, 0);
}
代码示例来源:origin: redisson/redisson
public boolean accept(String value, String rule, boolean include) {
return Wildcard.matchPath(value, rule);
}
};
代码示例来源:origin: redisson/redisson
/**
* Returns <code>true</code> if class or resource name matches
* at least one package rule from the list.
*/
protected boolean isMatchingRules(String name, String... rules) {
for (String rule : rules) {
if (Wildcard.equalsOrMatch(name, rule)) {
return true;
}
}
return false;
}
代码示例来源:origin: oblac/jodd
@Test
void testDifferences() {
assertTrue(Wildcard.match("/uphea", "*/uphea*"));
assertTrue(Wildcard.match("/prj/uphea-app.jar", "*/uphea*"));
assertTrue(Wildcard.matchPath("/uphea", "*/uphea*"));
assertTrue(Wildcard.matchPath("prj/uphea", "*/uphea*"));
assertFalse(Wildcard.matchPath("/prj/uphea-app.jar", "*/uphea*"));
assertTrue(Wildcard.matchPath("/prj/uphea-app.jar", "**/uphea*"));
assertTrue(Wildcard.match("/some/path/lib-jodd-v1", "*jodd*"));
assertTrue(Wildcard.matchPath("/some/path/lib-jodd-v1", "**/*jodd*"));
assertTrue(Wildcard.match("/some/path/lib-jodd-v1", "*/path/lib-jodd*"));
assertTrue(Wildcard.matchPath("/some/path/lib-jodd-v1", "**/path/lib-jodd*"));
assertTrue(Wildcard.match("/some/path/lib-jodd-v1", "*/lib-jodd*"));
assertTrue(Wildcard.matchPath("/some/path/lib-jodd-v1", "**/lib-jodd*"));
}
代码示例来源:origin: redisson/redisson
/**
* Accepts if a file is going to be watched.
*/
protected boolean acceptFile(File file) {
if (!file.isFile()) {
return false; // ignore non-files
}
String fileName = file.getName();
if (ignoreDotFiles) {
if (fileName.startsWith(StringPool.DOT)) {
return false; // ignore hidden files
}
}
if (patterns == null) {
return true;
}
return Wildcard.matchOne(fileName, patterns) != -1;
}
代码示例来源:origin: redisson/redisson
if (Wildcard.matchPathOne(entryName, patterns) == -1) {
continue;
代码示例来源:origin: redisson/redisson
/**
* Matches path against pattern using *, ? and ** wildcards.
* Both path and the pattern are tokenized on path separators (both \ and /).
* '**' represents deep tree wildcard, as in Ant.
*/
public static boolean matchPath(String path, String pattern) {
String[] pathElements = StringUtil.splitc(path, PATH_SEPARATORS);
String[] patternElements = StringUtil.splitc(pattern, PATH_SEPARATORS);
return matchTokens(pathElements, patternElements);
}
代码示例来源:origin: oblac/jodd
/**
* Accepts if a file is going to be watched.
*/
protected boolean acceptFile(final File file) {
if (!file.isFile()) {
return false; // ignore non-files
}
String fileName = file.getName();
if (ignoreDotFiles) {
if (fileName.startsWith(StringPool.DOT)) {
return false; // ignore hidden files
}
}
if (patterns == null) {
return true;
}
return Wildcard.matchOne(fileName, patterns) != -1;
}
代码示例来源:origin: oblac/jodd
if (Wildcard.matchPathOne(entryName, patterns) == -1) {
continue;
代码示例来源:origin: oblac/jodd
/**
* Matches path against pattern using *, ? and ** wildcards.
* Both path and the pattern are tokenized on path separators (both \ and /).
* '**' represents deep tree wildcard, as in Ant.
*/
public static boolean matchPath(final String path, final String pattern) {
String[] pathElements = StringUtil.splitc(path, PATH_SEPARATORS);
String[] patternElements = StringUtil.splitc(pattern, PATH_SEPARATORS);
return matchTokens(pathElements, patternElements);
}
代码示例来源:origin: redisson/redisson
public boolean accept(String value, String rule, boolean include) {
return Wildcard.match(value, rule);
}
};
代码示例来源:origin: redisson/redisson
/**
* Matches path to at least one pattern.
* Returns index of matched pattern or <code>-1</code> otherwise.
* @see #matchPath(String, String)
*/
public static int matchPathOne(String path, String[] patterns) {
for (int i = 0; i < patterns.length; i++) {
if (matchPath(path, patterns[i])) {
return i;
}
}
return -1;
}
代码示例来源:origin: oblac/jodd
/**
* Returns <code>true</code> if class or resource name matches
* at least one package rule from the list.
*/
protected boolean isMatchingRules(final String name, final String... rules) {
for (String rule : rules) {
if (Wildcard.equalsOrMatch(name, rule)) {
return true;
}
}
return false;
}
代码示例来源:origin: redisson/redisson
Wildcard.matchOne(entryMimeType, mimeTypes) :
StringUtil.equalsOne(entryMimeType, mimeTypes);
代码示例来源:origin: oblac/jodd
result = Wildcard.matchPathOne(uri, matches) != -1;
} else {
for (String match : matches) {
if (Wildcard.matchPathOne(uri, excludes) != -1) {
result = false;
代码示例来源:origin: org.jodd/jodd-core
/**
* Matches path against pattern using *, ? and ** wildcards.
* Both path and the pattern are tokenized on path separators (both \ and /).
* '**' represents deep tree wildcard, as in Ant.
*/
public static boolean matchPath(final String path, final String pattern) {
String[] pathElements = StringUtil.splitc(path, PATH_SEPARATORS);
String[] patternElements = StringUtil.splitc(pattern, PATH_SEPARATORS);
return matchTokens(pathElements, patternElements);
}
代码示例来源:origin: redisson/redisson
/**
* Matches string to at least one pattern.
* Returns index of matched pattern, or <code>-1</code> otherwise.
* @see #match(CharSequence, CharSequence)
*/
public static int matchOne(String src, String[] patterns) {
for (int i = 0; i < patterns.length; i++) {
if (match(src, patterns[i])) {
return i;
}
}
return -1;
}
代码示例来源:origin: oblac/jodd
/**
* Matches path to at least one pattern.
* Returns index of matched pattern or <code>-1</code> otherwise.
* @see #matchPath(String, String)
*/
public static int matchPathOne(final String path, final String... patterns) {
for (int i = 0; i < patterns.length; i++) {
if (matchPath(path, patterns[i])) {
return i;
}
}
return -1;
}
代码示例来源:origin: oblac/jodd
private void checkClassName(final List<String> classnameWhitelist, final String className) {
if (classnameWhitelist == null) {
return;
}
classnameWhitelist.forEach(pattern -> {
if (!Wildcard.equalsOrMatch(className, pattern)) {
throw new JsonException("Class can't be loaded as it is not whitelisted: " + className);
}
});
}
代码示例来源:origin: oblac/jodd
@SuppressWarnings("unchecked")
protected void extractMap(
final Map target,
final Map<String, PropsEntry> map,
final String[] profiles,
final String[] wildcardPatterns,
final String prefix
) {
for (Map.Entry<String, PropsEntry> entry : map.entrySet()) {
String key = entry.getKey();
if (wildcardPatterns != null) {
if (Wildcard.matchOne(key, wildcardPatterns) == -1) {
continue;
}
}
// shorten the key
if (prefix != null) {
if (!key.startsWith(prefix)) {
continue;
}
key = key.substring(prefix.length());
}
// only append if target DOES NOT contain the key
if (!target.containsKey(key)) {
target.put(key, entry.getValue().getValue(profiles));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!