Polishing

This commit is contained in:
Juergen Hoeller
2013-10-30 00:53:55 +01:00
parent 326154270f
commit bfa30913fb
3 changed files with 83 additions and 92 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.springframework.util.AntPathMatcher;
@@ -54,6 +53,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
private final List<String> fileExtensions = new ArrayList<String>();
/**
* Creates a new instance with the given URL patterns.
* Each pattern that is not empty and does not start with "/" is prepended with "/".
@@ -66,7 +66,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
/**
* Additional constructor with flags for using suffix pattern (.*) and
* trailing slash matches.
*
* @param patterns the URL patterns to use; if 0, the condition will match to every request.
* @param urlPathHelper for determining the lookup path of a request
* @param pathMatcher for path matching with patterns
@@ -118,8 +117,9 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
}
}
private static List<String> asList(String... patterns) {
return patterns != null ? Arrays.asList(patterns) : Collections.<String>emptyList();
return (patterns != null ? Arrays.asList(patterns) : Collections.<String>emptyList());
}
private static Set<String> prependLeadingSlash(Collection<String> patterns) {
@@ -187,7 +187,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
* Checks if any of the patterns match the given request and returns an instance
* that is guaranteed to contain matching patterns, sorted via
* {@link PathMatcher#getPatternComparator(String)}.
*
* <p>A matching pattern is obtained by making checks in the following order:
* <ul>
* <li>Direct match
@@ -195,12 +194,10 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
* <li>Pattern match
* <li>Pattern match with "/" appended if the pattern doesn't already end in "/"
* </ul>
*
* @param request the current request
*
* @return the same instance if the condition contains no patterns;
* or a new condition with sorted matching patterns;
* or {@code null} if no patterns match.
* or a new condition with sorted matching patterns;
* or {@code null} if no patterns match.
*/
@Override
public PatternsRequestCondition getMatchingCondition(HttpServletRequest request) {
@@ -209,9 +206,8 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
}
String lookupPath = this.pathHelper.getLookupPathForRequest(request);
List<String> matches = new ArrayList<String>();
for (String pattern : patterns) {
for (String pattern : this.patterns) {
String match = getMatchingPattern(pattern, lookupPath);
if (match != null) {
matches.add(match);
@@ -259,7 +255,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
* {@link PathMatcher#getPatternComparator(String)}. If all compared
* patterns match equally, but one instance has more patterns, it is
* considered a closer match.
*
* <p>It is assumed that both instances have been obtained via
* {@link #getMatchingCondition(HttpServletRequest)} to ensure they
* contain only patterns that match the request and are sorted with
@@ -270,7 +265,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
String lookupPath = this.pathHelper.getLookupPathForRequest(request);
Comparator<String> patternComparator = this.pathMatcher.getPatternComparator(lookupPath);
Iterator<String> iterator = patterns.iterator();
Iterator<String> iterator = this.patterns.iterator();
Iterator<String> iteratorOther = other.patterns.iterator();
while (iterator.hasNext() && iteratorOther.hasNext()) {
int result = patternComparator.compare(iterator.next(), iteratorOther.next());