li.strolch.search.ValueSearchExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agent Show documentation
Show all versions of agent Show documentation
Strolch Agent which is the runtime for Strolch
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);
}
}