Class RegularExpression<E>

  • Type Parameters:
    E - the type of the sequence elements
    All Implemented Interfaces:
    com.google.common.base.Predicate<java.util.List<E>>, java.util.function.Predicate<java.util.List<E>>

    public class RegularExpression<E>
    extends java.lang.Object
    implements com.google.common.base.Predicate<java.util.List<E>>
    A regular expression engine that operates over sequences of user-specified objects.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean apply​(java.util.List<E> tokens)
      Apply the expression against a list of tokens.
      static <E> FiniteAutomaton.Automaton<E> build​(java.util.List<Expression<E>> exprs)
      Build an NFA from the list of expressions.
      static <E> RegularExpression<E> compile​(java.lang.String expression, com.google.common.base.Function<java.lang.String,​Expression.BaseExpression<E>> factoryDelegate)
      Create a regular expression from the specified string.
      static <E> RegularExpression<E> compile​(java.util.List<Expression<E>> expressions)
      Create a regular expression without tokenization support.
      boolean equals​(java.lang.Object other)  
      Match<E> find​(java.util.List<E> tokens)
      Find the first match of the regular expression against tokens.
      Match<E> find​(java.util.List<E> tokens, int start)
      Find the first match of the regular expression against tokens, starting at the specified index.
      java.util.List<Match<E>> findAll​(java.util.List<E> tokens)
      Find all non-overlapping matches of the regular expression against tokens.
      int hashCode()  
      Match<E> lookingAt​(java.util.List<E> tokens)
      Determine if the regular expression matches the beginning of the supplied tokens.
      Match<E> lookingAt​(java.util.List<E> tokens, int start)
      Determine if the regular expression matches the supplied tokens, starting at the specified index.
      static void main​(java.lang.String[] args)
      An interactive program that compiles a word-based regular expression specified in arg1 and then reads strings from stdin, evaluating them against the regular expression.
      Match<E> match​(java.util.List<E> tokens)  
      boolean matches​(java.util.List<E> tokens)
      Apply the expression against a list of tokens.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.google.common.base.Predicate

        test
      • Methods inherited from interface java.util.function.Predicate

        and, negate, or
    • Constructor Detail

      • RegularExpression

        public RegularExpression​(java.util.List<Expression<E>> expressions)
    • Method Detail

      • compile

        public static <E> RegularExpression<E> compile​(java.util.List<Expression<E>> expressions)
        Create a regular expression without tokenization support.
        Parameters:
        expressions -
        Returns:
      • compile

        public static <E> RegularExpression<E> compile​(java.lang.String expression,
                                                       com.google.common.base.Function<java.lang.String,​Expression.BaseExpression<E>> factoryDelegate)
        Create a regular expression from the specified string.
        Parameters:
        expression -
        factoryDelegate -
        Returns:
      • equals

        public boolean equals​(java.lang.Object other)
        Specified by:
        equals in interface com.google.common.base.Predicate<E>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • build

        public static <E> FiniteAutomaton.Automaton<E> build​(java.util.List<Expression<E>> exprs)
        Build an NFA from the list of expressions.
        Parameters:
        exprs -
        Returns:
      • apply

        public boolean apply​(java.util.List<E> tokens)
        Apply the expression against a list of tokens.
        Specified by:
        apply in interface com.google.common.base.Predicate<E>
        Returns:
        true iff the expression if found within the tokens.
      • matches

        public boolean matches​(java.util.List<E> tokens)
        Apply the expression against a list of tokens.
        Returns:
        true iff the expression matches all of the tokens.
      • find

        public Match<E> find​(java.util.List<E> tokens)
        Find the first match of the regular expression against tokens. This method is slightly slower due to additional memory allocations. However, the response has much greater detail and is very useful for writing/debugging regular expressions.
        Parameters:
        tokens -
        Returns:
        an object representing the match, or null if no match is found.
      • find

        public Match<E> find​(java.util.List<E> tokens,
                             int start)
        Find the first match of the regular expression against tokens, starting at the specified index.
        Parameters:
        tokens - tokens to match against.
        start - index to start looking for a match.
        Returns:
        an object representing the match, or null if no match is found.
      • lookingAt

        public Match<E> lookingAt​(java.util.List<E> tokens)
        Determine if the regular expression matches the beginning of the supplied tokens.
        Parameters:
        tokens - the list of tokens to match.
        Returns:
        an object representing the match, or null if no match is found.
      • lookingAt

        public Match<E> lookingAt​(java.util.List<E> tokens,
                                  int start)
        Determine if the regular expression matches the supplied tokens, starting at the specified index.
        Parameters:
        tokens - the list of tokens to match.
        start - the index where the match should begin.
        Returns:
        an object representing the match, or null if no match is found.
      • match

        public Match<E> match​(java.util.List<E> tokens)
      • findAll

        public java.util.List<Match<E>> findAll​(java.util.List<E> tokens)
        Find all non-overlapping matches of the regular expression against tokens.
        Parameters:
        tokens -
        Returns:
        an list of objects representing the match.
      • main

        public static void main​(java.lang.String[] args)
        An interactive program that compiles a word-based regular expression specified in arg1 and then reads strings from stdin, evaluating them against the regular expression.
        Parameters:
        args -