com.github.mikesafonov.specification.builder.starter.predicates.AndPredicateBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-starter-specification-builder Show documentation
Show all versions of spring-boot-starter-specification-builder Show documentation
Spring Boot starter for building specifications in declarative way
package com.github.mikesafonov.specification.builder.starter.predicates;
import lombok.RequiredArgsConstructor;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import java.util.Arrays;
import java.util.function.Function;
/**
* @author Mike Safonov
*/
@RequiredArgsConstructor
public class AndPredicateBuilder implements PredicateBuilder {
private final CriteriaBuilder cb;
private final Expression[] expressions;
private final Function predicateBuilderFunction;
@Override
public Predicate build() {
Predicate[] predicates = Arrays.stream(expressions)
.map(predicateBuilderFunction)
.map(PredicateBuilder::build)
.toArray(Predicate[]::new);
return cb.and(predicates);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy