Skip to content

Commit

Permalink
Insist on using CollectionUtils.isEmpty() and `StringUtils.hasLengt…
Browse files Browse the repository at this point in the history
…h()`

search `(\w+) != null && !(\1).isEmpty\(\)`
  • Loading branch information
quaff committed May 9, 2024
1 parent 8137cc9 commit deb3a8e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public MultiValueMapAdapter(Map<K, List<V>> targetMap) {
@Nullable
public V getFirst(K key) {
List<V> values = this.targetMap.get(key);
return (values != null && !values.isEmpty() ? values.get(0) : null);
return (!CollectionUtils.isEmpty(values) ? values.get(0) : null);
}

@Override
Expand Down Expand Up @@ -95,7 +95,7 @@ public void setAll(Map<K, V> values) {
public Map<K, V> toSingleValueMap() {
Map<K, V> singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size());
this.targetMap.forEach((key, values) -> {
if (values != null && !values.isEmpty()) {
if (!CollectionUtils.isEmpty(values)) {
singleValueMap.put(key, values.get(0));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -271,7 +272,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar
public String processMultipartFileList(@RequestParam(required = false) List<MultipartFile> file,
@RequestPart(required = false) Map<String, String> json) throws IOException {

if (file != null && !file.isEmpty()) {
if (!CollectionUtils.isEmpty(file)) {
byte[] content = file.get(0).getBytes();
assertThat(file.get(1).getBytes()).isEqualTo(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand Down Expand Up @@ -271,7 +272,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar
public String processMultipartFileList(@RequestParam(required = false) List<MultipartFile> file,
@RequestPart(required = false) Map<String, String> json) throws IOException {

if (file != null && !file.isEmpty()) {
if (!CollectionUtils.isEmpty(file)) {
byte[] content = file.get(0).getBytes();
assertThat(file.get(1).getBytes()).isEqualTo(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque

@Nullable
private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
if (path != null && !path.isEmpty()) {
if (StringUtils.hasLength(path)) {
path = getUrlPathHelper().decodeRequestString(request, path);
if (path.charAt(0) != '/') {
String requestUri = getUrlPathHelper().getRequestUri(request);
Expand Down

0 comments on commit deb3a8e

Please sign in to comment.