Class RequestConditionHolder
- java.lang.Object
- org.springframework.web.reactive.result.condition.AbstractRequestCondition<RequestConditionHolder>
- org.springframework.web.reactive.result.condition.RequestConditionHolder
- All Implemented Interfaces:
RequestCondition<RequestConditionHolder>
public final class RequestConditionHolder extends AbstractRequestCondition<RequestConditionHolder>
A holder for aRequestConditionuseful when the type of the request condition is not known ahead of time, e.g. custom condition. Since this class is also an implementation ofRequestCondition, effectively it decorates the held request condition and allows it to be combined and compared with other request conditions in a type and null safe way.When two
RequestConditionHolderinstances are combined or compared with each other, it is expected the conditions they hold are of the same type. If they are not, aClassCastExceptionis raised.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description RequestConditionHolder(RequestCondition<?> requestCondition)Create a new holder to wrap the given request condition.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RequestConditionHoldercombine(RequestConditionHolder other)Combine the request conditions held by the two RequestConditionHolder instances after making sure the conditions are of the same type.intcompareTo(RequestConditionHolder other, ServerWebExchange exchange)Compare the request conditions held by the two RequestConditionHolder instances after making sure the conditions are of the same type.RequestCondition<?>getCondition()Return the held request condition, ornullif not holding one.protected Collection<?>getContent()Return the discrete items a request condition is composed of.RequestConditionHoldergetMatchingCondition(ServerWebExchange exchange)Get the matching condition for the held request condition wrap it in a new RequestConditionHolder instance.protected StringgetToStringInfix()The notation to use when printing discrete items of content.Methods inherited from class org.springframework.web.reactive.result.condition.AbstractRequestCondition
equals, hashCode, isEmpty, toString
Constructor Detail
RequestConditionHolder
public RequestConditionHolder(@Nullable RequestCondition<?> requestCondition)
Create a new holder to wrap the given request condition.- Parameters:
requestCondition- the condition to hold (may benull)
Method Detail
getCondition
@Nullable public RequestCondition<?> getCondition()
Return the held request condition, ornullif not holding one.
getContent
protected Collection<?> getContent()
Description copied from class:AbstractRequestConditionReturn the discrete items a request condition is composed of.For example URL patterns, HTTP request methods, param expressions, etc.
- Specified by:
getContentin classAbstractRequestCondition<RequestConditionHolder>- Returns:
- a collection of objects (never
null)
getToStringInfix
protected String getToStringInfix()
Description copied from class:AbstractRequestConditionThe notation to use when printing discrete items of content.For example
" || "for URL patterns or" && "for param expressions.- Specified by:
getToStringInfixin classAbstractRequestCondition<RequestConditionHolder>
combine
public RequestConditionHolder combine(RequestConditionHolder other)
Combine the request conditions held by the two RequestConditionHolder instances after making sure the conditions are of the same type. Or if one holder is empty, the other holder is returned.- Parameters:
other- the condition to combine with.- Returns:
- a request condition instance that is the result of combining the two condition instances.
getMatchingCondition
public RequestConditionHolder getMatchingCondition(ServerWebExchange exchange)
Get the matching condition for the held request condition wrap it in a new RequestConditionHolder instance. Or otherwise if this is an empty holder, return the same holder instance.- Returns:
- a condition instance in case of a match or
nullotherwise.
compareTo
public int compareTo(RequestConditionHolder other, ServerWebExchange exchange)
Compare the request conditions held by the two RequestConditionHolder instances after making sure the conditions are of the same type. Or if one holder is empty, the other holder is preferred.