@@ -58,7 +58,9 @@ public class AntPathMatcher implements PathMatcher {
58
58
private static final Pattern VARIABLE_PATTERN = Pattern .compile ("\\ {[^/]+?\\ }" );
59
59
60
60
61
- private String pathSeparator = DEFAULT_PATH_SEPARATOR ;
61
+ private String pathSeparator ;
62
+
63
+ private PathSeparatorPatternCache pathSeparatorPatternCache ;
62
64
63
65
private boolean trimTokens = true ;
64
66
@@ -68,13 +70,13 @@ public class AntPathMatcher implements PathMatcher {
68
70
69
71
final Map <String , AntPathStringMatcher > stringMatcherCache = new ConcurrentHashMap <String , AntPathStringMatcher >(256 );
70
72
71
- private PathSeparatorPatternCache pathSeparatorPatternCache = new PathSeparatorPatternCache (DEFAULT_PATH_SEPARATOR );
72
-
73
73
74
74
/**
75
75
* Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
76
76
*/
77
77
public AntPathMatcher () {
78
+ this .pathSeparator = DEFAULT_PATH_SEPARATOR ;
79
+ this .pathSeparatorPatternCache = new PathSeparatorPatternCache (DEFAULT_PATH_SEPARATOR );
78
80
}
79
81
80
82
/**
@@ -580,14 +582,13 @@ public boolean matchStrings(String str, Map<String, String> uriTemplateVariables
580
582
* {@link #getPatternComparator(String)}.
581
583
* <p>In order, the most "generic" pattern is determined by the following:
582
584
* <ul>
583
- * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
584
- * <li>if the other pattern is an actual match</li>
585
- * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
586
- * <li>if it's got more "*" than the other pattern</li>
587
- * <li>if it's got more "{foo}" than the other pattern</li>
588
- * <li>if it's shorter than the other pattern</li>
585
+ * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
586
+ * <li>if the other pattern is an actual match</li>
587
+ * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
588
+ * <li>if it's got more "*" than the other pattern</li>
589
+ * <li>if it's got more "{foo}" than the other pattern</li>
590
+ * <li>if it's shorter than the other pattern</li>
589
591
* </ul>
590
- * </p>
591
592
*/
592
593
protected static class AntPatternComparator implements Comparator <String > {
593
594
@@ -598,15 +599,13 @@ public AntPatternComparator(String path) {
598
599
}
599
600
600
601
/**
601
- * Compare two patterns to determine which should match first, i.e. which is the most specific
602
- * regarding the current path.
603
- *
602
+ * Compare two patterns to determine which should match first, i.e. which
603
+ * is the most specific regarding the current path.
604
604
* @return a negative integer, zero, or a positive integer as pattern1 is
605
605
* more specific, equally specific, or less specific than pattern2.
606
606
*/
607
607
@ Override
608
608
public int compare (String pattern1 , String pattern2 ) {
609
-
610
609
PatternInfo info1 = new PatternInfo (pattern1 );
611
610
PatternInfo info2 = new PatternInfo (pattern2 );
612
611
@@ -664,6 +663,7 @@ else if (info2.getUriVars() < info1.getUriVars()) {
664
663
return 0 ;
665
664
}
666
665
666
+
667
667
/**
668
668
* Value class that holds information about the pattern, e.g. number of
669
669
* occurrences of "*", "**", and "{" pattern elements.
@@ -684,7 +684,6 @@ private static class PatternInfo {
684
684
685
685
private Integer length ;
686
686
687
-
688
687
public PatternInfo (String pattern ) {
689
688
this .pattern = pattern ;
690
689
if (this .pattern != null ) {
@@ -769,8 +768,7 @@ private static class PathSeparatorPatternCache {
769
768
770
769
private final String endsOnDoubleWildCard ;
771
770
772
-
773
- private PathSeparatorPatternCache (String pathSeparator ) {
771
+ public PathSeparatorPatternCache (String pathSeparator ) {
774
772
this .endsOnWildCard = pathSeparator + "*" ;
775
773
this .endsOnDoubleWildCard = pathSeparator + "**" ;
776
774
}
0 commit comments