Package ml.options

Class ValueConstraint

java.lang.Object
ml.options.ValueConstraint
All Implemented Interfaces:
Constraint, XMLConstraint

public class ValueConstraint extends Object implements XMLConstraint
A constraint for options taking a value. It allows to constrain the values acceptable for such an option to e. g. a list of strings.
  • Constructor Details

    • ValueConstraint

      public ValueConstraint()
      The public no-org constructor. This is a prereq for all constraints since it is used for initialization based on XML data.
  • Method Details

    • init

      public void init(Constrainable constrainable, List<org.jdom.Element> list)
      This method is used to initialize this constraint based on data read from an XML configuration file. The method is invoked internally during setup with the instance of Constrainable to which the constraint applies and a list of JDOM elements, which contain the details about the constraint itself.

      This method initializes the constraint and attaches it to the list of constraints of the Constrainable instance.

      The parameters expected in the XML <param> tags for this constraint are

      Name Value Status
      type Same as the type parameter in add(OptionData, Type, String) Required
      spec Same as the spec parameter in add(OptionData, Type, String) Required

      Specified by:
      init in interface XMLConstraint
      Parameters:
      constrainable - The Constrainable instance to which this constraint applies
      list - A list of JDOM elements to be used to initialize the constraint. Specifically, these are tags of the form

      <param name="..." value="..." />

      containing key/value pairs with information.

    • add

      public static void add(OptionData optionData, String[] values, boolean caseSensitive)
      Add a constraint of ValueConstraint.Type STRING_ARRAY for the given option

      Parameters:
      optionData -
      values - A string array with the acceptable values for the option
      caseSensitive - Whether the string comparisons are to be made case sensitive or not
    • add

      public static void add(OptionData optionData, int[] values)
      Add a constraint of ValueConstraint.Type INT_ARRAY for the given option

      Parameters:
      optionData -
      values - An integer array with the acceptable values for the option
    • add

      public static void add(OptionData optionData, int imin, int imax)
      Add a constraint of ValueConstraint.Type INT_RANGE for the given option

      Parameters:
      optionData -
      imin - The minimum acceptable integer value
      imax - The maximum acceptable integer value (must be greater than or equal to imin)
    • add

      public static void add(OptionData optionData, ValueConstraint.Type type, String spec)
      Add a constraint of the given ValueConstraint.Type with the specified details

      Parameters:
      optionData -
      type - The type for this constraint
      spec - A string specifying the details for this constraint:

      Type Format for specification
      STRING_ARRAY All values separated by vertical bar (e. g. Foo|Bah|Yeah). If the first string is preceded by '+', the checks are run case insensitive (default is to run them case sensitive)
      INT_ARRAY All values separated by vertical bar (e. g. 1|2|7)
      INT_RANGE MIN:MAX (e. g. 7:12)
    • isSatisfied

      public boolean isSatisfied()
      The actual check routine

      Specified by:
      isSatisfied in interface Constraint
      Returns:
      A boolean indicating whether the constraint is satisfied or not
    • supports

      public boolean supports(Constrainable constrainable)
      Indicates whether a constraint supports a given type of Constrainable

      Specified by:
      supports in interface Constraint
      Parameters:
      constrainable -
      Returns:
      A boolean to indicate whether this Constrainable is supported. This constraint only supports OptionData constrainables
    • toString

      public String toString()
      This is the overloaded Object.toString() method

      Overrides:
      toString in class Object
      Returns:
      A string representing the instance