From e1c570af07839951276ec6df2c0ac90588fcc151 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Fri, 2 Oct 2020 13:55:34 +0200 Subject: [PATCH] Add equals(), hashCode() and toString() methods to HintRequestContext and RetryableRequestContext. --- .../loadbalancer/HintRequestContext.java | 19 ++++++++++++ .../loadbalancer/RetryableRequestContext.java | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java index ac3bec5e..0ef6b1cc 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/HintRequestContext.java @@ -16,6 +16,8 @@ package org.springframework.cloud.client.loadbalancer; +import java.util.Objects; + import org.springframework.core.style.ToStringCreator; /** @@ -53,4 +55,21 @@ public class HintRequestContext { 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); + } + } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java index 20595fa2..ef8b32ec 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/RetryableRequestContext.java @@ -16,7 +16,10 @@ package org.springframework.cloud.client.loadbalancer; +import java.util.Objects; + import org.springframework.cloud.client.ServiceInstance; +import org.springframework.core.style.ToStringCreator; /** * A request context object that allows storing information on previously used service @@ -46,4 +49,31 @@ public class RetryableRequestContext extends DefaultRequestContext { 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); + } + }