org.springframework.web.reactive.result.condition

Class PatternsRequestCondition

    • Constructor Detail

      • PatternsRequestCondition

        public PatternsRequestCondition(PathPattern... patterns)
        Creates a new instance with the given URL patterns.
        Parameters:
        patterns - 0 or more URL patterns; if 0 the condition will match to every request.
      • PatternsRequestCondition

        public PatternsRequestCondition(java.util.List<PathPattern> patterns)
        Creates a new instance with the given Stream of URL patterns.
    • Method Detail

      • getPatterns

        public java.util.Set<PathPattern> getPatterns()
      • combine

        public PatternsRequestCondition combine(PatternsRequestCondition other)
        Returns a new instance with URL patterns from the current instance ("this") and the "other" instance as follows:
        • If there are patterns in both instances, combine the patterns in "this" with the patterns in "other" using PathPattern.combine(PathPattern).
        • If only one instance has patterns, use them.
        • If neither instance has patterns, use an empty String (i.e. "").
        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 PatternsRequestCondition getMatchingCondition(ServerWebExchange exchange)
        Checks if any of the patterns match the given request and returns an instance that is guaranteed to contain matching patterns, sorted.
        Parameters:
        exchange - the current exchange
        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(PatternsRequestCondition other,
                             ServerWebExchange exchange)
        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(ServerWebExchange) to ensure they contain only patterns that match the request and are sorted with the best matches on top.