Class ConstraintSet

  • All Implemented Interfaces:
    SQLStringable

    public class ConstraintSet
    extends AbstractConstraint
    A representation of a set of constraints ORed together.
    Author:
    Matthew Wakeling
    • Constructor Detail

      • ConstraintSet

        public ConstraintSet()
        Constructor for a ConstraintSet object. Add AbstractConstraint objects to this object with the add method.
    • Method Detail

      • add

        public void add​(AbstractConstraint obj)
        Add an AbstractConstraint to this ConstraintSet.
        Parameters:
        obj - an AbstractConstraint to add to this ConstraintSet
        Throws:
        java.lang.IllegalArgumentException - if obj contains in any way a ConstraintSet. (This is to protect us from having anything but a simple Conjunctive Normal Form expression.)
      • getSQLString

        public java.lang.String getSQLString()
        Returns a String representation of this ConstraintSet object, suitable for forming part of an SQL query.
        Specified by:
        getSQLString in interface SQLStringable
        Specified by:
        getSQLString in class AbstractConstraint
        Returns:
        the String representation
      • compare

        public int compare​(AbstractConstraint obj,
                           java.util.Map<AbstractTable,​AbstractTable> tableMap,
                           java.util.Map<AbstractTable,​AbstractTable> reverseTableMap)
        Compare this ConstraintSet with another AbstractConstraint, ignoring aliases in member fields and tables. Compare this AbstractConstraint with another, ignoring aliases in member fields and tables.
        Specified by:
        compare in class AbstractConstraint
        Parameters:
        obj - an AbstractConstraint to compare to
        tableMap - a Map from tables in this constraint to tables in obj
        reverseTableMap - a reverse of tableMap
        Returns:
        INDEPENDENT, IMPLIED_BY, IMPLIES, EQUAL, OPPOSITE, EXCLUDES, or OR, depending on the constraints.
      • internalCompare

        protected int internalCompare​(AbstractConstraint obj,
                                      java.util.Map<AbstractTable,​AbstractTable> tableMap,
                                      java.util.Map<AbstractTable,​AbstractTable> reverseTableMap)
        Compare this ConstraintSet with another AbstractConstraint, ignoring aliases in member fields and tables. If obj is a ConstraintSet, then the comparison returned is loose - that is, it accepts the possibility of an occurance that cannot actually happen. This is a safe operation, but to get a correct result, one should combine A.internalCompare(B) with B.internalCompare(A), using the AbstractConstraint.alterComparisonAnd method. Even then, we have not written a proof that this method returns a completely strict comparison.
        Also, note that it is possible that this method will return values other than the seven recognised comparisons, if a ConstraintSet contains constraints that EXCLUDE each other or compare to each other with the OR comparison. This is alright - the value that the method has returned is merely more strict than the seven "useful" values are, and reflects the fact that one of the ConstraintSets is always true or false. We don't think we will be constructing any such ConstraintSets, so it ought to be alright.
        Parameters:
        obj - an AbstractConstraint to compare to
        tableMap - a Map from tables in this constraint to tables in obj
        reverseTableMap - a reverse of tableMap
        Returns:
        INDEPENDENT, IMPLIED_BY, IMPLIES, EQUAL, OPPOSITE, EXCLUDES, or OR, depending on the constraints.
      • hashCode

        public int hashCode()
        Overrides Object.hashCode().
        Specified by:
        hashCode in class AbstractConstraint
        Returns:
        an arbitrary integer based on the contents of the Constraint
      • getConstraints

        public java.util.Set<AbstractConstraint> getConstraints()
        Returns the Set of constraints forming this object.
        Returns:
        the Set of Constraints