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 class
ValueConstraint.Type
An 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 void
add(OptionData optionData, int[] values)
Add a constraint ofValueConstraint.Type
INT_ARRAY
for the given optionstatic void
add(OptionData optionData, int imin, int imax)
Add a constraint ofValueConstraint.Type
INT_RANGE
for the given optionstatic void
add(OptionData optionData, java.lang.String[] values, boolean caseSensitive)
Add a constraint ofValueConstraint.Type
STRING_ARRAY
for the given optionstatic void
add(OptionData optionData, ValueConstraint.Type type, java.lang.String spec)
Add a constraint of the givenValueConstraint.Type
with the specified detailsvoid
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.boolean
isSatisfied()
The actual check routineboolean
supports(Constrainable constrainable)
Indicates whether a constraint supports a given type ofConstrainable
java.lang.String
toString()
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 ofConstrainable
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 areName Value Status type Same as the type
parameter inadd(OptionData, Type, String)
Required spec Same as the spec
parameter inadd(OptionData, Type, String)
Required - Specified by:
init
in interfaceXMLConstraint
- Parameters:
constrainable
- TheConstrainable
instance 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.Type
STRING_ARRAY
for 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.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 ofValueConstraint.Type
INT_RANGE
for 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.Type
with 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:
isSatisfied
in 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:
supports
in interfaceConstraint
- Parameters:
constrainable
-- Returns:
- A boolean to indicate whether this
Constrainable
is supported. This constraint only supportsOptionData
constrainables
-
toString
public java.lang.String toString()
This is the overloadedObject.toString()
method- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representing the instance
-
-