[BAEL-9557] - Modified not null checks with Objects::nonNull and Collector.toList()
This commit is contained in:
parent
4955159975
commit
1e7f8c47bf
|
@ -2,6 +2,7 @@ package org.baeldung.persistence.dao;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.baeldung.web.util.SearchCriteria;
|
||||
|
@ -29,7 +30,7 @@ public final class MyUserPredicatesBuilder {
|
|||
final List<BooleanExpression> predicates = params.stream().map(param -> {
|
||||
MyUserPredicate predicate = new MyUserPredicate(param);
|
||||
return predicate.getPredicate();
|
||||
}).filter(predicate -> predicate != null).collect(Collectors.toCollection(ArrayList::new));
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
|
||||
BooleanExpression result = Expressions.asBoolean(true).isTrue();
|
||||
for (BooleanExpression predicate : predicates) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class UserSpecificationsBuilder {
|
|||
|
||||
final List<Specification<User>> specs = params.stream()
|
||||
.map(UserSpecification::new)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Specification<User> result = specs.get(0);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung.persistence.dao.rsql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.data.jpa.domain.Specifications;
|
||||
|
@ -28,8 +28,8 @@ public class GenericRsqlSpecBuilder<T> {
|
|||
List<Specifications<T>> specs = logicalNode.getChildren()
|
||||
.stream()
|
||||
.map(node -> createSpecification(node))
|
||||
.filter(specifications -> specifications != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Specifications<T> initialSpec = specs.stream().findFirst().get();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.baeldung.persistence.dao.rsql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -89,7 +88,7 @@ public class GenericRsqlSpecification<T> implements Specification<T> {
|
|||
}
|
||||
return obj;
|
||||
|
||||
}).collect(Collectors.toCollection(ArrayList::new));
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return args;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.baeldung.web.controller;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -64,7 +63,7 @@ public class UserController {
|
|||
@ResponseBody
|
||||
public List<User> findAll(@RequestParam(value = "search", required = false) String search) {
|
||||
List<SearchCriteria> params = new ArrayList<SearchCriteria>();
|
||||
if (Optional.ofNullable(search).isPresent()) {
|
||||
if (search != null) {
|
||||
Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),");
|
||||
Matcher matcher = pattern.matcher(search + ",");
|
||||
while (matcher.find()) {
|
||||
|
@ -127,7 +126,7 @@ public class UserController {
|
|||
@ResponseBody
|
||||
public Iterable<MyUser> findAllByQuerydsl(@RequestParam(value = "search") String search) {
|
||||
MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder();
|
||||
if (Optional.ofNullable(search).isPresent()) {
|
||||
if (search != null) {
|
||||
Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),");
|
||||
Matcher matcher = pattern.matcher(search + ",");
|
||||
while (matcher.find()) {
|
||||
|
|
Loading…
Reference in New Issue