Package ml.options
Class ValueConstraint
java.lang.Object
ml.options.ValueConstraint
- All Implemented Interfaces:
Constraint,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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAn enum with the supported subtypes for this constraint type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidadd(OptionData optionData, int[] values) Add a constraint ofValueConstraint.TypeINT_ARRAYfor the given optionstatic voidadd(OptionData optionData, int imin, int imax) Add a constraint ofValueConstraint.TypeINT_RANGEfor the given optionstatic voidadd(OptionData optionData, String[] values, boolean caseSensitive) Add a constraint ofValueConstraint.TypeSTRING_ARRAYfor the given optionstatic voidadd(OptionData optionData, ValueConstraint.Type type, String spec) Add a constraint of the givenValueConstraint.Typewith the specified detailsvoidinit(Constrainable constrainable, List<org.jdom.Element> list) This method is used to initialize this constraint based on data read from an XML configuration file.booleanThe actual check routinebooleansupports(Constrainable constrainable) Indicates whether a constraint supports a given type ofConstrainabletoString()This is the overloadedObject.toString()method
-
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
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 ofConstrainableto 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
Constrainableinstance.The parameters expected in the XML
<param>tags for this constraint areName Value Status type Same as the typeparameter inadd(OptionData, Type, String)Required spec Same as the specparameter inadd(OptionData, Type, String)Required - Specified by:
initin interfaceXMLConstraint- Parameters:
constrainable- TheConstrainableinstance to which this constraint applieslist- 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
Add a constraint ofValueConstraint.TypeSTRING_ARRAYfor the given option- Parameters:
optionData-values- A string array with the acceptable values for the optioncaseSensitive- Whether the string comparisons are to be made case sensitive or not
-
add
Add a constraint ofValueConstraint.TypeINT_ARRAYfor the given option- Parameters:
optionData-values- An integer array with the acceptable values for the option
-
add
Add a constraint ofValueConstraint.TypeINT_RANGEfor the given option- Parameters:
optionData-imin- The minimum acceptable integer valueimax- The maximum acceptable integer value (must be greater than or equal toimin)
-
add
Add a constraint of the givenValueConstraint.Typewith the specified details- Parameters:
optionData-type- The type for this constraintspec- 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:
isSatisfiedin interfaceConstraint- Returns:
- A boolean indicating whether the constraint is satisfied or not
-
supports
Indicates whether a constraint supports a given type ofConstrainable- Specified by:
supportsin interfaceConstraint- Parameters:
constrainable-- Returns:
- A boolean to indicate whether this
Constrainableis supported. This constraint only supportsOptionDataconstrainables
-
toString
This is the overloadedObject.toString()method
-