Skip to content

Commit

Permalink
Consistent MultiValueMap behavior for empty list values
Browse files Browse the repository at this point in the history
Closes gh-25227
  • Loading branch information
jhoeller committed Jun 10, 2020
1 parent 2010956 commit 00c9875
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -418,7 +418,7 @@ public void add(K key, V value) {
@Override
public V getFirst(K key) {
List<V> values = this.map.get(key);
return (values != null ? values.get(0) : null);
return (values != null && !values.isEmpty() ? values.get(0) : null);
}

@Override
Expand All @@ -439,7 +439,10 @@ public void setAll(Map<K, V> values) {
public Map<K, V> toSingleValueMap() {
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<K,V>(this.map.size());
for (Entry<K, List<V>> entry : map.entrySet()) {
singleValueMap.put(entry.getKey(), entry.getValue().get(0));
List<V> values = entry.getValue();
if (values != null && !values.isEmpty()) {
singleValueMap.put(entry.getKey(), values.get(0));
}
}
return singleValueMap;
}
Expand Down Expand Up @@ -506,10 +509,7 @@ public Set<Entry<K, List<V>>> entrySet() {

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return this.map.equals(other);
return (this == other || this.map.equals(other));
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -216,8 +216,8 @@ public LinkedCaseInsensitiveMap<V> clone() {
}

@Override
public boolean equals(Object obj) {
return this.targetMap.equals(obj);
public boolean equals(Object other) {
return (this == other || this.targetMap.equals(other));
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -208,8 +208,8 @@ public LinkedMultiValueMap<K, V> clone() {
}

@Override
public boolean equals(Object obj) {
return this.targetMap.equals(obj);
public boolean equals(Object other) {
return (this == other || this.targetMap.equals(other));
}

@Override
Expand Down

0 comments on commit 00c9875

Please sign in to comment.