Add equals/hashCode methods to ServerSentEvent

Closes gh-33606
This commit is contained in:
Juergen Hoeller
2024-09-30 11:22:43 +02:00
parent 8ab965c981
commit b59d0a396e
2 changed files with 24 additions and 28 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.http.codec;
import java.time.Duration;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
* Representation for a Server-Sent Event for use with Spring's reactive Web support.
@@ -102,6 +103,21 @@ public final class ServerSentEvent<T> {
}
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ServerSentEvent<?> that &&
ObjectUtils.nullSafeEquals(this.id, that.id) &&
ObjectUtils.nullSafeEquals(this.event, that.event) &&
ObjectUtils.nullSafeEquals(this.retry, that.retry) &&
ObjectUtils.nullSafeEquals(this.comment, that.comment) &&
ObjectUtils.nullSafeEquals(this.data, that.data)));
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHash(this.id, this.event, this.retry, this.comment, this.data);
}
@Override
public String toString() {
return ("ServerSentEvent [id = '" + this.id + "', event='" + this.event + "', retry=" +