Class ConstraintBuilder


  • public final class ConstraintBuilder
    extends java.lang.Object
    The ConstraintBuilder class is a builder that creates Constraint objects.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConstraintBuilder()
      Constructs a ConstraintBuilder object with default values.
      ConstraintBuilder​(Constraint constraint)
      Constructs a ConstraintBuilder object object using information from an existing Constraint object.
      ConstraintBuilder​(ConstraintKind kind)
      Constructs a ConstraintBuilder object using the provided constraint type.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Variable addVariable​(java.lang.String name, Data data)
      Creates a variable that has the specified name and type, adds it to the constraint to be created and returns a reference to it.
      Variable addVariable​(java.lang.String name, DataType type)
      Creates a variable that has the specified name and type, adds it to the constraint to be created and returns a reference to it.
      void addVariableCopies​(java.lang.Iterable<Variable> variables)
      Adds copies of variables in the specified collection to the constraint to be created.
      void addVariables​(java.lang.Iterable<Variable> variables)
      Adds variables in the specified collection to the constraint to be created.
      Constraint build()
      Builds the Constraint object basing on the specified attributes and returns it.
      void setDescription​(java.lang.String description)
      Sets the description of the constraint to be created.
      void setInnerRep​(java.lang.Object value)
      Sets the internal representation of the constraint to be created.
      void setKind​(ConstraintKind kind)
      Sets the type of the constraint to be created.
      void setName​(java.lang.String name)
      Sets the name of the constraint to be created.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConstraintBuilder

        public ConstraintBuilder()
        Constructs a ConstraintBuilder object with default values.

        Default name is a pseudo random UUID (see java.util.UUID.randomUUID()). Default description is an empty string. Default constraint type is formula-based ConstraintKind.FORMULA_BASED).

      • ConstraintBuilder

        public ConstraintBuilder​(ConstraintKind kind)
        Constructs a ConstraintBuilder object using the provided constraint type.

        Default name is a pseudo random UUID (see java.util.UUID.randomUUID()). Default description is an empty string.

        Parameters:
        kind - Constraint type.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
      • ConstraintBuilder

        public ConstraintBuilder​(Constraint constraint)
        Constructs a ConstraintBuilder object object using information from an existing Constraint object.
        Parameters:
        constraint - An existing constraint.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
    • Method Detail

      • setName

        public void setName​(java.lang.String name)
        Sets the name of the constraint to be created.
        Parameters:
        name - Constraint name.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
      • setDescription

        public void setDescription​(java.lang.String description)
        Sets the description of the constraint to be created.
        Parameters:
        description - Constraint description.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
      • setKind

        public void setKind​(ConstraintKind kind)
        Sets the type of the constraint to be created.
        Parameters:
        kind - Constraint type.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
      • setInnerRep

        public void setInnerRep​(java.lang.Object value)
        Sets the internal representation of the constraint to be created.
        Parameters:
        value - Internal representation of the constraint.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
      • addVariables

        public void addVariables​(java.lang.Iterable<Variable> variables)
        Adds variables in the specified collection to the constraint to be created. Variables are added directly (no copies are created).
        Parameters:
        variables - A collection of variables.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null; if the specified variable name has already been use to define a variable that has different type or value (an illegal attempt to redefine the variable). See the internal addVariable method.
      • addVariableCopies

        public void addVariableCopies​(java.lang.Iterable<Variable> variables)
        Adds copies of variables in the specified collection to the constraint to be created.
        Parameters:
        variables - A collection of variables.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null; if the specified variable name has already been use to define a variable that has different type or value (an illegal attempt to redefine the variable). See the internal addVariable method.
      • addVariable

        public Variable addVariable​(java.lang.String name,
                                    DataType type)
        Creates a variable that has the specified name and type, adds it to the constraint to be created and returns a reference to it.
        Parameters:
        name - Variable name.
        type - Variable type.
        Returns:
        A reference to the created variable.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null; if the specified variable name has already been use to define a variable that has different type or value (an illegal attempt to redefine the variable). See the internal addVariable method.
      • addVariable

        public Variable addVariable​(java.lang.String name,
                                    Data data)
        Creates a variable that has the specified name and type, adds it to the constraint to be created and returns a reference to it.
        Parameters:
        name - Variable name.
        data - Data object that specifies the type and the value of the variable.
        Returns:
        A reference to the created variable.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters equals null; if the specified variable name has already been use to define a variable that has different type or value (an illegal attempt to redefine the variable). See the internal addVariable method.
      • build

        public Constraint build()
        Builds the Constraint object basing on the specified attributes and returns it.
        Returns:
        A new constraint.
        Throws:
        java.lang.IllegalArgumentException - see the invariants of the Constraint class constructor.