Package org.springframework.web.servlet.mvc.condition

# Class PathPatternsRequestCondition

java.lang.Object
org.springframework.web.servlet.mvc.condition.AbstractRequestCondition<PathPatternsRequestCondition>
org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition

All Implemented Interfaces:
  `RequestCondition<PathPatternsRequestCondition>`

public final class PathPatternsRequestCondition extends AbstractRequestCondition<PathPatternsRequestCondition>
A logical disjunction (' || ') request condition that matches a request against a set of URL path patterns.

In contrast to `PatternsRequestCondition`, this condition uses parsed `PathPattern`s instead of String pattern matching with `AntPathMatcher`.

Since:
  5.3
Author:
  Rossen Stoyanchev

## Constructor Summary

Constructors
Constructor
Description
`PathPatternsRequestCondition()`
Default constructor resulting in an `""` (empty path) mapping.
`PathPatternsRequestCondition(org.springframework.web.util.pattern.PathPatternParser parser, String... patterns)`
Constructor with patterns to use.

## Method Summary

Modifier and Type
Method
Description
`PathPatternsRequestCondition`
`combine(PathPatternsRequestCondition other)`
Combine the patterns of the current and of the other instances as follows: If only one instance has patterns, use those.
`int`
`compareTo(PathPatternsRequestCondition other, HttpServletRequest request)`
Compare the two conditions based on the URL patterns they contain.
`protected Collection<org.springframework.web.util.pattern.PathPattern>`
`getContent()`
Return the discrete items a request condition is composed of.
`Set<String>`
`getDirectPaths()`
Return the mapping paths that are not patterns.
`org.springframework.web.util.pattern.PathPattern`
`getFirstPattern()`
Return the first pattern.
`PathPatternsRequestCondition`
`getMatchingCondition(HttpServletRequest request)`
Checks if any of the patterns match the given request and returns an instance that is guaranteed to contain matching patterns, sorted.
`Set<org.springframework.web.util.pattern.PathPattern>`
`getPatterns()`
Return the patterns in this condition.
`Set<String>`
`getPatternValues()`
Return the `getPatterns()` mapped to Strings.
`protected String`
`getToStringInfix()`
The notation to use when printing discrete items of content.
`boolean`
`isEmptyPathMapping()`
Whether the condition is the "" (empty path) mapping.

### Methods inherited from class org.springframework.web.servlet.mvc.condition.AbstractRequestCondition

`equals, hashCode, isEmpty, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### PathPatternsRequestCondition

public PathPatternsRequestCondition()
Default constructor resulting in an `""` (empty path) mapping.

### PathPatternsRequestCondition

public PathPatternsRequestCondition(org.springframework.web.util.pattern.PathPatternParser parser, String... patterns)
Constructor with patterns to use.

## Method Details

### getPatterns

public Set<org.springframework.web.util.pattern.PathPattern> getPatterns()
Return the patterns in this condition. If only the first (top) pattern is needed use `getFirstPattern()`.

### getContent

protected Collection<org.springframework.web.util.pattern.PathPattern> getContent()
Description copied from class: `AbstractRequestCondition`
Return the discrete items a request condition is composed of.

For example URL patterns, HTTP request methods, param expressions, etc.

Specified by:
  `getContent` in class `AbstractRequestCondition<PathPatternsRequestCondition>`
Returns:
  a collection of objects (never `null`)

### getToStringInfix

protected String getToStringInfix()
Description copied from class: `AbstractRequestCondition`
The notation to use when printing discrete items of content.

For example `" || "` for URL patterns or `" && "` for param expressions.

Specified by:
  `getToStringInfix` in class `AbstractRequestCondition<PathPatternsRequestCondition>`

### getFirstPattern

public org.springframework.web.util.pattern.PathPattern getFirstPattern()
Return the first pattern.

### isEmptyPathMapping

public boolean isEmptyPathMapping()
Whether the condition is the "" (empty path) mapping.

### getDirectPaths

public Set<String> getDirectPaths()
Return the mapping paths that are not patterns.

### getPatternValues

public Set<String> getPatternValues()
Return the `getPatterns()` mapped to Strings.

### combine

public PathPatternsRequestCondition combine(PathPatternsRequestCondition other)
Combine the patterns of the current and of the other instances as follows:

- If only one instance has patterns, use those.
- If both have patterns, combine patterns from "this" instance with patterns from the other instance via `PathPattern.combine(PathPattern)`.
- If neither has patterns, use `""` and `"/"` as root path patterns.

Parameters:
  `other` - the condition to combine with.
Returns:
  a request condition instance that is the result of combining the two condition instances.

### getMatchingCondition

@Nullable public PathPatternsRequestCondition getMatchingCondition(HttpServletRequest request)
Checks if any of the patterns match the given request and returns an instance that is guaranteed to contain matching patterns, sorted.

Parameters:
  `request` - the current request
Returns:
  the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or `null` if no patterns match.

### compareTo

public int compareTo(PathPatternsRequestCondition other, HttpServletRequest request)
Compare the two conditions based on the URL patterns they contain. Patterns are compared one at a time, from top to bottom. If all compared patterns match equally, but one instance has more patterns, it is considered a closer match.

It is assumed that both instances have been obtained via `getMatchingCondition(HttpServletRequest)` to ensure they contain only patterns that match the request and are sorted with the best matches on top.