org.apache.commons.cli2.validation
Class EnumValidator

java.lang.Object
  extended by org.apache.commons.cli2.validation.EnumValidator
All Implemented Interfaces:
Validator

public class EnumValidator
extends java.lang.Object
implements Validator

The EnumValidator validates the string argument values are valid. The following example shows how to limit the valid values for the color argument to 'red', 'green', or 'blue'.

 Set values = new HashSet();
 values.add("red");
 values.add("green");
 values.add("blue");
 ...
 ArgumentBuilder builder = new ArgumentBuilder();
 Argument color =
     builder.withName("color");
            .withValidator(new EnumValidator(values));
 

Author:
John Keyes

Field Summary
private  java.util.Set validValues
          List of permitted values
 
Constructor Summary
EnumValidator(java.util.Set values)
          Creates a new EnumValidator for the specified values.
 
Method Summary
 java.util.Set getValidValues()
          Returns the Set of valid argument values.
(package private)  java.lang.String getValuesAsString()
          Returns the permitted values in a comma separated String
protected  void setValidValues(java.util.Set validValues)
          Specifies the Set of valid argument values.
 void validate(java.util.List values)
          Validate the list of values against the list of permitted values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validValues

private java.util.Set validValues
List of permitted values

Constructor Detail

EnumValidator

public EnumValidator(java.util.Set values)
Creates a new EnumValidator for the specified values.

Parameters:
values - The list of permitted values
Method Detail

validate

public void validate(java.util.List values)
              throws InvalidArgumentException
Validate the list of values against the list of permitted values.

Specified by:
validate in interface Validator
Parameters:
values - The values to validate.
Throws:
InvalidArgumentException - If any of the specified values are not valid.
See Also:
Validator.validate(java.util.List)

getValuesAsString

java.lang.String getValuesAsString()
Returns the permitted values in a comma separated String

Returns:
String formatted list of values

getValidValues

public java.util.Set getValidValues()
Returns the Set of valid argument values.

Returns:
Returns the Set of valid argument values.

setValidValues

protected void setValidValues(java.util.Set validValues)
Specifies the Set of valid argument values.

Parameters:
validValues - The Set of valid argument values.