Consistent Nullable input in Hints
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,6 +25,7 @@ import org.springframework.core.io.buffer.DataBuffer;
|
|||||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants and convenience methods for working with hints.
|
* Constants and convenience methods for working with hints.
|
||||||
@@ -111,22 +112,22 @@ public abstract class Hints {
|
|||||||
* @param hints2 2nd map of hints
|
* @param hints2 2nd map of hints
|
||||||
* @return a single map with hints from both
|
* @return a single map with hints from both
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> merge(Map<String, Object> hints1, Map<String, Object> hints2) {
|
public static Map<String, Object> merge(
|
||||||
if (hints1.isEmpty() && hints2.isEmpty()) {
|
@Nullable Map<String, Object> hints1, @Nullable Map<String, Object> hints2) {
|
||||||
|
|
||||||
|
if (ObjectUtils.isEmpty(hints1) && ObjectUtils.isEmpty(hints2)) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
else if (hints2.isEmpty()) {
|
else if (ObjectUtils.isEmpty(hints2)) {
|
||||||
return hints1;
|
return (hints1 != null ? hints1 : Collections.emptyMap());
|
||||||
}
|
}
|
||||||
else if (hints1.isEmpty()) {
|
else if (ObjectUtils.isEmpty(hints1)) {
|
||||||
return hints2;
|
return hints2;
|
||||||
}
|
}
|
||||||
else {
|
Map<String, Object> result = CollectionUtils.newHashMap(hints1.size() + hints2.size());
|
||||||
Map<String, Object> result = CollectionUtils.newHashMap(hints1.size() + hints2.size());
|
result.putAll(hints1);
|
||||||
result.putAll(hints1);
|
result.putAll(hints2);
|
||||||
result.putAll(hints2);
|
return result;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,16 +139,14 @@ public abstract class Hints {
|
|||||||
* @param hintValue the hint value to merge
|
* @param hintValue the hint value to merge
|
||||||
* @return a single map with all hints
|
* @return a single map with all hints
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> merge(Map<String, Object> hints, String hintName, Object hintValue) {
|
public static Map<String, Object> merge(@Nullable Map<String, Object> hints, String hintName, Object hintValue) {
|
||||||
if (hints.isEmpty()) {
|
if (ObjectUtils.isEmpty(hints)) {
|
||||||
return Collections.singletonMap(hintName, hintValue);
|
return Collections.singletonMap(hintName, hintValue);
|
||||||
}
|
}
|
||||||
else {
|
Map<String, Object> result = CollectionUtils.newHashMap(hints.size() + 1);
|
||||||
Map<String, Object> result = CollectionUtils.newHashMap(hints.size() + 1);
|
result.putAll(hints);
|
||||||
result.putAll(hints);
|
result.put(hintName, hintValue);
|
||||||
result.put(hintName, hintValue);
|
return result;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user