org.springframework.messaging.handler

## Class DestinationPatternsMessageCondition

- java.lang.Object
- - org.springframework.messaging.handler.AbstractMessageCondition<DestinationPatternsMessageCondition>
  - - org.springframework.messaging.handler.DestinationPatternsMessageCondition

- All Implemented Interfaces:
    MessageCondition<DestinationPatternsMessageCondition>

      public final class DestinationPatternsMessageCondition
      extends AbstractMessageCondition<DestinationPatternsMessageCondition>

  A `MessageCondition` for matching the destination of a Message against one or more destination patterns using a `PathMatcher`.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `LOOKUP_DESTINATION_HEADER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DestinationPatternsMessageCondition(String... patterns)` Creates a new instance with the given destination patterns.
    `DestinationPatternsMessageCondition(String[] patterns, PathMatcher pathMatcher)` Additional constructor with flags for using suffix pattern (.*) and trailing slash matches.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DestinationPatternsMessageCondition` | `combine(DestinationPatternsMessageCondition 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 `PathMatcher.combine(String, String)`.
    `int` | `compareTo(DestinationPatternsMessageCondition other, Message<?> message)` Compare the two conditions based on the destination patterns they contain.
    `protected Collection<String>` | `getContent()`
    `DestinationPatternsMessageCondition` | `getMatchingCondition(Message<?> message)` Check if any of the patterns match the given Message destination and return an instance that is guaranteed to contain matching patterns, sorted via `PathMatcher.getPatternComparator(String)`.
    `Set<String>` | `getPatterns()`
    `protected String` | `getToStringInfix()` The notation to use when printing discrete items of content.

    - ### Methods inherited from class org.springframework.messaging.handler.AbstractMessageCondition

      `equals, hashCode, toString`

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

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

- - ### Field Detail

    - #### LOOKUP_DESTINATION_HEADER

          public static final String LOOKUP_DESTINATION_HEADER

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DestinationPatternsMessageCondition

          public DestinationPatternsMessageCondition(String... patterns)

      Creates a new instance with the given destination patterns. Each pattern that is not empty and does not start with "/" is prepended with "/".
      Parameters:
        `patterns` - 0 or more URL patterns; if 0 the condition will match to every request.

    - #### DestinationPatternsMessageCondition

          public DestinationPatternsMessageCondition(String[] patterns,
                                                     PathMatcher pathMatcher)

      Additional constructor with flags for using suffix pattern (.*) and trailing slash matches.
      Parameters:
        `patterns` - the URL patterns to use; if 0, the condition will match to every request.
        `pathMatcher` - for path matching with patterns

  - ### Method Detail

    - #### getPatterns

          public Set<String> getPatterns()

    - #### getContent

          protected Collection<String> getContent()

      Specified by:
        `getContent` in class `AbstractMessageCondition<DestinationPatternsMessageCondition>`
      Returns:
        the collection of objects the message condition is composed of .g. destination patterns), never `null`

    - #### getToStringInfix

          protected String getToStringInfix()

      Description copied from class: `AbstractMessageCondition`
      The notation to use when printing discrete items of content. For example " || " for URL patterns or " && " for param expressions.
      Specified by:
        `getToStringInfix` in class `AbstractMessageCondition<DestinationPatternsMessageCondition>`

    - #### combine

          public DestinationPatternsMessageCondition combine(DestinationPatternsMessageCondition 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 `PathMatcher.combine(String, String)`.
      - 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:
        the resulting message condition

    - #### getMatchingCondition

          public DestinationPatternsMessageCondition getMatchingCondition(Message<?> message)

      Check if any of the patterns match the given Message destination and return an instance that is guaranteed to contain matching patterns, sorted via `PathMatcher.getPatternComparator(String)`.
      Parameters:
        `message` - the message to match to
      Returns:
        the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or `null` either if a destination can not be extracted or there is no match

    - #### compareTo

          public int compareTo(DestinationPatternsMessageCondition other,
                               Message<?> message)

      Compare the two conditions based on the destination patterns they contain. Patterns are compared one at a time, from top to bottom via `PathMatcher.getPatternComparator(String)`. 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(Message)` to ensure they contain only patterns that match the request and are sorted with the best matches on top.