E - the type of the base expressionspublic class LogicExpression<E>
extends java.lang.Object
implements com.google.common.base.Predicate<E>
| Modifier | Constructor and Description |
|---|---|
protected |
LogicExpression(java.util.List<Expression<E>> expressions) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
apply(E entity) |
static <E> Expression.Apply<E> |
buildAst(java.util.List<Expression<E>> rpn)
Compile a rpn list of tokens into an expression tree.
|
static <E> LogicExpression<E> |
compile(java.util.List<Expression<E>> expressions)
Compile an infix list of tokens into an expression tree.
|
static <E> LogicExpression<E> |
compile(java.lang.String input,
com.google.common.base.Function<java.lang.String,Expression.Arg<E>> factoryDelegate)
Helper factory method to instantiate a LogicExpression.
|
java.util.List<java.lang.String> |
getArgs()
Return a list of the arguments contained in the expression.
|
boolean |
isEmpty()
If the expression is empty, it returns true for all inputs.
|
static void |
main(java.lang.String[] args)
Iteractively interpret logic statements from stdin such as "true | (true & false)".
|
java.util.List<Expression<E>> |
rpn(java.util.List<Expression<E>> tokens)
Converts an infix logic representation into a postfix logic representation.
|
java.lang.String |
toString() |
protected LogicExpression(java.util.List<Expression<E>> expressions) throws LogicException.TokenizeLogicException, LogicException.CompileLogicException
input - an infix representation of the logic expression.LogicException.TokenizeLogicExceptionLogicException.CompileLogicExceptionpublic static <E> LogicExpression<E> compile(java.util.List<Expression<E>> expressions)
rpn - a list of tokens in infix form.public static <E> LogicExpression<E> compile(java.lang.String input, com.google.common.base.Function<java.lang.String,Expression.Arg<E>> factoryDelegate)
input - The string to parse.factoryDelegate - The factory to build tokens.public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isEmpty()
public boolean apply(E entity)
apply in interface com.google.common.base.Predicate<E>public static <E> Expression.Apply<E> buildAst(java.util.List<Expression<E>> rpn)
rpn - a list of tokens in infix form.public java.util.List<java.lang.String> getArgs()
public java.util.List<Expression<E>> rpn(java.util.List<Expression<E>> tokens) throws LogicException.CompileLogicException
tokens - a list of tokens in infix form.LogicException.CompileLogicExceptionpublic static void main(java.lang.String[] args)
args -