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