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

com.jwebmp.entityassist.querybuilder.builders.GroupedExpression Maven / Gradle / Ivy

There is a newer version: 0.68.0.1
Show newest version
package com.jwebmp.entityassist.querybuilder.builders;

import com.jwebmp.entityassist.enumerations.GroupedFilterType;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import java.util.*;

/**
 * A grouped filter expression (bla bla bla) and (bla bla group 2)
 */
@SuppressWarnings("WeakerAccess")
public class GroupedExpression
		implements IFilterExpression
{
	/**
	 * The final set of expressions
	 */
	private final Set filterExpressions = new LinkedHashSet<>();

	/**
	 * The type of filter to apply
	 */
	private GroupedFilterType groupedFilterType;

	/**
	 * Returns the grouped filter type
	 *
	 * @return The given type
	 */
	@SuppressWarnings("unused")
	public GroupedFilterType getGroupedFilterType()
	{
		return groupedFilterType;
	}

	/**
	 * Method setGroupedFilterType sets the groupedFilterType of this GroupedExpression object.
	 * 

* The type of filter to apply * * @param groupedFilterType * the groupedFilterType of this GroupedExpression object. * * @return GroupedExpression */ @SuppressWarnings("UnusedReturnValue") public GroupedExpression setGroupedFilterType(GroupedFilterType groupedFilterType) { this.groupedFilterType = groupedFilterType; return this; } /** * Produces a predicate for the given filter expression * * * @return The predicate to apply */ @Override public Optional toPredicate(CriteriaBuilder builder) { List wheres = new ArrayList<>(); for (IFilterExpression filterExpression : getFilterExpressions()) { Optional op = filterExpression.toPredicate(builder); op.ifPresent(wheres::add); } if (wheres.isEmpty()) { return Optional.empty(); } else { Predicate[] preds = new Predicate[wheres.size()]; wheres.toArray(preds); Predicate groupPredicate = builder.or(preds); return Optional.of(groupPredicate); } } /** * Method getFilterExpressions returns the filterExpressions of this GroupedExpression object. *

* The final set of expressions * * @return the filterExpressions (type Set IFilterExpression ) of this GroupedExpression object. */ public Set getFilterExpressions() { return filterExpressions; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy