-
Notifications
You must be signed in to change notification settings - Fork 522
/
Copy pathPathSelectors.java
63 lines (57 loc) · 1.47 KB
/
PathSelectors.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.spring4all.swagger;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.util.AntPathMatcher;
/**
* 路径选择器
*/
public class PathSelectors {
private PathSelectors() {
throw new UnsupportedOperationException();
}
/**
* Any path satisfies this condition
*
* @return predicate that is always true
*/
public static Predicate<String> any() {
return Predicates.alwaysTrue();
}
/**
* No path satisfies this condition
*
* @return predicate that is always false
*/
public static Predicate<String> none() {
return Predicates.alwaysFalse();
}
/**
* Predicate that evaluates the supplied regular expression
*
* @param pathRegex - regex
* @return predicate that matches a particular regex
*/
public static Predicate<String> regex(final String pathRegex) {
return new Predicate<String>() {
@Override
public boolean apply(String input) {
return input.matches(pathRegex);
}
};
}
/**
* Predicate that evaluates the supplied ant pattern
*
* @param antPattern - ant Pattern
* @return predicate that matches a particular ant pattern
*/
public static Predicate<String> ant(final String antPattern) {
return new Predicate<String>() {
@Override
public boolean apply(String input) {
AntPathMatcher matcher = new AntPathMatcher();
return matcher.match(antPattern, input);
}
};
}
}