Class SimpleConstraint


  • public class SimpleConstraint
    extends Constraint
    Represents a constraint between two QueryEvaluable types. These are query elements that can be resolved to a value - fields, expressions, aggregate functions and constants. Constraint ops can be standard numeric comparison, IS_NULL, and also MATCHES for simple string pattern matching.
    Author:
    Richard Smith, Mark Woodbridge, Matthew Wakeling
    • Constructor Detail

      • SimpleConstraint

        public SimpleConstraint​(QueryEvaluable qe1,
                                ConstraintOp op,
                                QueryEvaluable qe2)
        Construct a Constraint. Check that java types of QueryEvaluables are compatible with the constraint type selected.
        Parameters:
        qe1 - first QueryEvaluable for comparison
        op - define comparison op
        qe2 - second QueryEvaluable for comparison
        Throws:
        java.lang.IllegalArgumentException - if type does not correspond to a defined operation
      • SimpleConstraint

        public SimpleConstraint​(QueryEvaluable qe1,
                                ConstraintOp op)
        Construct a Constraint. Check that correct constraint op is selected for single QueryEvaluable constructor
        Parameters:
        qe1 - first QueryEvaluable for comparison
        op - define op of comparison
        Throws:
        java.lang.IllegalArgumentException - if op does not correspond to a defined operation
    • Method Detail

      • getArg1

        public QueryEvaluable getArg1()
        Returns the left argument of the constraint.
        Returns:
        the left-hand argument
      • getArg2

        public QueryEvaluable getArg2()
        Returns the right argument of the constraint.
        Returns:
        the right-hand argument
      • equals

        public boolean equals​(java.lang.Object obj)
        Test whether two SimpleConstraints are equal, overrides Object.equals()
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to compare with
        Returns:
        true if objects are equal
      • hashCode

        public int hashCode()
        Get the hashCode for this object overrides Object.hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hashCode
      • validComparison

        public static boolean validComparison​(java.lang.Class<?> arg1,
                                              ConstraintOp op,
                                              java.lang.Class<?> arg2)
        Check whether a comparison is valid i.e. the arguments are comparable types and the the operator is permitted for those types
        Parameters:
        arg1 - the first argument
        op - how to compare the arguments
        arg2 - the second argument
        Returns:
        whether the comparison is valid
      • comparable

        public static boolean comparable​(java.lang.Class<?> arg1,
                                         java.lang.Class<?> arg2)
        Check whether the two arguments are of comparable types i.e. they are of similiar type and we know how to handle that type
        Parameters:
        arg1 - the first argument
        arg2 - the second argument
        Returns:
        whether the types are comparable
      • validOps

        public static java.util.List<ConstraintOp> validOps​(java.lang.Class<?> arg)
        Return the list of valid (binary) operator codes given arguments of a specified type
        Parameters:
        arg - the argument type
        Returns:
        an array of character codes
      • fixedEnumOps

        public static java.util.List<ConstraintOp> fixedEnumOps​(java.lang.Class<?> arg)
        For an argument type which an enumerated value set, return the list of operators for which it makes sense only to provide the enumerated values and not allow the user to enter an arbitrary string.
        Parameters:
        arg - the argument type
        Returns:
        constraint operators that will only accept an enumerated value
      • toString

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