From 1ca0460534d207a4f3d2861d34dbb8bacb76eb27 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 19 Aug 2014 16:00:55 -0400 Subject: [PATCH] Add equals/hashcode to FlashMap Brings consistency with the existing compareTo implementation. --- .../springframework/web/servlet/FlashMap.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java index 6c9cdb0d19..c81a55b54e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java @@ -20,6 +20,7 @@ import java.util.HashMap; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** @@ -146,6 +147,29 @@ public final class FlashMap extends HashMap implements Comparabl } } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj != null && obj instanceof FlashMap) { + FlashMap other = (FlashMap) obj; + if (this.targetRequestParams.equals(other.targetRequestParams) && + ObjectUtils.nullSafeEquals(this.targetRequestPath, other.targetRequestPath)) { + return true; + } + } + return false; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (this.targetRequestPath != null ? this.targetRequestPath.hashCode() : 0); + result = 31 * result + this.targetRequestParams.hashCode(); + return result; + } + @Override public String toString() { StringBuilder sb = new StringBuilder();