Browse Source

Override equals(), hashCode() and toString() in DefaultRequest and DefaultRequestContext.

pull/855/head
Olga Maciaszek-Sharma 4 years ago
parent
commit
653222d561
  1. 28
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequest.java
  2. 28
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequestContext.java

28
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequest.java

@ -16,6 +16,10 @@ @@ -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<T> implements Request<T> { @@ -43,4 +47,28 @@ public class DefaultRequest<T> implements Request<T> {
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);
}
}

28
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultRequestContext.java

@ -16,6 +16,10 @@ @@ -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 { @@ -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);
}
}

Loading…
Cancel
Save