CompositeRequestCondition.java (spring-framework-5.3.23) | : | CompositeRequestCondition.java (spring-framework-5.3.24) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright 2002-2021 the original author or authors. | * Copyright 2002-2022 the original author or authors. | |||
* | * | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | |||
* | * | |||
* https://www.apache.org/licenses/LICENSE-2.0 | * https://www.apache.org/licenses/LICENSE-2.0 | |||
* | * | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
skipping to change at line 34 | skipping to change at line 34 | |||
import org.springframework.util.Assert; | import org.springframework.util.Assert; | |||
import org.springframework.util.ObjectUtils; | import org.springframework.util.ObjectUtils; | |||
import org.springframework.web.server.ServerWebExchange; | import org.springframework.web.server.ServerWebExchange; | |||
/** | /** | |||
* Implements the {@link RequestCondition} contract by delegating to multiple | * Implements the {@link RequestCondition} contract by delegating to multiple | |||
* {@code RequestCondition} types and using a logical conjunction ({@code ' && ' }) to | * {@code RequestCondition} types and using a logical conjunction ({@code ' && ' }) to | |||
* ensure all conditions match a given request. | * ensure all conditions match a given request. | |||
* | * | |||
* <p>When {@code CompositeRequestCondition} instances are combined or compared | * <p>When {@code CompositeRequestCondition} instances are combined or compared | |||
* they are expected to (a) contain the same number of conditions and (b) that | * is expected that (a) they contain the same number of conditions and (b) | |||
* conditions in the respective index are of the same type. It is acceptable to | * conditions at the same index are of the same type. It is acceptable to | |||
* provide {@code null} conditions or no conditions at all to the constructor. | * provide {@code null} conditions or no conditions at all to the constructor. | |||
* | * | |||
* @author Rossen Stoyanchev | * @author Rossen Stoyanchev | |||
* @since 5.0 | * @since 5.0 | |||
*/ | */ | |||
public class CompositeRequestCondition extends AbstractRequestCondition<Composit eRequestCondition> { | public class CompositeRequestCondition extends AbstractRequestCondition<Composit eRequestCondition> { | |||
private final RequestConditionHolder[] requestConditions; | private final RequestConditionHolder[] requestConditions; | |||
/** | /** | |||
skipping to change at line 106 | skipping to change at line 106 | |||
protected String getToStringInfix() { | protected String getToStringInfix() { | |||
return " && "; | return " && "; | |||
} | } | |||
private int getLength() { | private int getLength() { | |||
return this.requestConditions.length; | return this.requestConditions.length; | |||
} | } | |||
/** | /** | |||
* If one instance is empty, return the other. | * If one instance is empty, return the other. | |||
* If both instances have conditions, combine the individual conditions | * <p>If both instances have conditions, combine the individual condition s | |||
* after ensuring they are of the same type and number. | * after ensuring they are of the same type and number. | |||
*/ | */ | |||
@Override | @Override | |||
public CompositeRequestCondition combine(CompositeRequestCondition other) { | public CompositeRequestCondition combine(CompositeRequestCondition other) { | |||
if (isEmpty() && other.isEmpty()) { | if (isEmpty() && other.isEmpty()) { | |||
return this; | return this; | |||
} | } | |||
else if (other.isEmpty()) { | else if (other.isEmpty()) { | |||
return this; | return this; | |||
} | } | |||
skipping to change at line 132 | skipping to change at line 132 | |||
RequestConditionHolder[] combinedConditions = new Request ConditionHolder[getLength()]; | RequestConditionHolder[] combinedConditions = new Request ConditionHolder[getLength()]; | |||
for (int i = 0; i < getLength(); i++) { | for (int i = 0; i < getLength(); i++) { | |||
combinedConditions[i] = this.requestConditions[i] .combine(other.requestConditions[i]); | combinedConditions[i] = this.requestConditions[i] .combine(other.requestConditions[i]); | |||
} | } | |||
return new CompositeRequestCondition(combinedConditions); | return new CompositeRequestCondition(combinedConditions); | |||
} | } | |||
} | } | |||
private void assertNumberOfConditions(CompositeRequestCondition other) { | private void assertNumberOfConditions(CompositeRequestCondition other) { | |||
Assert.isTrue(getLength() == other.getLength(), | Assert.isTrue(getLength() == other.getLength(), | |||
"Cannot combine CompositeRequestConditions with a | () -> "Cannot combine CompositeRequestConditions | |||
different number of conditions. " + | with a different number of conditions. " + | |||
ObjectUtils.nullSafeToString(this.requestConditio | ObjectUtils.nullSafeToString(this.requestConditio | |||
ns) + " and " + | ns) + " and " + | |||
ObjectUtils.nullSafeToString(other.requestConditi ons)); | ObjectUtils.nullSafeToString(other.requestConditi ons)); | |||
} | } | |||
/** | /** | |||
* Delegate to <em>all</em> contained conditions to match the request and return the | * Delegate to <em>all</em> contained conditions to match the request and return the | |||
* resulting "matching" condition instances. | * resulting "matching" condition instances. | |||
* <p>An empty {@code CompositeRequestCondition} matches to all requests. | * <p>An empty {@code CompositeRequestCondition} matches to all requests. | |||
*/ | */ | |||
@Override | @Override | |||
public CompositeRequestCondition getMatchingCondition(ServerWebExchange e xchange) { | public CompositeRequestCondition getMatchingCondition(ServerWebExchange e xchange) { | |||
End of changes. 4 change blocks. | ||||
8 lines changed or deleted | 8 lines changed or added |