Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.function.Predicate;

import org.reactivestreams.Publisher;

import reactor.core.publisher.Mono;

import org.springframework.cloud.gateway.handler.predicate.GatewayPredicate;
Expand Down Expand Up @@ -82,6 +83,23 @@ public void accept(Visitor visitor) {
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof DefaultAsyncPredicate)) {
return false;
}
DefaultAsyncPredicate<?> that = (DefaultAsyncPredicate<?>) o;
return Objects.equals(this.delegate, that.delegate);
}

@Override
public int hashCode() {
return Objects.hashCode(this.delegate);
}

}

class NegateAsyncPredicate<T> implements AsyncPredicate<T> {
Expand All @@ -95,14 +113,31 @@ public NegateAsyncPredicate(AsyncPredicate<? super T> predicate) {

@Override
public Publisher<Boolean> apply(T t) {
return Mono.from(predicate.apply(t)).map(b -> !b);
return Mono.from(predicate.apply(t)).map(result -> !result);
}

@Override
public String toString() {
return String.format("!(%s)", this.predicate);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof NegateAsyncPredicate)) {
return false;
}
NegateAsyncPredicate<?> that = (NegateAsyncPredicate<?>) o;
return Objects.equals(this.predicate, that.predicate);
}

@Override
public int hashCode() {
return Objects.hashCode(this.predicate);
}

}

class AndAsyncPredicate<T> implements AsyncPredicate<T> {
Expand All @@ -120,7 +155,8 @@ public AndAsyncPredicate(AsyncPredicate<? super T> left, AsyncPredicate<? super

@Override
public Publisher<Boolean> apply(T t) {
return Mono.from(left.apply(t)).flatMap(result -> !result ? Mono.just(false) : Mono.from(right.apply(t)));
return Mono.from(left.apply(t))
.flatMap(result -> !result ? Mono.just(false) : Mono.from(right.apply(t)));
}

@Override
Expand All @@ -134,6 +170,23 @@ public String toString() {
return String.format("(%s && %s)", this.left, this.right);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof AndAsyncPredicate)) {
return false;
}
AndAsyncPredicate<?> that = (AndAsyncPredicate<?>) o;
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
}

@Override
public int hashCode() {
return Objects.hash(this.left, this.right);
}

}

class OrAsyncPredicate<T> implements AsyncPredicate<T> {
Expand All @@ -151,7 +204,8 @@ public OrAsyncPredicate(AsyncPredicate<? super T> left, AsyncPredicate<? super T

@Override
public Publisher<Boolean> apply(T t) {
return Mono.from(left.apply(t)).flatMap(result -> result ? Mono.just(true) : Mono.from(right.apply(t)));
return Mono.from(left.apply(t))
.flatMap(result -> result ? Mono.just(true) : Mono.from(right.apply(t)));
}

@Override
Expand All @@ -165,6 +219,23 @@ public String toString() {
return String.format("(%s || %s)", this.left, this.right);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof OrAsyncPredicate)) {
return false;
}
OrAsyncPredicate<?> that = (OrAsyncPredicate<?>) o;
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
}

@Override
public int hashCode() {
return Objects.hash(this.left, this.right);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import org.springframework.cloud.gateway.support.Visitor;
import org.springframework.web.server.ServerWebExchange;

/**
* A {@link Predicate} that is specific to Spring Cloud Gateway, providing additional
* methods for composing predicates and visiting them.
*/
public interface GatewayPredicate extends Predicate<ServerWebExchange>, HasConfig {

@Override
Expand All @@ -46,7 +50,6 @@ default void accept(Visitor visitor) {

static GatewayPredicate wrapIfNeeded(Predicate<? super ServerWebExchange> other) {
GatewayPredicate right;

if (other instanceof GatewayPredicate gatewayPredicate) {
right = gatewayPredicate;
}
Expand Down Expand Up @@ -82,6 +85,23 @@ public String toString() {
return this.delegate.getClass().getSimpleName();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof GatewayPredicateWrapper)) {
return false;
}
GatewayPredicateWrapper that = (GatewayPredicateWrapper) o;
return Objects.equals(this.delegate, that.delegate);
}

@Override
public int hashCode() {
return Objects.hashCode(this.delegate);
}

}

class NegateGatewayPredicate implements GatewayPredicate {
Expand All @@ -94,8 +114,8 @@ public NegateGatewayPredicate(GatewayPredicate predicate) {
}

@Override
public boolean test(ServerWebExchange t) {
return !this.predicate.test(t);
public boolean test(ServerWebExchange exchange) {
return !this.predicate.test(exchange);
}

@Override
Expand All @@ -108,6 +128,23 @@ public String toString() {
return String.format("!%s", this.predicate);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof NegateGatewayPredicate)) {
return false;
}
NegateGatewayPredicate that = (NegateGatewayPredicate) o;
return Objects.equals(this.predicate, that.predicate);
}

@Override
public int hashCode() {
return Objects.hashCode(this.predicate);
}

}

class AndGatewayPredicate implements GatewayPredicate {
Expand All @@ -124,8 +161,8 @@ public AndGatewayPredicate(GatewayPredicate left, GatewayPredicate right) {
}

@Override
public boolean test(ServerWebExchange t) {
return (this.left.test(t) && this.right.test(t));
public boolean test(ServerWebExchange exchange) {
return this.left.test(exchange) && this.right.test(exchange);
}

@Override
Expand All @@ -139,6 +176,23 @@ public String toString() {
return String.format("(%s && %s)", this.left, this.right);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof AndGatewayPredicate)) {
return false;
}
AndGatewayPredicate that = (AndGatewayPredicate) o;
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
}

@Override
public int hashCode() {
return Objects.hash(this.left, this.right);
}

}

class OrGatewayPredicate implements GatewayPredicate {
Expand All @@ -155,8 +209,8 @@ public OrGatewayPredicate(GatewayPredicate left, GatewayPredicate right) {
}

@Override
public boolean test(ServerWebExchange t) {
return (this.left.test(t) || this.right.test(t));
public boolean test(ServerWebExchange exchange) {
return this.left.test(exchange) || this.right.test(exchange);
}

@Override
Expand All @@ -170,6 +224,23 @@ public String toString() {
return String.format("(%s || %s)", this.left, this.right);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof OrGatewayPredicate)) {
return false;
}
OrGatewayPredicate that = (OrGatewayPredicate) o;
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
}

@Override
public int hashCode() {
return Objects.hash(this.left, this.right);
}

}

}
Loading