Class CompositeRequestCondition
- java.lang.Object
- org.springframework.web.servlet.mvc.condition.AbstractRequestCondition<CompositeRequestCondition>
- org.springframework.web.servlet.mvc.condition.CompositeRequestCondition
- All Implemented Interfaces:
RequestCondition<CompositeRequestCondition>
public class CompositeRequestCondition extends AbstractRequestCondition<CompositeRequestCondition>
Implements theRequestCondition
contract by delegating to multipleRequestCondition
types and using a logical conjunction (' && ') to ensure all conditions match a given request.When
CompositeRequestCondition
instances are combined or compared they are expected to (a) contain the same number of conditions and (b) that conditions in the respective index are of the same type. It is acceptable to providenull
conditions or no conditions at all to the constructor.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description CompositeRequestCondition(RequestCondition<?>... requestConditions)
Create an instance with 0 or moreRequestCondition
types.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompositeRequestCondition
combine(CompositeRequestCondition other)
If one instance is empty, return the other.int
compareTo(CompositeRequestCondition other, HttpServletRequest request)
If one instance is empty, the other "wins".List<RequestCondition<?>>
getConditions()
Return the underlying conditions (possibly empty but nevernull
).protected Collection<?>
getContent()
Return the discrete items a request condition is composed of.CompositeRequestCondition
getMatchingCondition(HttpServletRequest request)
Delegate to all contained conditions to match the request and return the resulting "matching" condition instances.protected String
getToStringInfix()
The notation to use when printing discrete items of content.boolean
isEmpty()
Whether this instance contains 0 conditions or not.Methods inherited from class org.springframework.web.servlet.mvc.condition.AbstractRequestCondition
equals, hashCode, toString
Constructor Detail
CompositeRequestCondition
public CompositeRequestCondition(RequestCondition<?>... requestConditions)
Create an instance with 0 or moreRequestCondition
types. It is important to createCompositeRequestCondition
instances with the same number of conditions so they may be compared and combined. It is acceptable to providenull
conditions.
Method Detail
isEmpty
public boolean isEmpty()
Whether this instance contains 0 conditions or not.- Overrides:
isEmpty
in classAbstractRequestCondition<CompositeRequestCondition>
- Returns:
true
if empty;false
otherwise
getConditions
public List<RequestCondition<?>> getConditions()
Return the underlying conditions (possibly empty but nevernull
).
getContent
protected Collection<?> 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 classAbstractRequestCondition<CompositeRequestCondition>
- 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 classAbstractRequestCondition<CompositeRequestCondition>
combine
public CompositeRequestCondition combine(CompositeRequestCondition other)
If one instance is empty, return the other. If both instances have conditions, combine the individual conditions after ensuring they are of the same type and number.- 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 CompositeRequestCondition getMatchingCondition(HttpServletRequest request)
Delegate to all contained conditions to match the request and return the resulting "matching" condition instances.An empty
CompositeRequestCondition
matches to all requests.- Returns:
- a condition instance in case of a match or
null
otherwise.
compareTo
public int compareTo(CompositeRequestCondition other, HttpServletRequest request)
If one instance is empty, the other "wins". If both instances have conditions, compare them in the order in which they were provided.