joptsimple.util
Class RegexMatcher

java.lang.Object
  extended by joptsimple.util.RegexMatcher
All Implemented Interfaces:
ValueConverter<String>

public class RegexMatcher
extends Object
implements ValueConverter<String>

Ensures that values entirely match a regular expression.

Version:
$Id: RegexMatcher.java,v 1.6 2009/10/25 18:37:09 pholser Exp $
Author:
Paul Holser

Constructor Summary
RegexMatcher(String pattern, int flags)
          Creates a matcher that uses the given regular expression, modified by the given flags.
 
Method Summary
 String convert(String value)
          Converts the given string value into a Java type.
static ValueConverter<String> regex(String pattern)
          Gives a matcher that uses the given regular expression.
 String valuePattern()
          Gives a string that describes the pattern of the values this converter expects, if any.
 Class<String> valueType()
          Gives the class of the type of values this converter converts to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexMatcher

public RegexMatcher(String pattern,
                    int flags)
Creates a matcher that uses the given regular expression, modified by the given flags.

Parameters:
pattern - the regular expression pattern
flags - modifying regex flags
Throws:
IllegalArgumentException - if bit values other than those corresponding to the defined match flags are set in flags
PatternSyntaxException - if the expression's syntax is invalid
Method Detail

regex

public static ValueConverter<String> regex(String pattern)
Gives a matcher that uses the given regular expression.

Parameters:
pattern - the regular expression pattern
Returns:
the new converter
Throws:
PatternSyntaxException - if the expression's syntax is invalid

convert

public String convert(String value)
Description copied from interface: ValueConverter
Converts the given string value into a Java type.

Specified by:
convert in interface ValueConverter<String>
Parameters:
value - the string to convert
Returns:
the converted value

valueType

public Class<String> valueType()
Description copied from interface: ValueConverter
Gives the class of the type of values this converter converts to.

Specified by:
valueType in interface ValueConverter<String>
Returns:
the target class for conversion

valuePattern

public String valuePattern()
Description copied from interface: ValueConverter
Gives a string that describes the pattern of the values this converter expects, if any. For example, a date converter can respond with a date format string.

Specified by:
valuePattern in interface ValueConverter<String>
Returns:
a value pattern, or null if there's nothing interesting here


Copyright © 2011. All Rights Reserved.