From 653222d561a3f2900e2ee3832261ac96aa79c869 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Fri, 2 Oct 2020 13:38:54 +0200 Subject: [PATCH] Override equals(), hashCode() and toString() in DefaultRequest and DefaultRequestContext. --- .../client/loadbalancer/DefaultRequest.java | 28 +++++++++++++++++++ .../loadbalancer/DefaultRequestContext.java | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequest.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequest.java index 1d4ae931..9cafa174 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequest.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequest.java @@ -16,6 +16,10 @@ package org.springframework.cloud.client.loadbalancer; +import java.util.Objects; + +import org.springframework.core.style.ToStringCreator; + /** * A default implementation of {@link Request}. * @@ -43,4 +47,28 @@ public class DefaultRequest implements Request { this.context = context; } + @Override + public String toString() { + ToStringCreator to = new ToStringCreator(this); + to.append("context", context); + return to.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DefaultRequest)) { + return false; + } + DefaultRequest that = (DefaultRequest) o; + return Objects.equals(context, that.context); + } + + @Override + public int hashCode() { + return Objects.hash(context); + } + } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequestContext.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequestContext.java index 4e6bc5e0..48da012f 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequestContext.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequestContext.java @@ -16,6 +16,10 @@ package org.springframework.cloud.client.loadbalancer; +import java.util.Objects; + +import org.springframework.core.style.ToStringCreator; + /** * Contains information relevant to the request. * @@ -44,4 +48,28 @@ public class DefaultRequestContext { this.hint = hint; } + @Override + public String toString() { + ToStringCreator to = new ToStringCreator(this); + to.append("hint", hint); + return to.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DefaultRequestContext)) { + return false; + } + DefaultRequestContext that = (DefaultRequestContext) o; + return Objects.equals(hint, that.hint); + } + + @Override + public int hashCode() { + return Objects.hash(hint); + } + }