All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rocketbase.commons.service.PredicateHelper Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package io.rocketbase.commons.service;

import org.springframework.util.StringUtils;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

public interface PredicateHelper {

    default String buildLikeString(String value) {
        if (value.contains("*") || value.contains("%")) {
            return value.trim().toLowerCase().replace("*", "%");
        }
        return "%" + value.trim().toLowerCase() + "%";
    }

    default void addToListIfNotEmpty(List list, String value, String path, Root root, CriteriaBuilder cb) {
        if (!StringUtils.isEmpty(value)) {
            list.add(cb.like(cb.lower(root.get(path)), buildLikeString(value)));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy