Class LogicExpression


  • public class LogicExpression
    extends java.lang.Object
    In memory representation of constraint logic expression. Parses the expression provided to the constructor. Use the toString method to convert the expression back to text. An IllegalArgumentException will be thrown from the constructor if a parse error occurs (use the cause exception to find out why).
    Author:
    Thomas Riley
    See Also:
    PathQuery
    • Constructor Summary

      Constructors 
      Constructor Description
      LogicExpression​(java.lang.String expression)
      Create a new instance of LogicExpression parsing the given expression.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)
      java.lang.String getPartialString​(java.util.List<java.lang.String> variables)
      Produce an expression for this branch of the tree displaying only the children containing the variable in input
      LogicExpression.Node getRootNode()
      Get the root node.
      LogicExpression getSection​(java.util.Collection<java.lang.String> variables)
      Take a Collection of String variable names, and return the part of the Logic Expression that contains those variables.
      java.util.Set<java.lang.String> getVariableNames()
      Get the Set of variable names.
      int hashCode()
      void removeAllVariablesExcept​(java.util.Collection<java.lang.String> variables)
      Remove any variables that aren't in the given set.
      void removeVariable​(java.lang.String name)
      Remove a variable from the expression.
      java.util.List<LogicExpression> split​(java.util.List<? extends java.util.Collection<java.lang.String>> variables)
      Takes a List of collections of String variables and returns a List of the same length, containing sections of the LogicExpression with those variables in.
      java.lang.String toString()
      Get the expression as a string.
      LogicExpression validateForGroups​(java.util.List<? extends java.util.Collection<java.lang.String>> variables)
      Validates an expression for the given groups of codes, making sure each group is only ANDed together.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LogicExpression

        public LogicExpression​(java.lang.String expression)
        Create a new instance of LogicExpression parsing the given expression.
        Parameters:
        expression - the logic expression
        Throws:
        java.lang.IllegalArgumentException - if parse error occurs
    • Method Detail

      • toString

        public java.lang.String toString()
        Get the expression as a string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        expression as string
      • removeVariable

        public void removeVariable​(java.lang.String name)
        Remove a variable from the expression.
        Parameters:
        name - variable to remove
      • removeAllVariablesExcept

        public void removeAllVariablesExcept​(java.util.Collection<java.lang.String> variables)
        Remove any variables that aren't in the given set.
        Parameters:
        variables - Collection of variable names
      • getVariableNames

        public java.util.Set<java.lang.String> getVariableNames()
        Get the Set of variable names.
        Returns:
        set of variable names in this expression
      • split

        public java.util.List<LogicExpression> split​(java.util.List<? extends java.util.Collection<java.lang.String>> variables)
        Takes a List of collections of String variables and returns a List of the same length, containing sections of the LogicExpression with those variables in.
        Parameters:
        variables - a List of Collections of String variable names
        Returns:
        a List of LogicExpression objects
        Throws:
        java.lang.IllegalArgumentException - if the LogicExpression cannot be split up in this way, or if there is an overlap in variables, or if there is an unrepresented variable, or if there is an extra variable
      • getSection

        public LogicExpression getSection​(java.util.Collection<java.lang.String> variables)
        Take a Collection of String variable names, and return the part of the Logic Expression that contains those variables.
        Parameters:
        variables - a Collection of variable names
        Returns:
        a section of the LogicExpression
        Throws:
        java.lang.IllegalArgumentException - if there are unrecognised variables, or if the expression cannot be split up in that way
      • validateForGroups

        public LogicExpression validateForGroups​(java.util.List<? extends java.util.Collection<java.lang.String>> variables)
        Validates an expression for the given groups of codes, making sure each group is only ANDed together. Returns either this or an alternative LogicExpression.
        Parameters:
        variables - a List of Collections of String variable names
        Returns:
        a new LogicExpression
      • getPartialString

        public java.lang.String getPartialString​(java.util.List<java.lang.String> variables)
        Produce an expression for this branch of the tree displaying only the children containing the variable in input
        Parameters:
        variables - The variables to display.
        Returns:
        expression representing this branch
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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