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

This commit is contained in:
Olga Maciaszek-Sharma
2020-10-02 13:38:54 +02:00
parent 8748ef400f
commit 653222d561
2 changed files with 56 additions and 0 deletions

View File

@@ -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> {
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);
}
}

View File

@@ -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);
}
}