From 850083ca6c5b9216efff34870fc0d79714605675 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 30 Jun 2017 16:11:55 -0400 Subject: [PATCH] Polish --- .../web/util/pattern/PathPattern.java | 26 +++++++++---------- .../util/pattern/PathPatternMatcherTests.java | 6 +++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index 800a4263425..bb7823b546b 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -90,7 +90,7 @@ public class PathPattern implements Comparable { private boolean caseSensitive; /** If this pattern has no trailing slash, allow candidates to include one and still match successfully */ - boolean allowOptionalTrailingSlash; + private boolean allowOptionalTrailingSlash; /** How many variables are captured in this pattern */ private int capturedVariableCount; @@ -122,8 +122,9 @@ public class PathPattern implements Comparable { private boolean catchAll = false; - PathPattern(String patternText, PathPatternParser parser, PathElement head, char separator, boolean caseSensitive, - boolean allowOptionalTrailingSlash) { + PathPattern(String patternText, PathPatternParser parser, @Nullable PathElement head, + char separator, boolean caseSensitive, boolean allowOptionalTrailingSlash) { + this.patternString = patternText; this.parser = parser; this.head = head; @@ -168,14 +169,11 @@ public class PathPattern implements Comparable { } @Nullable - public PathRemainingMatchInfo getPathRemaining(@Nullable String path) { - return getPathRemaining(path != null ? - PathContainer.parse(path, StandardCharsets.UTF_8) : null); + public PathRemainingMatchInfo getPathRemaining(String path) { + return getPathRemaining(PathContainer.parse(path, StandardCharsets.UTF_8)); } - - /** * @param pathContainer the candidate path container to attempt to match against this pattern * @return true if the path matches this pattern @@ -203,7 +201,7 @@ public class PathPattern implements Comparable { * or {@code null} if the path does not match this pattern */ @Nullable - public PathRemainingMatchInfo getPathRemaining(@Nullable PathContainer pathContainer) { + public PathRemainingMatchInfo getPathRemaining(PathContainer pathContainer) { if (this.head == null) { return new PathRemainingMatchInfo(pathContainer); } @@ -487,7 +485,7 @@ public class PathPattern implements Comparable { private final Map> matrixVariables; - public PathMatchResult(Map uriVars, + PathMatchResult(Map uriVars, @Nullable Map> matrixVars) { this.uriVariables = Collections.unmodifiableMap(uriVars); @@ -522,11 +520,11 @@ public class PathPattern implements Comparable { private final PathMatchResult pathMatchResult; - PathRemainingMatchInfo(@Nullable PathContainer pathRemaining) { + PathRemainingMatchInfo(PathContainer pathRemaining) { this(pathRemaining, PathMatchResult.EMPTY); } - PathRemainingMatchInfo(@Nullable PathContainer pathRemaining, PathMatchResult pathMatchResult) { + PathRemainingMatchInfo(PathContainer pathRemaining, PathMatchResult pathMatchResult) { this.pathRemaining = pathRemaining; this.pathMatchResult = pathMatchResult; } @@ -535,7 +533,7 @@ public class PathPattern implements Comparable { * Return the part of a path that was not matched by a pattern. */ public String getPathRemaining() { - return this.pathRemaining == null ? null: this.pathRemaining.value(); + return this.pathRemaining.value(); } /** @@ -727,7 +725,7 @@ public class PathPattern implements Comparable { * @param container a path container * @return true if the container is not null and has more than zero elements */ - private boolean hasLength(PathContainer container) { + private boolean hasLength(@Nullable PathContainer container) { return container != null && container.elements().size() > 0; } diff --git a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternMatcherTests.java b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternMatcherTests.java index 26e143ce976..5c93949c127 100644 --- a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternMatcherTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternMatcherTests.java @@ -39,6 +39,7 @@ import org.springframework.web.util.pattern.PathPattern.PathRemainingMatchInfo; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -339,24 +340,25 @@ public class PathPatternMatcherTests { assertEquals("",parse("/resource/{*foo}").getPathRemaining(toPathContainer("/resource")).getPathRemaining()); PathPattern.PathRemainingMatchInfo pri = parse("/aaa/{bbb}/c?d/e*f/*/g").getPathRemaining(toPathContainer("/aaa/b/ccd/ef/x/g/i")); + assertNotNull(pri); assertEquals("/i",pri.getPathRemaining()); assertEquals("b",pri.getUriVariables().get("bbb")); pri = parse("/aaa/{bbb}/c?d/e*f/*/g/").getPathRemaining(toPathContainer("/aaa/b/ccd/ef/x/g/i")); + assertNotNull(pri); assertEquals("i",pri.getPathRemaining()); assertEquals("b",pri.getUriVariables().get("bbb")); pri = parse("/{aaa}_{bbb}/e*f/{x}/g").getPathRemaining(toPathContainer("/aa_bb/ef/x/g/i")); + assertNotNull(pri); assertEquals("/i",pri.getPathRemaining()); assertEquals("aa",pri.getUriVariables().get("aaa")); assertEquals("bb",pri.getUriVariables().get("bbb")); assertEquals("x",pri.getUriVariables().get("x")); assertNull(parse("/a/b").getPathRemaining(toPathContainer(""))); - assertNull(parse("/a/b").getPathRemaining((String) null)); assertEquals("/a/b",parse("").getPathRemaining(toPathContainer("/a/b")).getPathRemaining()); assertEquals("",parse("").getPathRemaining(toPathContainer("")).getPathRemaining()); - assertNull(parse("").getPathRemaining((String) null).getPathRemaining()); } @Test