net.sourceforge.argval.impl
Class ArgumentValidationImpl

java.lang.Object
  extended by net.sourceforge.argval.impl.ArgumentValidationImpl
All Implemented Interfaces:
ArgumentValidation

public class ArgumentValidationImpl
extends Object
implements ArgumentValidation

The class for validating arguments of (public) methods and constructors (precondition checking). For each argument that does not fulfill the required conditions, a message is added. These messages are used to create an IllegalArgumentException before the real work of the method / constructor should be started.

A simple example without pattern matching

First the incoming Strings are polished, which in fact means that they are trimmed (str.trim()) and when only a empty string remains it's changed into null. There are several methods isValidXxxx, which can be used to validate all kinds of conditions.

An example with pattern matching and set matching

 public class Address {
     private final static String PATTERN_DUTCH_POSTALCODE = "dutch_postalcode";
     
     private static Map patternMap;
     private static Set countrySet;
     
     static {
         patternMap = new HashMap();
         patternMap.put(PATTERN_DUTCH_POSTALCODE, "^[0-9]{4}[ ]?[A-Z]{2}$");
     
         countrySet = new HashSet();
         countrySet.add("The Netherlands");
     }
     
 public Address(String street, Integer houseNumber, String postbox, String postalCode, String city, String country) {
     street = ArgumentValidation.polish(street);
     postalCode = ArgumentValidation.polish(postalCode);
     city = ArgumentValidation.polish(city);
     country = ArgumentValidation.polish(country);
     
     ArgumentValidation argVal = new ArgumentValidation(patternMap);
         if (argVal.isValidWhenNotNull("street", street)) {
             argVal.isValidWhenGreaterThen("houseNumber", houseNumber.intValue(), 0);
        
         if (postalCode != null) {
             argVal.addError("When argument 'street' is given, no value for argument 'postbox' is expected.");
         }
     }
     else if (argVal.isValidWhenNotNull("postbox", postbox)) {
         if (argVal.isValidWhenNotNull("street", street)
                 || argVal.isValidWhenGreaterThen("houseNumber", houseNumber.intValue(), 0)) {
             argVal.addError("When argument 'postbox' is given, no values for argument 'street' and 'houseNumber' are expected.");
         }
     }
     argVal.isValidMatchingPattern("postalCode", postalCode, PATTERN_DUTCH_POSTALCODE);
     argVal.isValidWhenNotNull("city", city);
     argVal.isValidWhenInSet("country", country, countrySet);
     if (argVal.containsIllegalArgument()) throw argVal.createIllegalArgumentException();
     
     }
     
 }
 

An example with pattern matching, patterns added through a Properties instance

   private final static String PATTERN_NUMBER = "number";
   private final static String PATTERN_DUTCH_POSTALCODE = "dutch_postalcode";
 
   private static Properties properties;
   
   // Inside the constructor (or static initialization) create a (static) Properties instance, or inject it!
   public Constructor() {
       // Creating a Properties instance, with two pattern names {'number', postalcode'}.
       // Add for each pattern name a regular expression. As property file it should look like:
       // argument_validation.patterns = number postalcode 
       // argument_validation.number.regexp = ^[0-9]+$
       // argument_validation.postalcode.regexp = ^[0-9]{4}[ ]?[A-Z]{2}$
       properties = new Properties();
       properties.setProperty(ConfigurationManager.PROP_ARG_VAL_PATTERNS, PATTERN_NUMBER + " " + PATTERN_DUTCH_POSTALCODE);
       properties.setProperty(PropertiesUtil.createKey(
                   ConfigurationManager.PROP_ARG_VAL, PATTERN_NUMBER, ConfigurationManager.PROP_POSTFIX_REG_EXP), "^[0-9]+$");
       properties.setProperty(PropertiesUtil.createKey(
                   ConfigurationManager.PROP_ARG_VAL, PATTERN_DUTCH_POSTALCODE, ConfigurationManager.PROP_POSTFIX_REG_EXP), "^[0-9]{4}[ ]?[A-Z]{2}$");
   }
   
   
   public void doSomething(String number, String postalcode) {
       postalcode = ArgumentValidation.polishToUpper(postalcode);     
       ArgumentValidation argVal = new ArgumentValidation(properties);
       
       // Check the conditions by using regular expressions
       argVal.isValidMatchingPattern("number", number, PATTERN_NUMBER);
       argVal.isValidMatchingPattern("postalcode", postalcode, PATTERN_DUTCH_POSTALCODE);
       
       // Create an IllegalArgumentException if not all argument conditions are met.
       if (argVal.containsIllegalArgument()) throw argVal.createIllegalArgumentException();
       
       // Doing the real work for this method
       .....
   }
 

The patterns can also be added through a properties file. Each pattern must have a name, through which the method isValidMatchingPattern(<arg as string>, <arg>, <pattern name>) will access the regular expression. Each pattern name has to be named under the key argument_validation.patterns. To assign each pattern name a regular expression, the key combination of argument_validation.<pattern name>.regexp is used.

 argument_validation.patterns = number postalcode 
 argument_validation.number.regexp = ^[0-9]+$
 argument_validation.postalcode.regexp = ^[0-9]{4}[ ]?[A-Z]{2}$
 

Author:
T. Verhagen

Field Summary
 
Fields inherited from interface net.sourceforge.argval.ArgumentValidation
VALIDATION_TYPE_NAME_ARGUMENT, VALIDATION_TYPE_NAME_PROPERTY_KEY
 
Constructor Summary
ArgumentValidationImpl()
          The default constructor.
ArgumentValidationImpl(Map<String,String> patternMap)
          Construct an ArgumentValidation instance, which can also validate against regular expressions.
ArgumentValidationImpl(Map<String,String> patternMap, Map<String,String> dateFormatMap)
           
ArgumentValidationImpl(Map<String,String> patternMap, Map<String,String> dateFormatMap, String validationTypeName)
           
ArgumentValidationImpl(Map<String,String> patternMap, org.apache.oro.text.regex.PatternCompiler compiler, org.apache.oro.text.regex.PatternMatcher matcher)
          Construct an ArgumentValidation instance, which can also validate against regular expressions.
ArgumentValidationImpl(Map<String,String> patternMap, org.apache.oro.text.regex.PatternCompiler compiler, org.apache.oro.text.regex.PatternMatcher matcher, Map<String,String> dateFormatMap)
           
ArgumentValidationImpl(Map<String,String> patternMap, org.apache.oro.text.regex.PatternCompiler compiler, org.apache.oro.text.regex.PatternMatcher matcher, Map<String,String> dateFormatMap, String validationTypeName)
           
ArgumentValidationImpl(Map<String,String> patternMap, org.apache.oro.text.regex.PatternCompiler compiler, org.apache.oro.text.regex.PatternMatcher matcher, String validationTypeName)
           
ArgumentValidationImpl(Map<String,String> patternMap, String validationTypeName)
           
ArgumentValidationImpl(Properties properties, org.apache.oro.text.regex.PatternCompiler compiler, org.apache.oro.text.regex.PatternMatcher matcher)
          TODO [2007.07.18 tv] update with date pattern Construct an ArgumentValidation instance, which can also validate against regular expressions.
ArgumentValidationImpl(String validationTypeName)
          The default constructor.
 
Method Summary
 void addError(String error)
          Add an error message to the list of error messages.
 void addError(String argumentName, String message)
          Add an error message, for the given argumentName, to the list of error messages.
 void addError(String argumentName, String key, String message)
          Add an error message, for when the argument is a Map instance, to the list of error messages, for the given key.
 boolean containsIllegalArgument()
          Returns true if there are arguments checked (through one of the methods isValidXxxxx), that did not full fill the condition of that validation check, otherwise false.
 IllegalArgumentException createIllegalArgumentException()
          Creates an IllegalArgumentException with a detailed message about which arguments did not satisfy the required conditions.
 String getMessage()
          Creates a message about all the validated conditions which are not satisfied.
 Map<String,String> getPattern()
          Returns the Map of pattern names and their regular expression.
 org.apache.oro.text.regex.Pattern getPattern(String patternName)
          Returns the Pattern found under the patternName, or throws an IllegalArgumentException if the patternName is not available.
 Set<String> getPatternNames()
          Returns the Set of pattern names.
 String getRegularExpression(String patternName)
          Returns the regular expression found under the patternName, or throws an IllegalArgumentException if the patternName is not available.
 boolean isValidCollectionWhenMinElements(String argumentName, Collection<?> argumentValue, int minElements)
          Validates if the Collection argumentValue is at least containing the minimal number of elements (minElements).
 boolean isValidCollectionWhenNoNulls(String argumentName, Collection<?> argumentValue)
          Validates if the Collection argumentValue is not null and that its containing elements are also not null.
 boolean isValidMatchingDateFormat(String argumentName, String argumentValue, DateFormat dateFormat)
          Validates if the String argumentValue matches the dateFormat.
 boolean isValidMatchingDateFormat(String argumentName, String argumentValue, String dateFormatName)
          Validates if the String argumentValue matches the date format registered under the dateFormatName.
 boolean isValidMatchingPattern(String argumentName, String argumentValue, String patternName)
          Validates if the String argumentValue matches the pattern regisstered under the patternName.
 boolean isValidNotNullForKey(String argumentName, Map<String,String> argumentValueMap, String key)
           
 boolean isValidStringLength(String argumentName, String argumentValue, int length)
          Validates if the String argumentValue has an exact length of length.
 boolean isValidStringMaxLength(String argumentName, String argumentValue, int maxLength)
          Validates if the String argumentValue has a maximum length of maxLength.
 boolean isValidStringMinAndMaxLength(String argumentName, String argumentValue, int minLength, int maxLength)
          Validates if the String argumentValue has a minimal length of minLength and a maximum length of maxLength.
 boolean isValidStringMinLength(String argumentName, String argumentValue, int minLength)
          Validates if the String argumentValue has a minimal length of minLength.
 boolean isValidWhenBoolean(String argumentName, String argumentValue)
          Validates if the String argumentValue contains the text true or false.
 boolean isValidWhenDirectory(String argumentName, File argumentValue)
           
 boolean isValidWhenDirectory(String argumentName, String argumentValue)
          Validates if the String argumentValue is a directory.
 boolean isValidWhenFile(String argumentName, File argumentValue)
           
 boolean isValidWhenFile(String argumentName, String argumentValue)
          Validates if the String argumentValue is a file.
 boolean isValidWhenGreaterThen(String argumentName, int argumentValue, int value)
          Validates if the Integer argumentValue is greate then Integer value.
 boolean isValidWhenInSet(String argumentName, String argumentValue, Set<String> argumentSet)
          Validates if the String argumentValue is an element contained by the Set argumentSet.
 boolean isValidWhenInteger(String argumentName, String argumentValue)
          Validates if the String argumentValue is an Integer value.
 boolean isValidWhenLong(String argumentName, String argumentValue)
          Validates if the String argumentValue is a Long value.
 boolean isValidWhenNotInSet(String argumentName, String argumentValue, Set<String> argumentSet)
          Validates if the String argumentValue is not already contained by the Set argumentSet.
 boolean isValidWhenNotNull(String argumentName, Object argumentValue)
          Validates if the String argumentValue contains an instance reference (is not null).
 boolean isValidWhenNotNullInCollection(String argumentName, Collection<?> argumentValue)
           
 boolean isValidWhenUri(String argumentName, String argumentValue)
          Validates if the String argumentValue is an valid uri.
 boolean isValidWhenUrl(String argumentName, String argumentValue)
          Validates if the String argumentValue is an valid url.
static String polish(String text)
          Returns the incoming text, but stripes leading and trailing spaces and returns null when the (remaining) text is an empty String instance.
static String polishToLower(String text)
          Returns the incoming text polished (see polish(String) and converted into lower case.
static String polishToUpper(String text)
          Returns the incoming text polished (see polish(String) and converted into upper case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgumentValidationImpl

public ArgumentValidationImpl()
The default constructor.


ArgumentValidationImpl

public ArgumentValidationImpl(String validationTypeName)
The default constructor.


ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap)
Construct an ArgumentValidation instance, which can also validate against regular expressions. It will use the org.apache.oro.text.regex.Perl5Compiler and org.apache.oro.text.regex.Perl5Matcher. See for detailed information on creating regular expressions the package description.

Parameters:
patternMap - A Map instance, containing pattern names and their regular expressions.

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              String validationTypeName)

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              Map<String,String> dateFormatMap)

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              Map<String,String> dateFormatMap,
                              String validationTypeName)

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              org.apache.oro.text.regex.PatternCompiler compiler,
                              org.apache.oro.text.regex.PatternMatcher matcher)
Construct an ArgumentValidation instance, which can also validate against regular expressions. See for detailed information on creating regular expressions the package description.

Parameters:
patternMap - A Map instance, containing pattern names and their regular expressions.
compiler - A org.apache.oro.text.regex.PatternCompiler compiler.
matcher - A org.apache.oro.text.regex.PatternMatcher matcher.

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              org.apache.oro.text.regex.PatternCompiler compiler,
                              org.apache.oro.text.regex.PatternMatcher matcher,
                              String validationTypeName)

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              org.apache.oro.text.regex.PatternCompiler compiler,
                              org.apache.oro.text.regex.PatternMatcher matcher,
                              Map<String,String> dateFormatMap)

ArgumentValidationImpl

public ArgumentValidationImpl(Map<String,String> patternMap,
                              org.apache.oro.text.regex.PatternCompiler compiler,
                              org.apache.oro.text.regex.PatternMatcher matcher,
                              Map<String,String> dateFormatMap,
                              String validationTypeName)
Parameters:
patternMap -
compiler -
matcher -
dateFormatMap -
validationTypeName - - The type of validation (default 'Argument'), but use this for checking other type of things like 'Property-key's.

ArgumentValidationImpl

public ArgumentValidationImpl(Properties properties,
                              org.apache.oro.text.regex.PatternCompiler compiler,
                              org.apache.oro.text.regex.PatternMatcher matcher)
TODO [2007.07.18 tv] update with date pattern Construct an ArgumentValidation instance, which can also validate against regular expressions. See for detailed information on creating regular expressions the package description.

Parameters:
properties - A properties instance, containing pattern names and their regular expressions.
compiler - A org.apache.oro.text.regex.PatternCompiler compiler.
matcher - A org.apache.oro.text.regex.PatternMatcher matcher.
Method Detail

getMessage

public String getMessage()
Description copied from interface: ArgumentValidation
Creates a message about all the validated conditions which are not satisfied.

Specified by:
getMessage in interface ArgumentValidation
Returns:
The message containing the details about the not met conditions.

containsIllegalArgument

public boolean containsIllegalArgument()
Description copied from interface: ArgumentValidation
Returns true if there are arguments checked (through one of the methods isValidXxxxx), that did not full fill the condition of that validation check, otherwise false.

Specified by:
containsIllegalArgument in interface ArgumentValidation
Returns:
true if not all validated conditions are satisfied, otherwise false.

createIllegalArgumentException

public IllegalArgumentException createIllegalArgumentException()
Description copied from interface: ArgumentValidation
Creates an IllegalArgumentException with a detailed message about which arguments did not satisfy the required conditions.

Specified by:
createIllegalArgumentException in interface ArgumentValidation
Returns:
a new IllegalArgumentException
See Also:
ArgumentValidation.getMessage()

isValidWhenNotNull

public boolean isValidWhenNotNull(String argumentName,
                                  Object argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue contains an instance reference (is not null).

Specified by:
isValidWhenNotNull in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenNotNullInCollection

public boolean isValidWhenNotNullInCollection(String argumentName,
                                              Collection<?> argumentValue)
Specified by:
isValidWhenNotNullInCollection in interface ArgumentValidation

addError

public void addError(String argumentName,
                     String message)
Add an error message, for the given argumentName, to the list of error messages.

Specified by:
addError in interface ArgumentValidation
Parameters:
argumentName - - the argument (or property-key) in which the problem is found.
message - - the message that describes the problem.

addError

public void addError(String argumentName,
                     String key,
                     String message)
Description copied from interface: ArgumentValidation
Add an error message, for when the argument is a Map instance, to the list of error messages, for the given key.

Specified by:
addError in interface ArgumentValidation
Parameters:
argumentName - - the argument Map (or property-key).
key - - the key under which the problem is found.
message - - the message that describes the problem.

isValidWhenBoolean

public boolean isValidWhenBoolean(String argumentName,
                                  String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue contains the text true or false.

Specified by:
isValidWhenBoolean in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenInteger

public boolean isValidWhenInteger(String argumentName,
                                  String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is an Integer value.

Specified by:
isValidWhenInteger in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenLong

public boolean isValidWhenLong(String argumentName,
                               String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is a Long value.

Specified by:
isValidWhenLong in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenDirectory

public boolean isValidWhenDirectory(String argumentName,
                                    String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is a directory.

Specified by:
isValidWhenDirectory in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenDirectory

public boolean isValidWhenDirectory(String argumentName,
                                    File argumentValue)
Specified by:
isValidWhenDirectory in interface ArgumentValidation

isValidWhenFile

public boolean isValidWhenFile(String argumentName,
                               String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is a file.

Specified by:
isValidWhenFile in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenFile

public boolean isValidWhenFile(String argumentName,
                               File argumentValue)
Specified by:
isValidWhenFile in interface ArgumentValidation

isValidWhenUrl

public boolean isValidWhenUrl(String argumentName,
                              String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is an valid url.

Specified by:
isValidWhenUrl in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenUri

public boolean isValidWhenUri(String argumentName,
                              String argumentValue)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is an valid uri.

Specified by:
isValidWhenUri in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidWhenInSet

public boolean isValidWhenInSet(String argumentName,
                                String argumentValue,
                                Set<String> argumentSet)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is an element contained by the Set argumentSet.

Specified by:
isValidWhenInSet in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
argumentSet - The Set to validate against.
Returns:
true if the condition is met, otherwise false.

isValidWhenNotInSet

public boolean isValidWhenNotInSet(String argumentName,
                                   String argumentValue,
                                   Set<String> argumentSet)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue is not already contained by the Set argumentSet.

Specified by:
isValidWhenNotInSet in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
argumentSet - The Set to validate against.
Returns:
true if the condition is met, otherwise false.

isValidCollectionWhenNoNulls

public boolean isValidCollectionWhenNoNulls(String argumentName,
                                            Collection<?> argumentValue)
Description copied from interface: ArgumentValidation
Validates if the Collection argumentValue is not null and that its containing elements are also not null. Meaning the Collection may be empty. And when not empty, each entry should contain a instance.

Specified by:
isValidCollectionWhenNoNulls in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.

isValidCollectionWhenMinElements

public boolean isValidCollectionWhenMinElements(String argumentName,
                                                Collection<?> argumentValue,
                                                int minElements)
Description copied from interface: ArgumentValidation
Validates if the Collection argumentValue is at least containing the minimal number of elements (minElements).

Specified by:
isValidCollectionWhenMinElements in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
minElements - The minimal number of arguments, the collection should contain.
Returns:
true if the condition is met, otherwise false.

isValidWhenGreaterThen

public boolean isValidWhenGreaterThen(String argumentName,
                                      int argumentValue,
                                      int value)
Description copied from interface: ArgumentValidation
Validates if the Integer argumentValue is greate then Integer value.

Specified by:
isValidWhenGreaterThen in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
value - The value to validate against.
Returns:
true if the condition is met, otherwise false.

isValidStringMinLength

public boolean isValidStringMinLength(String argumentName,
                                      String argumentValue,
                                      int minLength)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue has a minimal length of minLength.

Specified by:
isValidStringMinLength in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
minLength - The length to validate against.
Returns:
true if the condition is met, otherwise false.

isValidStringMaxLength

public boolean isValidStringMaxLength(String argumentName,
                                      String argumentValue,
                                      int maxLength)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue has a maximum length of maxLength.

Specified by:
isValidStringMaxLength in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
maxLength - The length to validate against.
Returns:
true if the condition is met, otherwise false.

isValidStringLength

public boolean isValidStringLength(String argumentName,
                                   String argumentValue,
                                   int length)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue has an exact length of length.

Specified by:
isValidStringLength in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
length - The length to validate against.
Returns:
true if the condition is met, otherwise false.

isValidStringMinAndMaxLength

public boolean isValidStringMinAndMaxLength(String argumentName,
                                            String argumentValue,
                                            int minLength,
                                            int maxLength)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue has a minimal length of minLength and a maximum length of maxLength.

Specified by:
isValidStringMinAndMaxLength in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
minLength - The minimal length to validate against.
maxLength - The maximum length to validate against.
Returns:
true if the condition is met, otherwise false.

isValidMatchingDateFormat

public boolean isValidMatchingDateFormat(String argumentName,
                                         String argumentValue,
                                         DateFormat dateFormat)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue matches the dateFormat.

Specified by:
isValidMatchingDateFormat in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
dateFormat - The date format which is used for matching.
Returns:
true if the condition is met, otherwise false.

isValidMatchingDateFormat

public boolean isValidMatchingDateFormat(String argumentName,
                                         String argumentValue,
                                         String dateFormatName)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue matches the date format registered under the dateFormatName.

Specified by:
isValidMatchingDateFormat in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
Returns:
true if the condition is met, otherwise false.
See Also:
ArgumentValidation.isValidMatchingDateFormat(String, String, DateFormat)

isValidMatchingPattern

public boolean isValidMatchingPattern(String argumentName,
                                      String argumentValue,
                                      String patternName)
Description copied from interface: ArgumentValidation
Validates if the String argumentValue matches the pattern regisstered under the patternName.

Specified by:
isValidMatchingPattern in interface ArgumentValidation
Parameters:
argumentName - The name of the argument, which is validated.
argumentValue - The value of the argument, which is validated.
patternName - The name of the pattern, which is used for matching.
Returns:
true if the condition is met, otherwise false.

addError

public void addError(String error)
Description copied from interface: ArgumentValidation
Add an error message to the list of error messages. The list of error messages is used to create the IllegalArgumentException message.

Specified by:
addError in interface ArgumentValidation
Parameters:
error - The error message to add.
See Also:
ArgumentValidation.addError(String, String)

getPatternNames

public Set<String> getPatternNames()
Description copied from interface: ArgumentValidation
Returns the Set of pattern names.

Specified by:
getPatternNames in interface ArgumentValidation
Returns:
The names of all the patterns.

getPattern

public Map<String,String> getPattern()
Description copied from interface: ArgumentValidation
Returns the Map of pattern names and their regular expression.

Specified by:
getPattern in interface ArgumentValidation
Returns:
All pattern names and their regular expression (as String).

getPattern

public org.apache.oro.text.regex.Pattern getPattern(String patternName)
Description copied from interface: ArgumentValidation
Returns the Pattern found under the patternName, or throws an IllegalArgumentException if the patternName is not available.

Specified by:
getPattern in interface ArgumentValidation
Parameters:
patternName - The name of the pattern.
Returns:
The found Pattern.

getRegularExpression

public String getRegularExpression(String patternName)
Description copied from interface: ArgumentValidation
Returns the regular expression found under the patternName, or throws an IllegalArgumentException if the patternName is not available.

Specified by:
getRegularExpression in interface ArgumentValidation
Parameters:
patternName - The name of the pattern.
Returns:
The regular expression.

polish

public static String polish(String text)
Returns the incoming text, but stripes leading and trailing spaces and returns null when the (remaining) text is an empty String instance.

Parameters:
text - The text to polish.
Returns:
The text without leading and trailing spaces that remains or null, when no characters are left.

polishToLower

public static String polishToLower(String text)
Returns the incoming text polished (see polish(String) and converted into lower case.

Parameters:
text - The text to polish and convert.
Returns:
The polished and to lower case converted text.
See Also:
polish(String)

polishToUpper

public static String polishToUpper(String text)
Returns the incoming text polished (see polish(String) and converted into upper case.

Parameters:
text - The text to polish and convert.
Returns:
The polished and to upper case converted text.
See Also:
polish(String)

isValidNotNullForKey

public boolean isValidNotNullForKey(String argumentName,
                                    Map<String,String> argumentValueMap,
                                    String key)
Specified by:
isValidNotNullForKey in interface ArgumentValidation


Copyright © 2013 Verhagen Software. All Rights Reserved.