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

li.strolch.search.ValueSearchExpression Maven / Gradle / Ivy

The newest version!
package li.strolch.search;

/**
 * Defines a search expression interface to perform where clauses on an object
 */
@FunctionalInterface
public interface ValueSearchExpression {

	/**
	 * See if this search expression matches the given element
	 *
	 * @param element
	 * 		the element to match
	 *
	 * @return true if the element is matched with this search expression
	 */
	boolean matches(T element);

	/**
	 * Returns a new search expression where this search expression is ORed with the given search expression
	 *
	 * @param right
	 * 		the right hand side of the search expression
	 *
	 * @return the new search expression with an internal OR of the two search expressions
	 */
	default ValueSearchExpression or(ValueSearchExpression right) {
		return element -> this.matches(element) || right.matches(element);
	}

	/**
	 * Returns a new search expression where this search expression is ANDed with the given search expression
	 *
	 * @param right
	 * 		the right hand side of the search expression
	 *
	 * @return the new search expression with an internal AND of the two search expressions
	 */
	default ValueSearchExpression and(ValueSearchExpression right) {
		return element -> this.matches(element) && right.matches(element);
	}

	/**
	 * Negates this search expression
	 *
	 * @return a new search expression where this search expression is negated
	 */
	default ValueSearchExpression not() {
		return element -> !this.matches(element);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy