Search in sources :

Example 1 with SearchOperation

use of org.baeldung.web.util.SearchOperation in project tutorials by eugenp.

the class GenericSpecificationsBuilder method with.

public final GenericSpecificationsBuilder<U> with(final String precedenceIndicator, final String key, final String operation, final Object value, final String prefix, final String suffix) {
    SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0));
    if (op != null) {
        if (// the operation may be complex operation
        op == SearchOperation.EQUALITY) {
            final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
            final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
            if (startWithAsterisk && endWithAsterisk) {
                op = SearchOperation.CONTAINS;
            } else if (startWithAsterisk) {
                op = SearchOperation.ENDS_WITH;
            } else if (endWithAsterisk) {
                op = SearchOperation.STARTS_WITH;
            }
        }
        params.add(new SpecSearchCriteria(precedenceIndicator, key, op, value));
    }
    return this;
}
Also used : SearchOperation(org.baeldung.web.util.SearchOperation) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria)

Example 2 with SearchOperation

use of org.baeldung.web.util.SearchOperation in project tutorials by eugenp.

the class UserSpecificationsBuilder method with.

public final UserSpecificationsBuilder with(final String orPredicate, final String key, final String operation, final Object value, final String prefix, final String suffix) {
    SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0));
    if (op != null) {
        if (op == SearchOperation.EQUALITY) {
            // the operation may be complex operation
            final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
            final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
            if (startWithAsterisk && endWithAsterisk) {
                op = SearchOperation.CONTAINS;
            } else if (startWithAsterisk) {
                op = SearchOperation.ENDS_WITH;
            } else if (endWithAsterisk) {
                op = SearchOperation.STARTS_WITH;
            }
        }
        params.add(new SpecSearchCriteria(orPredicate, key, op, value));
    }
    return this;
}
Also used : SearchOperation(org.baeldung.web.util.SearchOperation) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria)

Aggregations

SearchOperation (org.baeldung.web.util.SearchOperation)2 SpecSearchCriteria (org.baeldung.web.util.SpecSearchCriteria)2