Clean up the code to make it cleaner
Signed-off-by: longtanfei <lucky8987@163.com>
This commit is contained in:
@@ -212,11 +212,6 @@
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
|
||||
@@ -77,8 +77,7 @@ public interface AsyncPredicate<T> extends Function<T, Publisher<Boolean>>, HasC
|
||||
|
||||
@Override
|
||||
public void accept(Visitor visitor) {
|
||||
if (delegate instanceof GatewayPredicate) {
|
||||
GatewayPredicate gatewayPredicate = (GatewayPredicate) delegate;
|
||||
if (delegate instanceof GatewayPredicate gatewayPredicate) {
|
||||
gatewayPredicate.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +58,7 @@ public class CookieRoutePredicateFactory extends AbstractRoutePredicateFactory<C
|
||||
if (cookies == null) {
|
||||
return false;
|
||||
}
|
||||
for (HttpCookie cookie : cookies) {
|
||||
if (cookie.getValue().matches(config.regexp)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return cookies.stream().anyMatch(cookie -> cookie.getValue().matches(config.regexp));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,8 +47,8 @@ public interface GatewayPredicate extends Predicate<ServerWebExchange>, HasConfi
|
||||
static GatewayPredicate wrapIfNeeded(Predicate<? super ServerWebExchange> other) {
|
||||
GatewayPredicate right;
|
||||
|
||||
if (other instanceof GatewayPredicate) {
|
||||
right = (GatewayPredicate) other;
|
||||
if (other instanceof GatewayPredicate gatewayPredicate) {
|
||||
right = gatewayPredicate;
|
||||
}
|
||||
else {
|
||||
right = new GatewayPredicateWrapper(other);
|
||||
@@ -72,8 +72,7 @@ public interface GatewayPredicate extends Predicate<ServerWebExchange>, HasConfi
|
||||
|
||||
@Override
|
||||
public void accept(Visitor visitor) {
|
||||
if (delegate instanceof GatewayPredicate) {
|
||||
GatewayPredicate gatewayPredicate = (GatewayPredicate) delegate;
|
||||
if (delegate instanceof GatewayPredicate gatewayPredicate) {
|
||||
gatewayPredicate.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,14 +201,10 @@ public class RouteDefinitionRouteLocator implements RouteLocator {
|
||||
// this is a very rare case, but possible, just match all
|
||||
return AsyncPredicate.from(exchange -> true);
|
||||
}
|
||||
AsyncPredicate<ServerWebExchange> predicate = lookup(routeDefinition, predicates.get(0));
|
||||
|
||||
for (PredicateDefinition andPredicate : predicates.subList(1, predicates.size())) {
|
||||
AsyncPredicate<ServerWebExchange> found = lookup(routeDefinition, andPredicate);
|
||||
predicate = predicate.and(found);
|
||||
}
|
||||
|
||||
return predicate;
|
||||
return predicates.stream()
|
||||
.map(nextPredicate -> lookup(routeDefinition, nextPredicate))
|
||||
.reduce(AsyncPredicate.from(exchange -> true), AsyncPredicate::and);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user