Package ml.options
Class ValueConstraint
- java.lang.Object
-
- ml.options.ValueConstraint
-
- All Implemented Interfaces:
Constraint,XMLConstraint
public class ValueConstraint extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classValueConstraint.TypeAn enum with the supported subtypes for this constraint type
-
Constructor Summary
Constructors Constructor Description ValueConstraint()The public no-org constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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, java.lang.String[] values, boolean caseSensitive)Add a constraint ofValueConstraint.TypeSTRING_ARRAYfor the given optionstatic voidadd(OptionData optionData, ValueConstraint.Type type, java.lang.String spec)Add a constraint of the givenValueConstraint.Typewith the specified detailsvoidinit(Constrainable constrainable, java.util.List<org.jdom.Element> list)This method is used to initialize this constraint based on data read from an XML configuration file.booleanisSatisfied()The actual check routinebooleansupports(Constrainable constrainable)Indicates whether a constraint supports a given type ofConstrainablejava.lang.StringtoString()This is the overloadedObject.toString()method
-
-
-
Method Detail
-
init
public void init(Constrainable constrainable, java.util.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 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
public static void add(OptionData optionData, java.lang.String[] values, boolean caseSensitive)
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
public static void add(OptionData optionData, int[] values)
Add a constraint ofValueConstraint.TypeINT_ARRAYfor 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 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
public static void add(OptionData optionData, ValueConstraint.Type type, java.lang.String spec)
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
public boolean supports(Constrainable constrainable)
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
public java.lang.String toString()
This is the overloadedObject.toString()method- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representing the instance
-
-