You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2006/01/22 04:25:12 UTC
svn commit: r371174 [2/3] - in /jakarta/commons/proper/validator/trunk: ./
src/share/org/apache/commons/validator/routines/
src/test/org/apache/commons/validator/routines/ xdocs/
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java Sat Jan 21 19:24:40 2006
@@ -20,6 +20,7 @@
*/
package org.apache.commons.validator.routines;
+import java.text.Format;
import java.util.Locale;
/**
@@ -30,9 +31,10 @@
* a <code>Float</code> using <code>java.text.NumberFormat</code>
* to parse either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* <p>Use one of the <code>isValid()</code> methods to just validate or
@@ -55,9 +57,10 @@
* <code>format()</code> methods are also provided. That is you can
* format either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* @version $Revision$ $Date$
@@ -79,17 +82,32 @@
* Construct a <i>strict</i> instance.
*/
public FloatValidator() {
- this(true);
+ this(true, STANDARD_FORMAT);
}
/**
- * Construct an instance with the specified strict setting.
+ * <p>Construct an instance with the specified strict setting
+ * and format type.</p>
+ *
+ * <p>The <code>formatType</code> specified what type of
+ * <code>NumberFormat</code> is created - valid types
+ * are:</p>
+ * <ul>
+ * <li>AbstractNumberValidator.STANDARD_FORMAT -to create
+ * <i>standard</i> number formats (the default).</li>
+ * <li>AbstractNumberValidator.CURRENCY_FORMAT -to create
+ * <i>currency</i> number formats.</li>
+ * <li>AbstractNumberValidator.PERCENT_FORMAT -to create
+ * <i>percent</i> number formats (the default).</li>
+ * </ul>
*
* @param strict <code>true</code> if strict
* <code>Format</code> parsing should be used.
+ * @param formatType The <code>NumberFormat</code> type to
+ * create for validation, default is STANDARD_FORMAT.
*/
- public FloatValidator(boolean strict) {
- super(strict, true);
+ public FloatValidator(boolean strict, int formatType) {
+ super(strict, formatType, true);
}
/**
@@ -101,7 +119,7 @@
* if invalid.
*/
public Float validate(String value) {
- return (Float)validateObj(value);
+ return (Float)parse(value, (String)null, (Locale)null);
}
/**
@@ -113,7 +131,7 @@
* @return The parsed <code>Float</code> if valid or <code>null</code> if invalid.
*/
public Float validate(String value, String pattern) {
- return (Float)validateObj(value, pattern);
+ return (Float)parse(value, pattern, (Locale)null);
}
/**
@@ -121,12 +139,25 @@
* specified <code>Locale</code>.
*
* @param value The value validation is being performed on.
- * @param locale The locale to use for the date format, defaults to the default
- * system default if null.
+ * @param locale The locale to use for the number format, system default if null.
* @return The parsed <code>Float</code> if valid or <code>null</code> if invalid.
*/
public Float validate(String value, Locale locale) {
- return (Float)validateObj(value, locale);
+ return (Float)parse(value, (String)null, locale);
+ }
+
+ /**
+ * <p>Validate/convert a <code>Float</code> using the
+ * specified pattern and/ or <code>Locale</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @param pattern The pattern used to validate the value against, or the
+ * default for the <code>Locale</code> if <code>null</code>.
+ * @param locale The locale to use for the date format, system default if null.
+ * @return The parsed <code>Float</code> if valid or <code>null</code> if invalid.
+ */
+ public Float validate(String value, String pattern, Locale locale) {
+ return (Float)parse(value, pattern, locale);
}
/**
@@ -207,13 +238,14 @@
* <p>Perform further validation and convert the <code>Number</code> to
* a <code>Float</code>.</p>
*
- * @param number The number validation is being performed on.
- * @return The validated/converted <code>Float</code> value if valid
- * or <code>null</code> if invalid.
+ * @param value The parsed <code>Number</code> object created.
+ * @param formatter The Format used to parse the value with.
+ * @return The parsed <code>Number</code> converted to a
+ * <code>Float</code> if valid or <code>null</code> if invalid.
*/
- protected Object processNumber(Number number) {
+ protected Object processParsedValue(Object value, Format formatter) {
- double doubleValue = number.doubleValue();
+ double doubleValue = ((Number)value).doubleValue();
if (doubleValue > 0) {
if (doubleValue < Float.MIN_VALUE) {
@@ -232,7 +264,7 @@
}
}
- return new Float(number.floatValue());
+ return new Float((float)doubleValue);
}
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java Sat Jan 21 19:24:40 2006
@@ -20,6 +20,7 @@
*/
package org.apache.commons.validator.routines;
+import java.text.Format;
import java.util.Locale;
/**
@@ -30,9 +31,10 @@
* a <code>Integer</code> using <code>java.text.NumberFormat</code>
* to parse either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* <p>Use one of the <code>isValid()</code> methods to just validate or
@@ -55,9 +57,10 @@
* <code>format()</code> methods are also provided. That is you can
* format either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* @version $Revision$ $Date$
@@ -79,17 +82,32 @@
* Construct a <i>strict</i> instance.
*/
public IntegerValidator() {
- this(true);
+ this(true, STANDARD_FORMAT);
}
/**
- * Construct an instance with the specified strict setting.
+ * <p>Construct an instance with the specified strict setting
+ * and format type.</p>
+ *
+ * <p>The <code>formatType</code> specified what type of
+ * <code>NumberFormat</code> is created - valid types
+ * are:</p>
+ * <ul>
+ * <li>AbstractNumberValidator.STANDARD_FORMAT -to create
+ * <i>standard</i> number formats (the default).</li>
+ * <li>AbstractNumberValidator.CURRENCY_FORMAT -to create
+ * <i>currency</i> number formats.</li>
+ * <li>AbstractNumberValidator.PERCENT_FORMAT -to create
+ * <i>percent</i> number formats (the default).</li>
+ * </ul>
*
* @param strict <code>true</code> if strict
* <code>Format</code> parsing should be used.
+ * @param formatType The <code>NumberFormat</code> type to
+ * create for validation, default is STANDARD_FORMAT.
*/
- public IntegerValidator(boolean strict) {
- super(strict, false);
+ public IntegerValidator(boolean strict, int formatType) {
+ super(strict, formatType, false);
}
/**
@@ -101,7 +119,7 @@
* if invalid.
*/
public Integer validate(String value) {
- return (Integer)validateObj(value);
+ return (Integer)parse(value, (String)null, (Locale)null);
}
/**
@@ -113,7 +131,7 @@
* @return The parsed <code>Integer</code> if valid or <code>null</code> if invalid.
*/
public Integer validate(String value, String pattern) {
- return (Integer)validateObj(value, pattern);
+ return (Integer)parse(value, pattern, (Locale)null);
}
/**
@@ -121,12 +139,25 @@
* specified <code>Locale</code>.
*
* @param value The value validation is being performed on.
- * @param locale The locale to use for the date format, defaults to the default
- * system default if null.
+ * @param locale The locale to use for the number format, system default if null.
* @return The parsed <code>Integer</code> if valid or <code>null</code> if invalid.
*/
public Integer validate(String value, Locale locale) {
- return (Integer)validateObj(value, locale);
+ return (Integer)parse(value, (String)null, locale);
+ }
+
+ /**
+ * <p>Validate/convert a <code>Integer</code> using the
+ * specified pattern and/ or <code>Locale</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @param pattern The pattern used to validate the value against, or the
+ * default for the <code>Locale</code> if <code>null</code>.
+ * @param locale The locale to use for the date format, system default if null.
+ * @return The parsed <code>Integer</code> if valid or <code>null</code> if invalid.
+ */
+ public Integer validate(String value, String pattern, Locale locale) {
+ return (Integer)parse(value, pattern, locale);
}
/**
@@ -207,23 +238,20 @@
* <p>Perform further validation and convert the <code>Number</code> to
* an <code>Integer</code>.</p>
*
- * @param number The number validation is being performed on.
- * @return The validated/converted <code>Integer</code> value if valid
- * or <code>null</code> if invalid.
+ * @param value The parsed <code>Number</code> object created.
+ * @param formatter The Format used to parse the value with.
+ * @return The parsed <code>Number</code> converted to an
+ * <code>Integer</code> if valid or <code>null</code> if invalid.
*/
- protected Object processNumber(Number number) {
-
- long longValue = number.longValue();
+ protected Object processParsedValue(Object value, Format formatter) {
- if (longValue < Integer.MIN_VALUE) {
- return null;
- }
+ long longValue = ((Number)value).longValue();
- if (longValue > Integer.MAX_VALUE) {
+ if (longValue < Integer.MIN_VALUE ||
+ longValue > Integer.MAX_VALUE) {
return null;
+ } else {
+ return new Integer((int)longValue);
}
-
- return new Integer(number.intValue());
-
}
}
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java Sat Jan 21 19:24:40 2006
@@ -20,6 +20,7 @@
*/
package org.apache.commons.validator.routines;
+import java.text.Format;
import java.util.Locale;
/**
@@ -30,9 +31,10 @@
* a <code>Long</code> using <code>java.text.NumberFormat</code>
* to parse either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* <p>Use one of the <code>isValid()</code> methods to just validate or
@@ -79,17 +81,32 @@
* Construct a <i>strict</i> instance.
*/
public LongValidator() {
- this(true);
+ this(true, STANDARD_FORMAT);
}
/**
- * Construct an instance with the specified strict setting.
+ * <p>Construct an instance with the specified strict setting
+ * and format type.</p>
+ *
+ * <p>The <code>formatType</code> specified what type of
+ * <code>NumberFormat</code> is created - valid types
+ * are:</p>
+ * <ul>
+ * <li>AbstractNumberValidator.STANDARD_FORMAT -to create
+ * <i>standard</i> number formats (the default).</li>
+ * <li>AbstractNumberValidator.CURRENCY_FORMAT -to create
+ * <i>currency</i> number formats.</li>
+ * <li>AbstractNumberValidator.PERCENT_FORMAT -to create
+ * <i>percent</i> number formats (the default).</li>
+ * </ul>
*
* @param strict <code>true</code> if strict
* <code>Format</code> parsing should be used.
+ * @param formatType The <code>NumberFormat</code> type to
+ * create for validation, default is STANDARD_FORMAT.
*/
- public LongValidator(boolean strict) {
- super(strict, false);
+ public LongValidator(boolean strict, int formatType) {
+ super(strict, formatType, false);
}
/**
@@ -101,7 +118,7 @@
* if invalid.
*/
public Long validate(String value) {
- return (Long)validateObj(value);
+ return (Long)parse(value, (String)null, (Locale)null);
}
/**
@@ -113,7 +130,7 @@
* @return The parsed <code>Long</code> if valid or <code>null</code> if invalid.
*/
public Long validate(String value, String pattern) {
- return (Long)validateObj(value, pattern);
+ return (Long)parse(value, pattern, (Locale)null);
}
/**
@@ -121,12 +138,25 @@
* specified <code>Locale</code>.
*
* @param value The value validation is being performed on.
- * @param locale The locale to use for the date format, defaults to the default
- * system default if null.
+ * @param locale The locale to use for the number format, system default if null.
* @return The parsed <code>Long</code> if valid or <code>null</code> if invalid.
*/
public Long validate(String value, Locale locale) {
- return (Long)validateObj(value, locale);
+ return (Long)parse(value, (String)null, locale);
+ }
+
+ /**
+ * <p>Validate/convert a <code>Long</code> using the
+ * specified pattern and/ or <code>Locale</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @param pattern The pattern used to validate the value against, or the
+ * default for the <code>Locale</code> if <code>null</code>.
+ * @param locale The locale to use for the date format, system default if null.
+ * @return The parsed <code>Long</code> if valid or <code>null</code> if invalid.
+ */
+ public Long validate(String value, String pattern, Locale locale) {
+ return (Long)parse(value, pattern, locale);
}
/**
@@ -204,19 +234,19 @@
}
/**
- * <p>Perform further validation and convert the <code>Number</code> to
- * an <code>Long</code>.</p>
+ * Convert the parsed value to a <code>Long</code>.
*
- * @param number The number validation is being performed on.
- * @return The validated/converted <code>Long</code> value if valid
- * or <code>null</code> if invalid.
+ * @param value The parsed <code>Number</code> object created.
+ * @param formatter The Format used to parse the value with.
+ * @return The parsed <code>Number</code> converted to a
+ * <code>Long</code>.
*/
- protected Object processNumber(Number number) {
+ protected Object processParsedValue(Object value, Format formatter) {
- if (number instanceof Long) {
- return number;
+ if (value instanceof Long) {
+ return value;
} else {
- return new Long(number.longValue());
+ return new Long(((Number)value).longValue());
}
}
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java Sat Jan 21 19:24:40 2006
@@ -20,19 +20,31 @@
*/
package org.apache.commons.validator.routines;
+import java.text.DecimalFormat;
import java.text.Format;
-import java.text.NumberFormat;
-import java.util.Locale;
+import java.math.BigDecimal;
/**
* <p><b>Percentage Validation</b> and Conversion routines (<code>java.math.BigDecimal</code>).</p>
*
- * <p>This validator is a variation of the <code>BigDecimal</code> Validator
- * that uses the <i>percentage</code> format when validating using
- * a <code>Locale</i>.</p>
+ * <p>This is one implementation of a percent validator that has the following features:</p>
+ * <ul>
+ * <li>It is <i>lenient</i> about the the presence of the <i>percent symbol</i></li>
+ * <li>It converts the percent to a <code>java.math.BigDecimal</code></li>
+ * </ul>
*
- * <p>Otherwise it provides the same functionality as the <code>BigDecimal</code>
- * with converted values being returned as a <code>BigDecimal</code>.</p>
+ * <p>However any of the <i>number</i> validators can be used for <i>percent</i> validation.
+ * For example, if you wanted a <i>percent</i> validator that converts to a
+ * <code>java.lang.Float</code> then you can simply instantiate an
+ * <code>FloatValidator</code> with the appropriate <i>format type</i>:</p>
+ *
+ * <p><code>... = new FloatValidator(false, FloatValidator.PERCENT_FORMAT);</code></p>
+ *
+ * <p>Pick the appropriate validator, depending on the type (i.e Float, Double or BigDecimal)
+ * you want the percent converted to. Please note, it makes no sense to use
+ * one of the validators that doesn't handle fractions (i.e. byte, short, integer, long
+ * and BigInteger) since percentages are converted to fractions (i.e <code>50%</code> is
+ * converted to <code>0.5</code>).</p>
*
* @version $Revision$ $Date$
* @since Validator 1.2.1
@@ -41,11 +53,16 @@
private static final PercentValidator VALIDATOR = new PercentValidator();
+ /** DecimalFormat's percent (thousand multiplier) symbol */
+ private static final char PERCENT_SYMBOL = '%';
+
+ private static final BigDecimal POINT_ZERO_ONE = new BigDecimal("0.01");
+
/**
* Return a singleton instance of this validator.
* @return A singleton instance of the PercentValidator.
*/
- public static BigDecimalValidator getPercentInstance() {
+ public static BigDecimalValidator getInstance() {
return VALIDATOR;
}
@@ -63,22 +80,49 @@
* <code>Format</code> parsing should be used.
*/
public PercentValidator(boolean strict) {
- super(strict);
+ super(strict, PERCENT_FORMAT, true);
}
/**
- * <p>Returns a percentage <code>NumberFormat</code> for the specified Locale.</p>
+ * <p>Parse the value with the specified <code>Format</code>.</p>
*
- * @param locale The locale a percentage <code>NumberFormat</code> is required
- * for, defaults to the default.
- * @return The percentage <code>NumberFormat</code> to created.
+ * <p>This implementation is lenient whether the currency symbol
+ * is present or not. The default <code>NumberFormat</code>
+ * behaviour is for the parsing to "fail" if the currency
+ * symbol is missing. This method re-parses with a format
+ * without the currency symbol if it fails initially.</p>
+ *
+ * @param value The value to be parsed.
+ * @param formatter The Format to parse the value with.
+ * @return The parsed value if valid or <code>null</code> if invalid.
*/
- public Format getFormat(Locale locale) {
+ protected Object parse(String value, Format formatter) {
- if (locale == null) {
- locale = Locale.getDefault();
+ // Initial parse of the value
+ BigDecimal parsedValue = (BigDecimal)super.parse(value, formatter);
+ if (parsedValue != null || !(formatter instanceof DecimalFormat)) {
+ return parsedValue;
}
- return NumberFormat.getPercentInstance(locale);
+ // Re-parse using a pattern without the percent symbol
+ DecimalFormat decimalFormat = (DecimalFormat)formatter;
+ String pattern = decimalFormat.toPattern();
+ if (pattern.indexOf(PERCENT_SYMBOL) >= 0) {
+ StringBuffer buffer = new StringBuffer(pattern.length());
+ for (int i = 0; i < pattern.length(); i++) {
+ if (pattern.charAt(i) != PERCENT_SYMBOL) {
+ buffer.append(pattern.charAt(i));
+ }
+ }
+ decimalFormat.applyPattern(buffer.toString());
+ parsedValue = (BigDecimal)super.parse(value, decimalFormat);
+
+ // If parsed OK, divide by 100 to get percent
+ if (parsedValue != null) {
+ parsedValue = parsedValue.multiply(POINT_ZERO_ONE);
+ }
+
+ }
+ return parsedValue;
}
}
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java Sat Jan 21 19:24:40 2006
@@ -20,6 +20,7 @@
*/
package org.apache.commons.validator.routines;
+import java.text.Format;
import java.util.Locale;
/**
@@ -30,9 +31,10 @@
* a <code>Short</code> using <code>java.text.NumberFormat</code>
* to parse either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* <p>Use one of the <code>isValid()</code> methods to just validate or
@@ -55,9 +57,10 @@
* <code>format()</code> methods are also provided. That is you can
* format either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
* @version $Revision$ $Date$
@@ -79,17 +82,32 @@
* Construct a <i>strict</i> instance.
*/
public ShortValidator() {
- this(true);
+ this(true, STANDARD_FORMAT);
}
/**
- * Construct an instance with the specified strict setting.
+ * <p>Construct an instance with the specified strict setting
+ * and format type.</p>
+ *
+ * <p>The <code>formatType</code> specified what type of
+ * <code>NumberFormat</code> is created - valid types
+ * are:</p>
+ * <ul>
+ * <li>AbstractNumberValidator.STANDARD_FORMAT -to create
+ * <i>standard</i> number formats (the default).</li>
+ * <li>AbstractNumberValidator.CURRENCY_FORMAT -to create
+ * <i>currency</i> number formats.</li>
+ * <li>AbstractNumberValidator.PERCENT_FORMAT -to create
+ * <i>percent</i> number formats (the default).</li>
+ * </ul>
*
* @param strict <code>true</code> if strict
* <code>Format</code> parsing should be used.
+ * @param formatType The <code>NumberFormat</code> type to
+ * create for validation, default is STANDARD_FORMAT.
*/
- public ShortValidator(boolean strict) {
- super(strict, false);
+ public ShortValidator(boolean strict, int formatType) {
+ super(strict, formatType, false);
}
/**
@@ -101,7 +119,7 @@
* if invalid.
*/
public Short validate(String value) {
- return (Short)validateObj(value);
+ return (Short)parse(value, (String)null, (Locale)null);
}
/**
@@ -113,7 +131,7 @@
* @return The parsed <code>Short</code> if valid or <code>null</code> if invalid.
*/
public Short validate(String value, String pattern) {
- return (Short)validateObj(value, pattern);
+ return (Short)parse(value, pattern, (Locale)null);
}
/**
@@ -121,12 +139,25 @@
* specified <code>Locale</code>.
*
* @param value The value validation is being performed on.
- * @param locale The locale to use for the date format, defaults to the default
- * system default if null.
+ * @param locale The locale to use for the number format, system default if null.
* @return The parsed <code>Short</code> if valid or <code>null</code> if invalid.
*/
public Short validate(String value, Locale locale) {
- return (Short)validateObj(value, locale);
+ return (Short)parse(value, (String)null, locale);
+ }
+
+ /**
+ * <p>Validate/convert a <code>Short</code> using the
+ * specified pattern and/ or <code>Locale</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @param pattern The pattern used to validate the value against, or the
+ * default for the <code>Locale</code> if <code>null</code>.
+ * @param locale The locale to use for the date format, system default if null.
+ * @return The parsed <code>Short</code> if valid or <code>null</code> if invalid.
+ */
+ public Short validate(String value, String pattern, Locale locale) {
+ return (Short)parse(value, pattern, locale);
}
/**
@@ -207,23 +238,20 @@
* <p>Perform further validation and convert the <code>Number</code> to
* a <code>Short</code>.</p>
*
- * @param number The number validation is being performed on.
- * @return The validated/converted <code>Short</code> value if valid
- * or <code>null</code> if invalid.
+ * @param value The parsed <code>Number</code> object created.
+ * @param formatter The Format used to parse the value with.
+ * @return The parsed <code>Number</code> converted to a
+ * <code>Short</code> if valid or <code>null</code> if invalid.
*/
- protected Object processNumber(Number number) {
-
- long longValue = number.longValue();
+ protected Object processParsedValue(Object value, Format formatter) {
- if (longValue < Short.MIN_VALUE) {
- return null;
- }
+ long longValue = ((Number)value).longValue();
- if (longValue > Short.MAX_VALUE) {
+ if (longValue < Short.MIN_VALUE ||
+ longValue > Short.MAX_VALUE) {
return null;
+ } else {
+ return new Short((short)longValue);
}
-
- return new Short(number.shortValue());
-
}
}
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java Sat Jan 21 19:24:40 2006
@@ -22,6 +22,7 @@
package org.apache.commons.validator.routines;
import java.text.DateFormat;
+import java.text.Format;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
@@ -29,16 +30,21 @@
/**
* <p><b>Time Validation</b> and Conversion routines (<code>java.util.Calendar</code>).</p>
*
- * <p>This validator provides a number of methods for
- * validating/converting a <code>String</code> value to
- * a Time using <code>java.text.DateFormat</code>
- * to parse either:</p>
+ * <p>This validator provides a number of methods for validating/converting
+ * a <code>String</code> time value to a <code>java.util.Calendar</code> using
+ * <code>java.text.DateFormat</code> to parse either:</p>
* <ul>
- * <li>using a specified pattern</li>
- * <li>using the format for a specified <code>Locale</code></li>
- * <li>using the format for the <i>default</i> <code>Locale</code></li>
+ * <li>using the default format for the default <code>Locale</code></li>
+ * <li>using a specified pattern with the default <code>Locale</code></li>
+ * <li>using the default format for a specified <code>Locale</code></li>
+ * <li>using a specified pattern with a specified <code>Locale</code></li>
* </ul>
*
+ * <p>For each of the above mechanisms, conversion method (i.e the
+ * <code>validate</code> methods) implementations are provided which
+ * either use the default <code>TimeZone</code> or allow the
+ * <code>TimeZone</code> to be specified.</p>
+ *
* <p>Use one of the <code>isValid()</code> methods to just validate or
* one of the <code>validate()</code> methods to validate and receive a
* <i>converted</i> <code>Calendar</code> value for the time.</p>
@@ -52,7 +58,7 @@
* object afterwards.</p>
*
* <p>Once a value has been sucessfully converted the following
- * methods can be used to perform various date comparison checks:</p>
+ * methods can be used to perform various time comparison checks:</p>
* <ul>
* <li><code>compareTime()</code> compares the hours, minutes, seconds
* and milliseconds of two calendars, returing 0, -1 or +1 indicating
@@ -114,77 +120,106 @@
}
/**
- * <p>Validate/convert a time using the default
- * <code>Locale</code> and <code>TimeZone</code>.
+ * <p>Validate/convert a time using the default <code>Locale</code>
+ * and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @return The parsed <code>Calendar</code> if valid or <code>null</code>
* if invalid.
*/
public Calendar validate(String value) {
- return (Calendar)validateObj(value);
+ return (Calendar)parse(value, (String)null, (Locale)null, (TimeZone)null);
}
/**
- * <p>Validate/convert a time using the specified
- * <code>TimeZone</code> and default <code>Locale</code>.
+ * <p>Validate/convert a time using the specified <code>TimeZone</code>
+ * and default <code>Locale</code>.
*
* @param value The value validation is being performed on.
- * @param timeZone The Time Zone used to parse the date, system default if null.
+ * @param timeZone The Time Zone used to parse the time, system default if null.
* @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
*/
public Calendar validate(String value, TimeZone timeZone) {
- return (Calendar)validateObj(value, Locale.getDefault(), timeZone);
+ return (Calendar)parse(value, (String)null, (Locale)null, timeZone);
}
/**
- * <p>Validate/convert a time using the specified
- * <i>pattern</i> and default <code>TimeZone</code>.
+ * <p>Validate/convert a time using the specified <i>pattern</i> and
+ * default <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against.
* @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
*/
public Calendar validate(String value, String pattern) {
- return (Calendar)validateObj(value, pattern);
+ return (Calendar)parse(value, pattern, (Locale)null, (TimeZone)null);
}
/**
- * <p>Validate/convert a time using the specified
- * <i>pattern</i> and <code>TimeZone</code>.
+ * <p>Validate/convert a time using the specified <i>pattern</i>
+ * and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against.
- * @param timeZone The Time Zone used to parse the date, system default if null.
+ * @param timeZone The Time Zone used to parse the time, system default if null.
* @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
*/
public Calendar validate(String value, String pattern, TimeZone timeZone) {
- return (Calendar)validateObj(value, pattern, timeZone);
+ return (Calendar)parse(value, pattern, (Locale)null, timeZone);
}
/**
- * <p>Validate/convert a time using the specified
- * <code>Locale</code> and <code>TimeZone</code>.
+ * <p>Validate/convert a time using the specified <code>Locale</code>
+ * default <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
- * @param locale The locale to use for the date format, system default if null.
+ * @param locale The locale to use for the time format, system default if null.
* @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
*/
public Calendar validate(String value, Locale locale) {
- return (Calendar)validateObj(value, locale);
+ return (Calendar)parse(value, (String)null, locale, (TimeZone)null);
}
/**
- * Checks if the value is a valid time for a
- * specified <code>Locale</code>.
+ * <p>Validate/convert a time using the specified specified <code>Locale</code>
+ * and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
+ * @param locale The locale to use for the time format, system default if null.
+ * @param timeZone The Time Zone used to parse the time, system default if null.
+ * @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
+ */
+ public Calendar validate(String value, Locale locale, TimeZone timeZone) {
+ return (Calendar)parse(value, (String)null, locale, timeZone);
+ }
+
+ /**
+ * <p>Validate/convert a time using the specified pattern and <code>Locale</code>
+ * and the default <code>TimeZone</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @param pattern The pattern used to validate the value against, or the
+ * default for the <code>Locale</code> if <code>null</code>.
+ * @param locale The locale to use for the date format, system default if null.
+ * @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
+ */
+ public Calendar validate(String value, String pattern, Locale locale) {
+ return (Calendar)parse(value, pattern, locale, (TimeZone)null);
+ }
+
+ /**
+ * <p>Validate/convert a time using the specified pattern, <code>Locale</code>
+ * and <code>TimeZone</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @param pattern The pattern used to validate the value against, or the
+ * default for the <code>Locale</code> if <code>null</code>.
* @param locale The locale to use for the date format, system default if null.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
*/
- public Calendar validate(String value, Locale locale, TimeZone timeZone) {
- return (Calendar)validateObj(value, locale, timeZone);
+ public Calendar validate(String value, String pattern, Locale locale, TimeZone timeZone) {
+ return (Calendar)parse(value, pattern, locale, timeZone);
}
/**
@@ -240,17 +275,13 @@
}
/**
- * <p>Perform further validation and convert the <code>Calendar</code> to
- * the appropriate type.</p>
- *
- * <p>This implementation returns the <code>Calendar</code> object
- * unchanged</p>
+ * <p>Convert the parsed <code>Date</code> to a <code>Calendar</code>.</p>
*
- * @param calendar The calendar object create from the parsed value.
- * @return The validated/converted <code>Calendar</code> value if valid
- * or <code>null</code> if invalid.
+ * @param value The parsed <code>Date</code> object created.
+ * @param formatter The Format used to parse the value with.
+ * @return The parsed value converted to a <code>Calendar</code>.
*/
- protected Object processCalendar(Calendar calendar) {
- return calendar;
+ protected Object processParsedValue(Object value, Format formatter) {
+ return ((DateFormat)formatter).getCalendar();
}
}
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html Sat Jan 21 19:24:40 2006
@@ -4,77 +4,273 @@
</head>
<body bgcolor="white">
<p>This package contains <i>independant</i> validation routines.</p>
- <h1>Purpose</h1>
- <p>
- Commons Validator serves two purposes:
- </p>
- <ul>
- <li>To provide standard, independant validation routines/functions.</li>
- <li>To provide a <i>mini</i> framework for Validation.</li>
- </ul>
- <p>
- This package has been created, since version 1.2.1, in an attempt to clearly
- separate these two concerns and is the location for the standard, independant
- validation routines/functions in <em>Commons Validator</em>.
- </p>
-
- <p>
- The contents of this package have no dependencies on the framework aspect of
- Commons Validator and can be used on their own.
- </p>
-
- <h1>Date and Time Validators</h1>
- <p>
- The date and time validators either validate according to a specified <i>format</i>
- or use a standard <i>format</i> for a specified <code>Locale</code>.
- </p>
- <ul>
- <li><a href="DateValidator.html">Date Validator</a> - validates dates
- converting to a <code>java.util.Date</code> type. Also provides functions
- to compare dates.</li>
- <li><a href="CalendarValidator.html">Calendar Validator</a> - validates dates
- converting to a <code>java.util.Calendar</code> type. Also provides functions
- to compare dates.</li>
- <li><a href="TimeValidator.html">Time Validator</a> - validates times
- converting to a <code>java.util.Calendar</code> type. Also provides functions
- to compare times.</li>
- </ul>
- <h1>Numeric Validators</h1>
- <p>
- The numeric validators either validate according to a specified <i>format</i>
- or use a standard <i>format</i> for a specified <code>Locale</code>.
- </p>
- <ul>
- <li><a href="ByteValidator.html">Byte Validator</a> - validates numbers
- converting to a <code>java.lang.Byte</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="ShortValidator.html">Short Validator</a> - validates numbers
- converting to a <code>java.lang.Short</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="IntegerValidator.html">Integer Validator</a> - validates numbers
- converting to a <code>java.lang.Integer</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="LongValidator.html">Long Validator</a> - validates numbers
- converting to a <code>java.lang.Long</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="FloatValidator.html">Float Validator</a> - validates numbers
- converting to a <code>java.lang.Float</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="DoubleValidator.html">Double Validator</a> - validates numbers
- converting to a <code>java.lang.Integer</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="BigIntegerValidator.html">BigInteger Validator</a> - validates numbers
- converting to a <code>java.math.BigInteger</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="BigDecimalValidator.html">BigDecimal Validator</a> - validates numbers
- converting to a <code>java.math.BigDecimal</code> type. Also provides functions
- for minimum, maximum and range checks.</li>
- <li><a href="CurrencyValidator.html">Currency Validator</a> - validates numbers
- in using the <i>currency</i> format for a specified <code>Locale</code>.
- Validated values are converted to a <code>java.math.BigDecimal</code> type.</li>
- <li><a href="PercentValidator.html">Percent Validator</a> - validates numbers
- in using the <i>percentage</i> format for a specified <code>Locale</code>.
- Validated values are converted to a <code>java.math.BigDecimal</code> type.</li>
- </ul>
+<h1>Table of Contents</h1>
+
+<ul>
+<li>1. <a href="#overview">Overview</a>
+<li>2. <a href="#date">Date and Time Validators</a>
+ <ul>
+ <li>2.1 <a href="#date.overview">Overview</a></li>
+ <li>2.2 <a href="#date.validate">Validating a Date Value</a></li>
+ <li>2.3 <a href="#date.format">Formatting</a></li>
+ <li>2.4 <a href="#date.timezone">Time Zones</a></li>
+ <li>2.5 <a href="#date.compare">Comparing Dates and Times</a></li>
+ </ul></li>
+<li>2. <a href="#numeric">Numeric Validators</a>
+ <ul>
+ <li>3.1 <a href="#numeric.overview">Overview</a></li>
+ <li>3.2 <a href="#numeric.validate">Validating a Numeric Value</a></li>
+ <li>3.3 <a href="#numeric.format">Formatting</a></li>
+ <li>3.4 <a href="#numeric.compare">Comparing Numbers</a></li>
+ </ul></li>
+</ul>
+
+<a name="overview"></a>
+<h1>1. Overview</h1>
+<p>
+ Commons Validator serves two purposes:
+</p>
+ <ul>
+ <li>To provide standard, independant validation routines/functions.</li>
+ <li>To provide a <i>mini</i> framework for Validation.</li>
+ </ul>
+<p>
+ This package has been created, since version 1.2.1, in an attempt to clearly
+ separate these two concerns and is the location for the standard, independant
+ validation routines/functions in <em>Commons Validator</em>.
+</p>
+
+<p>
+ The contents of this package have no dependencies on the framework aspect of
+ Commons Validator and can be used on their own.
+</p>
+
+<a name="date"></a>
+<h1>2. Date and Time Validators</h1>
+
+<a name="date.overview"></a>
+<h3>2.1 Overview</h3>
+<p>
+ The date and time validators either validate according to a specified <i>format</i>
+ or use a standard <i>format</i> for a specified <code>Locale</code>.
+</p>
+<ul>
+ <li><a href="DateValidator.html">Date Validator</a> - validates dates
+ converting to a <code>java.util.Date</code> type.</li>
+ <li><a href="CalendarValidator.html">Calendar Validator</a> - validates dates
+ converting to a <code>java.util.Calendar</code> type.</li>
+ <li><a href="TimeValidator.html">Time Validator</a> - validates times
+ converting to a <code>java.util.Calendar</code> type.</li>
+</ul>
+
+<a name="date.validate"></a>
+<h3>2.2 Validating a Date Value</h3>
+<p>
+ You can either use one of the <code>isValid()</code> methods to just determine
+ if a date is valid, or use one of the <code>validate()</code> methods to
+ validate a date and convert it to a <code>java.util.Date</code>...
+</p>
+<pre>
+ // Get the Date validator
+ DateValidator validator = DateValidator.getInstance();
+
+ // Validate/Convert the date
+ Date fooDate = validator.validate(fooString, "dd/MM/yyyy");
+ if (fooDate == null) {
+ // error...not a valid date
+ return;
+ }
+</pre>
+
+<p>The following methods are provided to validate a date/time (return a boolean result):
+</p>
+<ul>
+ <li><code>isValid(<i>value</i>)</code></li>
+ <li><code>isValid(<i>value</i>, <i>pattern</i>)</code></li>
+ <li><code>isValid(<i>value</i>, Locale)</code></li>
+ <li><code>isValid(<i>value</i>, <i>pattern</i>, Locale)</code></li>
+</ul>
+<p>The following methods are provided to validate a date/time and convert it to either a
+ <code>java.util.Date</code> or <code>java.util.Calendar</code>:
+</p>
+<ul>
+ <li><code>validate(<i>value</i>)</code></li>
+ <li><code>validate(<i>value</i>, <i>pattern</i>)</code></li>
+ <li><code>validate(<i>value</i>, Locale)</code></li>
+ <li><code>validate(<i>value</i>, <i>pattern</i>, Locale)</code></li>
+</ul>
+
+<a name="date.format"></a>
+<h3>2.3 Formatting</h3>
+<p>
+ Formatting and validating are two sides of the same coin. Typically
+ <i>input</i> values which are converted from Strings according to a
+ specified <i>format</i> also have to be rendered for <i>output</i> in
+ the same format. These validators provide the mechanism for formatting from
+ date/time objects to Strings. The following methods are provided to format
+ date/time values as Strings:
+</p>
+<ul>
+ <li><code>format(<i>number</i>)</code></li>
+ <li><code>format(<i>number</i>, <i>pattern</i>)</code></li>
+ <li><code>format(<i>number</i>, Locale)</code></li>
+ <li><code>format(<i>number</i>, <i>pattern</i>, Locale)</code></li>
+</ul>
+
+<a name="date.timezone"></a>
+<h3>2.4 Time Zones</h3>
+<p>
+ If the date being parsed relates to a different time zone than the
+ system default, you can specify the <code>TimeZone</code> to use when
+ validating/converting:
+</p>
+<pre>
+ // Get the GMT time zone
+ TimeZone GMT = TimeZone.getInstance("GMT");
+
+ // Validate/Convert the date using GMT
+ Date fooDate = validator.validate(fooString, "dd/MM/yyyy", GMT);
+</pre>
+
+<p>The followng Time Zone <i>flavours</i> of the Validation/Conversion methods
+ are provided:</p>
+<ul>
+ <li><code>validate(<i>value</i>, TimeZone)</code></li>
+ <li><code>validate(<i>value</i>, <i>pattern</i>, TimeZone)</code></li>
+ <li><code>validate(<i>value</i>, Locale, TimeZone)</code></li>
+ <li><code>validate(<i>value</i>, <i>pattern</i>, Locale, TimeZone)</code></li>
+</ul>
+
+<a name="date.compare"></a>
+<h3>2.5 Comparing Dates and Times</h3>
+<p>
+ As well as validating that a value is a valid date or time, these validators
+ also provide <i>date comparison</i> functions. The <code>DateValidator</code>
+ and <code>CalendarValidator</code> provide functions for comparing years,
+ quarters, months, weeks and dates and the <code>TimeValidator</code> provides
+ functions for comparing hours, minutes, seconds and milliseconds.
+ For example, to check that a date is in the current month, you could use
+ the <code>compareMonths()</code> method, which compares the year and month
+ components of a date:
+</p>
+<pre>
+ // Check the date is in the current month
+ int compare = validator.compareMonths{fooDate, new Date(), null);
+ if (compare != 0) {
+ // error...not in current month
+ return;
+ }
+</pre>
+
+
+<a name="numeric"></a>
+<h1>3 Numeric Validators</h1>
+
+<a name="numeric.overview"></a>
+<h3>3.1 Overview</h3>
+<p>
+ The numeric validators either validate according to a specified <i>format</i>
+ or use a standard <i>format</i> for a specified <code>Locale</code> or use
+ a <i>custom</i> format for a specified <code>Locale</code>.
+</p>
+<ul>
+ <li><a href="ByteValidator.html">Byte Validator</a> - validates numbers
+ converting to a <code>java.lang.Byte</code> type.</li>
+ <li><a href="ShortValidator.html">Short Validator</a> - validates numbers
+ converting to a <code>java.lang.Short</code> type.</li>
+ <li><a href="IntegerValidator.html">Integer Validator</a> - validates numbers
+ converting to a <code>java.lang.Integer</code> type.</li>
+ <li><a href="LongValidator.html">Long Validator</a> - validates numbers
+ converting to a <code>java.lang.Long</code> type.</li>
+ <li><a href="FloatValidator.html">Float Validator</a> - validates numbers
+ converting to a <code>java.lang.Float</code> type.</li>
+ <li><a href="DoubleValidator.html">Double Validator</a> - validates numbers
+ converting to a <code>java.lang.Double</code> type.</li>
+ <li><a href="BigIntegerValidator.html">BigInteger Validator</a> - validates numbers
+ converting to a <code>java.math.BigInteger</code> type.</li>
+ <li><a href="BigDecimalValidator.html">BigDecimal Validator</a> - validates numbers
+ converting to a <code>java.math.BigDecimal</code> type.</li>
+ <li><a href="CurrencyValidator.html">Currency Validator</a> - validates numbers
+ in a <i>currency</i> format, converting to a <code>java.math.BigDecimal</code>
+ type.</li>
+ <li><a href="PercentValidator.html">Percent Validator</a> - validates numbers in
+ a <i>percentage</i> format converting to a <code>java.math.BigDecimal</code>
+ type.</li>
+</ul>
+
+<a name="numeric.validate"></a>
+<h3>3.2 Validating a Numeric Value</h3>
+<p>
+ You can either use one of the <code>isValid()</code> methods to just determine
+ if a number is valid, or use one of the <code>validate()</code> methods to
+ validate a number and convert it to an appropriate type.
+</p>
+<p>
+ The following example validates an integer against a custom pattern
+ for the <i>German</i> locale. Please note the format is specified using
+ the standard symbols for </code>java.text.DecimalFormat</code> so although
+ the decimal separator is indicated as a period (".") in the format, the
+ validator will check using the German decimal separator - which is a comma (",").
+</p>
+<pre>
+ // Get the Integer validator
+ IntegerValidator validator = IntegerValidator.getInstance();
+
+ // Validate/Convert the number
+ Integer fooInteger = validator.validate(fooString, "#,##0.00", Locale.GERMAN);
+ if (fooInteger == null) {
+ // error...not a valid date
+ return;
+ }
+</pre>
+<p>The following methods are provided to validate a number (return a boolean result):</p>
+<ul>
+ <li><code>isValid(<i>value</i>)</code></li>
+ <li><code>isValid(<i>value</i>, <i>pattern</i>)</code></li>
+ <li><code>isValid(<i>value</i>, Locale)</code></li>
+ <li><code>isValid(<i>value</i>, <i>pattern</i>, Locale)</code></li>
+</ul>
+
+<p>The following methods are provided to validate a date/time and convert it one of
+ the <code>java.lang.Number</code> implementations:</p>
+<ul>
+ <li><code>validate(<i>value</i>)</code></li>
+ <li><code>validate(<i>value</i>, <i>pattern</i>)</code></li>
+ <li><code>validate(<i>value</i>, Locale)</code></li>
+ <li><code>validate(<i>value</i>, <i>pattern</i>, Locale)</code></li>
+</ul>
+
+<a name="numeric.format"></a>
+<h3>3.3 Formatting</h3>
+<p>
+ Formatting and validating are two sides of the same coin. Typically
+ <i>input</i> values which are converted from Strings according to a
+ specified <i>format</i> also have to be rendered for <i>output</i> in
+ the same format. These validators provide the mechanism for formatting from
+ numeric objects to Strings. The following methods are provided to format
+ numeric values as Strings:
+</p>
+<ul>
+ <li><code>format(<i>number</i>)</code></li>
+ <li><code>format(<i>number</i>, <i>pattern</i>)</code></li>
+ <li><code>format(<i>number</i>, Locale)</code></li>
+ <li><code>format(<i>number</i>, <i>pattern</i>, Locale)</code></li>
+</ul>
+
+<a name="numeric.compare"></a>
+<h3>3.4 Comparing Numbers</h3>
+<p>
+ As well as validating that a value is a valid number, these validators
+ also provide functions for validating the <i>minimum</i>, <i>minimum</i>
+ and <i>range</i> of a value.
+</p>
+<pre>
+ // Check the number is between 25 and 75
+ int compare = validator.compareMonths{fooDate, new Date(), null);
+ if (validator.isInRange(fooInteger, 25, 75) {
+ // valid...in the specified range
+ return;
+ }
+</pre>
</body>
</html>
Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java (original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java Sat Jan 21 19:24:40 2006
@@ -38,6 +38,7 @@
protected static final TimeZone GMT = TimeZone.getTimeZone("GMT"); // 0 offset
protected static final TimeZone EST = TimeZone.getTimeZone("EST"); // - 5 hours
protected static final TimeZone EET = TimeZone.getTimeZone("EET"); // + 2 hours
+ protected static final TimeZone UTC = TimeZone.getTimeZone("UTC"); // + 2 hours
protected String[] patternValid = new String[] {
"2005-01-01"
@@ -123,7 +124,7 @@
public void testPatternValid() {
for (int i = 0; i < patternValid.length; i++) {
String text = i + " value=[" +patternValid[i]+"] failed ";
- Object date = validator.validateObj(patternValid[i], "yy-MM-dd");
+ Object date = validator.parse(patternValid[i], "yy-MM-dd", null, null);
assertNotNull("validateObj() " + text + date, date);
assertTrue("isValid() " + text, validator.isValid(patternValid[i], "yy-MM-dd"));
if (date instanceof Calendar) {
@@ -139,7 +140,7 @@
public void testPatternInvalid() {
for (int i = 0; i < patternInvalid.length; i++) {
String text = i + " value=[" +patternInvalid[i]+"] passed ";
- Object date = validator.validateObj(patternInvalid[i], "yy-MM-dd");
+ Object date = validator.parse(patternInvalid[i], "yy-MM-dd", null, null);
assertNull("validateObj() " + text + date, date);
assertFalse("isValid() " + text, validator.isValid(patternInvalid[i], "yy-MM-dd"));
}
@@ -151,7 +152,7 @@
public void testLocaleValid() {
for (int i = 0; i < localeValid.length; i++) {
String text = i + " value=[" +localeValid[i]+"] failed ";
- Object date = validator.validateObj(localeValid[i], Locale.US);
+ Object date = validator.parse(localeValid[i], null, Locale.US, null);
assertNotNull("validateObj() " + text + date, date);
assertTrue("isValid() " + text, validator.isValid(localeValid[i], Locale.US));
if (date instanceof Calendar) {
@@ -167,7 +168,7 @@
public void testLocaleInvalid() {
for (int i = 0; i < localeInvalid.length; i++) {
String text = i + " value=[" +localeInvalid[i]+"] passed ";
- Object date = validator.validateObj(localeInvalid[i], Locale.US);
+ Object date = validator.parse(localeInvalid[i], null, Locale.US, null);
assertNull("validateObj() " + text + date, date);
assertFalse("isValid() " + text, validator.isValid(localeInvalid[i], Locale.US));
}
@@ -179,7 +180,7 @@
public void testFormat() {
// Create a Date or Calendar
- Object test = validator.validateObj("2005-11-28", "yyyy-MM-dd");
+ Object test = validator.parse("2005-11-28", "yyyy-MM-dd", null, null);
assertNotNull("Test Date ", test);
assertEquals("Format pattern", "28.11.05", validator.format(test, "dd.MM.yy"));
assertEquals("Format locale", "11/28/05", validator.format(test, Locale.US));
Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java (original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java Sat Jan 21 19:24:40 2006
@@ -84,15 +84,23 @@
}
/**
+ * Test Format Type
+ */
+ public void testFormatType() {
+ assertEquals("Format Type A", 0, validator.getFormatType());
+ assertEquals("Format Type B", AbstractNumberValidator.STANDARD_FORMAT, validator.getFormatType());
+ }
+
+ /**
* Test Min/Max values allowed
*/
public void testValidateMinMax() {
DecimalFormat fmt = new DecimalFormat("#");
if (max != null) {
- assertEquals("Test Max", max, validator.validateObj(fmt.format(max)));
- assertNull("Test Max + 1", validator.validateObj(fmt.format(maxPlusOne)));
- assertEquals("Test Min", min, validator.validateObj(fmt.format(min)));
- assertNull("Test min - 1", validator.validateObj(fmt.format(minMinusOne)));
+ assertEquals("Test Max", max, validator.parse(fmt.format(max), "#", null));
+ assertNull("Test Max + 1", validator.parse(fmt.format(maxPlusOne), "#", null));
+ assertEquals("Test Min", min, validator.parse(fmt.format(min), "#", null));
+ assertNull("Test min - 1", validator.parse(fmt.format(minMinusOne), "#", null));
}
}
@@ -102,10 +110,10 @@
public void testInvalidStrict() {
for (int i = 0; i < invalidStrict.length; i++) {
String text = "idx=["+i+"] value=[" + invalidStrict[i] + "]";
- assertNull("(A) " + text, strictValidator.validateObj(invalidStrict[i], Locale.US));
- assertFalse("(B) " + text, strictValidator.isValid(invalidStrict[i], Locale.US));
- assertNull("(C) " + text, strictValidator.validateObj(invalidStrict[i], testPattern));
- assertFalse("(D) " + text, strictValidator.isValid(invalidStrict[i], testPattern));
+ assertNull("(A) " + text, strictValidator.parse(invalidStrict[i], null, Locale.US));
+ assertFalse("(B) " + text, strictValidator.isValid(invalidStrict[i], null, Locale.US));
+ assertNull("(C) " + text, strictValidator.parse(invalidStrict[i], testPattern, null));
+ assertFalse("(D) " + text, strictValidator.isValid(invalidStrict[i], testPattern, null));
}
}
@@ -115,10 +123,10 @@
public void testInvalidNotStrict() {
for (int i = 0; i < invalid.length; i++) {
String text = "idx=["+i+"] value=[" + invalid[i] + "]";
- assertNull("(A) " + text, validator.validateObj(invalid[i], Locale.US));
- assertFalse("(B) " + text, validator.isValid(invalid[i], Locale.US));
- assertNull("(C) " + text, validator.validateObj(invalid[i], testPattern));
- assertFalse("(D) " + text, validator.isValid(invalid[i], testPattern));
+ assertNull("(A) " + text, validator.parse(invalid[i], null, Locale.US));
+ assertFalse("(B) " + text, validator.isValid(invalid[i], null, Locale.US));
+ assertNull("(C) " + text, validator.parse(invalid[i], testPattern, null));
+ assertFalse("(D) " + text, validator.isValid(invalid[i], testPattern, null));
}
}
@@ -128,10 +136,10 @@
public void testValidStrict() {
for (int i = 0; i < validStrict.length; i++) {
String text = "idx=["+i+"] value=[" + validStrictCompare[i] + "]";
- assertEquals("(A) " + text, validStrictCompare[i], strictValidator.validateObj(validStrict[i], Locale.US));
- assertTrue("(B) " + text, strictValidator.isValid(validStrict[i], Locale.US));
- assertEquals("(C) " + text, validStrictCompare[i], strictValidator.validateObj(validStrict[i], testPattern));
- assertTrue("(D) " + text, strictValidator.isValid(validStrict[i], testPattern));
+ assertEquals("(A) " + text, validStrictCompare[i], strictValidator.parse(validStrict[i], null, Locale.US));
+ assertTrue("(B) " + text, strictValidator.isValid(validStrict[i], null, Locale.US));
+ assertEquals("(C) " + text, validStrictCompare[i], strictValidator.parse(validStrict[i], testPattern, null));
+ assertTrue("(D) " + text, strictValidator.isValid(validStrict[i], testPattern, null));
}
}
@@ -141,10 +149,10 @@
public void testValidNotStrict() {
for (int i = 0; i < valid.length; i++) {
String text = "idx=["+i+"] value=[" + validCompare[i] + "]";
- assertEquals("(A) " + text, validCompare[i], validator.validateObj(valid[i], Locale.US));
- assertTrue("(B) " + text, validator.isValid(valid[i], Locale.US));
- assertEquals("(C) " + text, validCompare[i], validator.validateObj(valid[i], testPattern));
- assertTrue("(D) " + text, validator.isValid(valid[i], testPattern));
+ assertEquals("(A) " + text, validCompare[i], validator.parse(valid[i], null, Locale.US));
+ assertTrue("(B) " + text, validator.isValid(valid[i], null, Locale.US));
+ assertEquals("(C) " + text, validCompare[i], validator.parse(valid[i], testPattern, null));
+ assertTrue("(D) " + text, validator.isValid(valid[i], testPattern, null));
}
}
@@ -153,16 +161,16 @@
*/
public void testValidateLocale() {
- assertEquals("US Locale, US Format", testNumber, strictValidator.validateObj(testStringUS, Locale.US));
- assertNull("US Locale, DE Format", strictValidator.validateObj(testStringDE, Locale.US));
+ assertEquals("US Locale, US Format", testNumber, strictValidator.parse(testStringUS, null, Locale.US));
+ assertNull("US Locale, DE Format", strictValidator.parse(testStringDE, null, Locale.US));
// Default German Locale
- assertEquals("DE Locale, DE Format", testNumber, strictValidator.validateObj(testStringDE, Locale.GERMAN));
- assertNull("DE Locale, US Format", strictValidator.validateObj(testStringUS, Locale.GERMAN));
+ assertEquals("DE Locale, DE Format", testNumber, strictValidator.parse(testStringDE, null, Locale.GERMAN));
+ assertNull("DE Locale, US Format", strictValidator.parse(testStringUS, null, Locale.GERMAN));
// Default Locale has been set to Locale.US in setup()
- assertEquals("Default Locale, US Format", testNumber, strictValidator.validateObj(testStringUS));
- assertNull("Default Locale, DE Format", strictValidator.validateObj(testStringDE));
+ assertEquals("Default Locale, US Format", testNumber, strictValidator.parse(testStringUS, null, null));
+ assertNull("Default Locale, DE Format", strictValidator.parse(testStringDE, null, null));
}
/**
Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java (original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java Sat Jan 21 19:24:40 2006
@@ -50,7 +50,7 @@
super.setUp();
validator = new BigDecimalValidator(false);
- strictValidator = new BigDecimalValidator(true);
+ strictValidator = new BigDecimalValidator();
testPattern = "#,###.###";
@@ -91,57 +91,65 @@
* Test BigDecimalValidator validate Methods
*/
public void testBigDecimalValidatorMethods() {
- Locale locale = Locale.GERMAN;
- String pattern = "0,00,00";
- String patternVal = "1,23,45";
- String localeVal = "12.345";
- String defaultVal = "12,345";
- String XXXX = "XXXX";
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
BigDecimal expected = new BigDecimal(12345);
assertEquals("validate(A) default", expected, BigDecimalValidator.getInstance().validate(defaultVal));
assertEquals("validate(A) locale ", expected, BigDecimalValidator.getInstance().validate(localeVal, locale));
assertEquals("validate(A) pattern", expected, BigDecimalValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, BigDecimalValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
assertTrue("isValid(A) default", BigDecimalValidator.getInstance().isValid(defaultVal));
assertTrue("isValid(A) locale ", BigDecimalValidator.getInstance().isValid(localeVal, locale));
assertTrue("isValid(A) pattern", BigDecimalValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", BigDecimalValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
assertNull("validate(B) default", BigDecimalValidator.getInstance().validate(XXXX));
assertNull("validate(B) locale ", BigDecimalValidator.getInstance().validate(XXXX, locale));
assertNull("validate(B) pattern", BigDecimalValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", BigDecimalValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
assertFalse("isValid(B) default", BigDecimalValidator.getInstance().isValid(XXXX));
assertFalse("isValid(B) locale ", BigDecimalValidator.getInstance().isValid(XXXX, locale));
assertFalse("isValid(B) pattern", BigDecimalValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", BigDecimalValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
}
/**
* Test BigDecimal Range/Min/Max
*/
public void testBigDecimalRangeMinMax() {
- BigDecimalValidator validator = (BigDecimalValidator)strictValidator;
- BigDecimal number9 = validator.validate("9", "#");
- BigDecimal number10 = validator.validate("10", "#");
- BigDecimal number11 = validator.validate("11", "#");
- BigDecimal number19 = validator.validate("19", "#");
- BigDecimal number20 = validator.validate("20", "#");
- BigDecimal number21 = validator.validate("21", "#");
+ BigDecimalValidator validator = new BigDecimalValidator(true, AbstractNumberValidator.STANDARD_FORMAT, true);
+ BigDecimal number9 = new BigDecimal("9");
+ BigDecimal number10 = new BigDecimal("10");
+ BigDecimal number11 = new BigDecimal("11");
+ BigDecimal number19 = new BigDecimal("19");
+ BigDecimal number20 = new BigDecimal("20");
+ BigDecimal number21 = new BigDecimal("21");
+
+ float min = (float)10;
+ float max = (float)20;
// Test isInRange()
- assertFalse("isInRange() < min", validator.isInRange(number9, 10, 20));
- assertTrue("isInRange() = min", validator.isInRange(number10, 10, 20));
- assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
- assertTrue("isInRange() = max", validator.isInRange(number20, 10, 20));
- assertFalse("isInRange() > max", validator.isInRange(number21, 10, 20));
+ assertFalse("isInRange(A) < min", validator.isInRange(number9, min, max));
+ assertTrue("isInRange(A) = min", validator.isInRange(number10, min, max));
+ assertTrue("isInRange(A) in range", validator.isInRange(number11, min, max));
+ assertTrue("isInRange(A) = max", validator.isInRange(number20, min, max));
+ assertFalse("isInRange(A) > max", validator.isInRange(number21, min, max));
// Test minValue()
- assertFalse("minValue() < min", validator.minValue(number9, 10));
- assertTrue("minValue() = min", validator.minValue(number10, 10));
- assertTrue("minValue() > min", validator.minValue(number11, 10));
+ assertFalse("minValue(A) < min", validator.minValue(number9, min));
+ assertTrue("minValue(A) = min", validator.minValue(number10, min));
+ assertTrue("minValue(A) > min", validator.minValue(number11, min));
// Test minValue()
- assertTrue("maxValue() < max", validator.maxValue(number19, 20));
- assertTrue("maxValue() = max", validator.maxValue(number20, 20));
- assertFalse("maxValue() > max", validator.maxValue(number21, 20));
+ assertTrue("maxValue(A) < max", validator.maxValue(number19, max));
+ assertTrue("maxValue(A) = max", validator.maxValue(number20, max));
+ assertFalse("maxValue(A) > max", validator.maxValue(number21, max));
}
}
Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java (original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java Sat Jan 21 19:24:40 2006
@@ -49,8 +49,8 @@
protected void setUp() throws Exception {
super.setUp();
- validator = new BigIntegerValidator(false);
- strictValidator = new BigIntegerValidator(true);
+ validator = new BigIntegerValidator(false, 0);
+ strictValidator = new BigIntegerValidator();
testPattern = "#,###";
@@ -92,6 +92,7 @@
Locale locale = Locale.GERMAN;
String pattern = "0,00,00";
String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
String localeVal = "12.345";
String defaultVal = "12,345";
String XXXX = "XXXX";
@@ -99,18 +100,22 @@
assertEquals("validate(A) default", expected, BigIntegerValidator.getInstance().validate(defaultVal));
assertEquals("validate(A) locale ", expected, BigIntegerValidator.getInstance().validate(localeVal, locale));
assertEquals("validate(A) pattern", expected, BigIntegerValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, BigIntegerValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
assertTrue("isValid(A) default", BigIntegerValidator.getInstance().isValid(defaultVal));
assertTrue("isValid(A) locale ", BigIntegerValidator.getInstance().isValid(localeVal, locale));
assertTrue("isValid(A) pattern", BigIntegerValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", BigIntegerValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
assertNull("validate(B) default", BigIntegerValidator.getInstance().validate(XXXX));
assertNull("validate(B) locale ", BigIntegerValidator.getInstance().validate(XXXX, locale));
assertNull("validate(B) pattern", BigIntegerValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", BigIntegerValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
assertFalse("isValid(B) default", BigIntegerValidator.getInstance().isValid(XXXX));
assertFalse("isValid(B) locale ", BigIntegerValidator.getInstance().isValid(XXXX, locale));
assertFalse("isValid(B) pattern", BigIntegerValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", BigIntegerValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
}
/**
Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java?rev=371174&r1=371173&r2=371174&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java (original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java Sat Jan 21 19:24:40 2006
@@ -48,8 +48,8 @@
protected void setUp() throws Exception {
super.setUp();
- validator = new ByteValidator(false);
- strictValidator = new ByteValidator(true);
+ validator = new ByteValidator(false, 0);
+ strictValidator = new ByteValidator();
testPattern = "#,###";
@@ -91,6 +91,7 @@
Locale locale = Locale.GERMAN;
String pattern = "0,00";
String patternVal = "1,23";
+ String germanPatternVal = "1.23";
String localeVal = ".123";
String defaultVal = ",123";
String XXXX = "XXXX";
@@ -98,18 +99,22 @@
assertEquals("validate(A) default", expected, ByteValidator.getInstance().validate(defaultVal));
assertEquals("validate(A) locale ", expected, ByteValidator.getInstance().validate(localeVal, locale));
assertEquals("validate(A) pattern", expected, ByteValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, ByteValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
assertTrue("isValid(A) default", ByteValidator.getInstance().isValid(defaultVal));
assertTrue("isValid(A) locale ", ByteValidator.getInstance().isValid(localeVal, locale));
assertTrue("isValid(A) pattern", ByteValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", ByteValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
assertNull("validate(B) default", ByteValidator.getInstance().validate(XXXX));
assertNull("validate(B) locale ", ByteValidator.getInstance().validate(XXXX, locale));
assertNull("validate(B) pattern", ByteValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", ByteValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
assertFalse("isValid(B) default", ByteValidator.getInstance().isValid(XXXX));
assertFalse("isValid(B) locale ", ByteValidator.getInstance().isValid(XXXX, locale));
assertFalse("isValid(B) pattern", ByteValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", ByteValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org