Skip to content

Commit 1ca0460

Browse files
committed
Add equals/hashcode to FlashMap
Brings consistency with the existing compareTo implementation.
1 parent bb8be50 commit 1ca0460

File tree

1 file changed

+24
-0
lines changed
  • spring-webmvc/src/main/java/org/springframework/web/servlet

1 file changed

+24
-0
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.util.LinkedMultiValueMap;
2222
import org.springframework.util.MultiValueMap;
23+
import org.springframework.util.ObjectUtils;
2324
import org.springframework.util.StringUtils;
2425

2526
/**
@@ -146,6 +147,29 @@ public int compareTo(FlashMap other) {
146147
}
147148
}
148149

150+
@Override
151+
public boolean equals(Object obj) {
152+
if (this == obj) {
153+
return true;
154+
}
155+
if (obj != null && obj instanceof FlashMap) {
156+
FlashMap other = (FlashMap) obj;
157+
if (this.targetRequestParams.equals(other.targetRequestParams) &&
158+
ObjectUtils.nullSafeEquals(this.targetRequestPath, other.targetRequestPath)) {
159+
return true;
160+
}
161+
}
162+
return false;
163+
}
164+
165+
@Override
166+
public int hashCode() {
167+
int result = super.hashCode();
168+
result = 31 * result + (this.targetRequestPath != null ? this.targetRequestPath.hashCode() : 0);
169+
result = 31 * result + this.targetRequestParams.hashCode();
170+
return result;
171+
}
172+
149173
@Override
150174
public String toString() {
151175
StringBuilder sb = new StringBuilder();

0 commit comments

Comments
 (0)