Browse Source

Add equals(), hashCode() and toString() methods to HintRequestContext and RetryableRequestContext.

pull/837/head
Olga Maciaszek-Sharma 4 years ago
parent
commit
e1c570af07
  1. 19
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java
  2. 30
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java

19
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java

@ -16,6 +16,8 @@
package org.springframework.cloud.client.loadbalancer; package org.springframework.cloud.client.loadbalancer;
import java.util.Objects;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
/** /**
@ -53,4 +55,21 @@ public class HintRequestContext {
return to.toString(); return to.toString();
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof HintRequestContext)) {
return false;
}
HintRequestContext that = (HintRequestContext) o;
return Objects.equals(hint, that.hint);
}
@Override
public int hashCode() {
return Objects.hash(hint);
}
} }

30
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java

@ -16,7 +16,10 @@
package org.springframework.cloud.client.loadbalancer; package org.springframework.cloud.client.loadbalancer;
import java.util.Objects;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.core.style.ToStringCreator;
/** /**
* A request context object that allows storing information on previously used service * A request context object that allows storing information on previously used service
@ -46,4 +49,31 @@ public class RetryableRequestContext extends DefaultRequestContext {
return previousServiceInstance; return previousServiceInstance;
} }
@Override
public String toString() {
ToStringCreator to = new ToStringCreator(this);
to.append("previousServiceInstance", previousServiceInstance);
return to.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof RetryableRequestContext)) {
return false;
}
if (!super.equals(o)) {
return false;
}
RetryableRequestContext context = (RetryableRequestContext) o;
return Objects.equals(previousServiceInstance, context.previousServiceInstance);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), previousServiceInstance);
}
} }

Loading…
Cancel
Save