Class LogicExpressionParser<E>

  • Type Parameters:
    E - the type of the base expressions
    All Implemented Interfaces:
    com.google.common.base.Function<java.lang.String,​LogicExpression<E>>, java.util.function.Function<java.lang.String,​LogicExpression<E>>

    public abstract class LogicExpressionParser<E>
    extends java.lang.Object
    implements com.google.common.base.Function<java.lang.String,​LogicExpression<E>>
    A logic expression engine that operates over user specified objects.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      LogicExpression<E> apply​(java.lang.String string)  
      abstract Expression.Arg<E> factory​(java.lang.String argument)
      The factory method creates an argument from the supplied token string.
      LogicExpression<E> parse​(java.lang.String string)
      Create a LogicExpression object from the supplied string.
      java.lang.String readToken​(java.lang.String remainder)
      The readToken method reads a token from the remaining LogicExpression string.
      java.util.List<Expression<E>> tokenize​(java.lang.String input)
      Convert an infix string logic representation to an infix list of tokens.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.google.common.base.Function

        equals
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Field Detail

      • doubleQuoteStringLiteralRegex

        public static final java.util.regex.Pattern doubleQuoteStringLiteralRegex
      • singleQuoteStringLiteralRegex

        public static final java.util.regex.Pattern singleQuoteStringLiteralRegex
      • regexLiteralRegex

        public static final java.util.regex.Pattern regexLiteralRegex
      • literalPatterns

        private static final java.util.List<java.util.regex.Pattern> literalPatterns
    • Constructor Detail

      • LogicExpressionParser

        public LogicExpressionParser()
    • Method Detail

      • parse

        public LogicExpression<E> parse​(java.lang.String string)
        Create a LogicExpression object from the supplied string.
        Parameters:
        string -
        Returns:
      • apply

        public LogicExpression<E> apply​(java.lang.String string)
        Specified by:
        apply in interface com.google.common.base.Function<java.lang.String,​LogicExpression<E>>
        Specified by:
        apply in interface java.util.function.Function<java.lang.String,​LogicExpression<E>>
      • factory

        public abstract Expression.Arg<E> factory​(java.lang.String argument)
        The factory method creates an argument from the supplied token string.
        Parameters:
        argument - a string representation of a token
        Returns:
        an evaluatable representation of a token
      • readToken

        public java.lang.String readToken​(java.lang.String remainder)
        The readToken method reads a token from the remaining LogicExpression string. A token may contain a string. If it contains parentheses, the token will last until the parentheses are balanced. And &, |, or unbalanced ) will mark the end of a token. This is a default implementation that may be overriden.
        Parameters:
        remainder - the remaining text to tokenize
        Returns:
        a token from the beginning on `remaining`