commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r370397 [2/4] - in /jakarta/commons/proper/validator/trunk: ./ src/share/org/apache/commons/validator/routines/ src/test/org/apache/commons/validator/routines/
Date Thu, 19 Jan 2006 06:38:52 GMT
Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,314 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * <p><b>Date Validation</b> and Conversion routines (<code>java.util.Date</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    a <code>Date</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>
+ *    </ul>
+ *    
+ * <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>Date</code> value.</p>
+ *    
+ * <p>Implementations of the <code>validate()</code> method are provided
+ *    to create <code>Date</code> objects for different <i>time zones</i>
+ *    if the system default is not appropriate.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform various date comparison checks:</p>
+ *    <ul>
+ *       <li><code>compareDates()</code> compares the day, month and
+ *           year of two dates, returing 0, -1 or +1 indicating
+ *           whether the first date is equal, before or after the second.</li>
+ *       <li><code>compareWeeks()</code> compares the week and 
+ *           year of two dates, returing 0, -1 or +1 indicating
+ *           whether the first week is equal, before or after the second.</li>
+ *       <li><code>compareMonths()</code> compares the month and
+ *           year of two dates, returing 0, -1 or +1 indicating
+ *           whether the first month is equal, before or after the second.</li>
+ *       <li><code>compareQuarters()</code> compares the quarter and
+ *           year of two dates, returing 0, -1 or +1 indicating
+ *           whether the first quarter is equal, before or after the second.</li>
+ *       <li><code>compareYears()</code> compares the 
+ *           year of two dates, returing 0, -1 or +1 indicating
+ *           whether the first year is equal, before or after the second.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ * 
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class DateValidator extends AbstractCalendarValidator {
+
+    private static final DateValidator VALIDATOR = new DateValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the DateValidator.
+     */
+    public static DateValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance with <i>short</i>
+     * date style.
+     */
+    public DateValidator() {
+        this(true, DateFormat.SHORT);
+    }
+
+    /**
+     * Construct an instance with the specified <i>strict</i>
+     * and <i>date style</i> parameters.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     * @param dateStyle the date style to use for Locale validation.
+     */
+    public DateValidator(boolean strict, int dateStyle) {
+        super(strict, dateStyle, -1);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Date</code> using the default
+     *    <code>Locale</code> and <code>TimeZone</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Date</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Date validate(String value) {
+        return (Date)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Date</code> 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.
+     * @return The parsed <code>Date</code> if valid or <code>null</code> if invalid.
+     */
+    public Date validate(String value, TimeZone timeZone) {
+        return (Date)validateObj(value, Locale.getDefault(), timeZone);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Date</code> 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>Date</code> if valid or <code>null</code> if invalid.
+     */
+    public Date validate(String value, String pattern) {
+        return (Date)validateObj(value, pattern);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Date</code> 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.
+     * @return The parsed <code>Date</code> if valid or <code>null</code> if invalid.
+     */
+    public Date validate(String value, String pattern, TimeZone timeZone) {
+        return (Date)validateObj(value, pattern, timeZone);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Date</code> using the specified
+     *    <code>Locale</code> and 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.
+     * @return The parsed <code>Date</code> if valid or <code>null</code> if invalid.
+     */
+    public Date validate(String value, Locale locale) {
+        return (Date)validateObj(value, locale);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Date</code> using the 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 date format, system default if null.
+     * @param timeZone The Time Zone used to parse the date, system default if null.
+     * @return The parsed <code>Date</code> if valid or <code>null</code> if invalid.
+     */
+    public Date validate(String value, Locale locale, TimeZone timeZone) {
+        return (Date)validateObj(value, locale, timeZone);
+    }
+
+    /**
+     * <p>Compare Dates (day, month and year - not time).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @param timeZone The Time Zone used to compare the dates, system default if null.
+     * @return Zero if the dates are equal, -1 if first
+     * date is less than the seconds and +1 if the first
+     * date is greater than.
+     */
+    public int compareDates(Date value, Date compare, TimeZone timeZone) {
+        Calendar calendarValue   = getCalendar(value, timeZone);
+        Calendar calendarCompare = getCalendar(compare, timeZone);
+        return compare(calendarValue, calendarCompare, Calendar.DATE);
+    }
+
+    /**
+     * <p>Compare Weeks (week and year).</p>
+     * 
+     * @param value The <code>Date</code> value to check.
+     * @param compare The <code>Date</code> to compare the value to.
+     * @param timeZone The Time Zone used to compare the dates, system default if null.
+     * @return Zero if the weeks are equal, -1 if first
+     * parameter's week is less than the seconds and +1 if the first
+     * parameter's week is greater than.
+     */
+    public int compareWeeks(Date value, Date compare, TimeZone timeZone) {
+        Calendar calendarValue   = getCalendar(value, timeZone);
+        Calendar calendarCompare = getCalendar(compare, timeZone);
+        return compare(calendarValue, calendarCompare, Calendar.WEEK_OF_YEAR);
+    }
+
+    /**
+     * <p>Compare Months (month and year).</p>
+     * 
+     * @param value The <code>Date</code> value to check.
+     * @param compare The <code>Date</code> to compare the value to.
+     * @param timeZone The Time Zone used to compare the dates, system default if null.
+     * @return Zero if the months are equal, -1 if first
+     * parameter's month is less than the seconds and +1 if the first
+     * parameter's month is greater than.
+     */
+    public int compareMonths(Date value, Date compare, TimeZone timeZone) {
+        Calendar calendarValue   = getCalendar(value, timeZone);
+        Calendar calendarCompare = getCalendar(compare, timeZone);
+        return compare(calendarValue, calendarCompare, Calendar.MONTH);
+    }
+
+    /**
+     * <p>Compare Quarters (quarter and year).</p>
+     * 
+     * @param value The <code>Date</code> value to check.
+     * @param compare The <code>Date</code> to compare the value to.
+     * @param timeZone The Time Zone used to compare the dates, system default if null.
+     * @return Zero if the months are equal, -1 if first
+     * parameter's quarter is less than the seconds and +1 if the first
+     * parameter's quarter is greater than.
+     */
+    public int compareQuarters(Date value, Date compare, TimeZone timeZone) {
+        return compareQuarters(value, compare, timeZone, 1);
+    }
+
+    /**
+     * <p>Compare Quarters (quarter and year).</p>
+     * 
+     * @param value The <code>Date</code> value to check.
+     * @param compare The <code>Date</code> to compare the value to.
+     * @param timeZone The Time Zone used to compare the dates, system default if null.
+     * @param monthOfFirstQuarter The  month that the first quarter starts.
+     * @return Zero if the quarters are equal, -1 if first
+     * parameter's quarter is less than the seconds and +1 if the first
+     * parameter's quarter is greater than.
+     */
+    public int compareQuarters(Date value, Date compare, TimeZone timeZone, int monthOfFirstQuarter) {
+        Calendar calendarValue   = getCalendar(value, timeZone);
+        Calendar calendarCompare = getCalendar(compare, timeZone);
+        return super.compareQuarters(calendarValue, calendarCompare, monthOfFirstQuarter);
+    }
+
+    /**
+     * <p>Compare Years.</p>
+     * 
+     * @param value The <code>Date</code> value to check.
+     * @param compare The <code>Date</code> to compare the value to.
+     * @param timeZone The Time Zone used to compare the dates, system default if null.
+     * @return Zero if the years are equal, -1 if first
+     * parameter's year is less than the seconds and +1 if the first
+     * parameter's year is greater than.
+     */
+    public int compareYears(Date value, Date compare, TimeZone timeZone) {
+        Calendar calendarValue   = getCalendar(value, timeZone);
+        Calendar calendarCompare = getCalendar(compare, timeZone);
+        return compare(calendarValue, calendarCompare, Calendar.YEAR);
+    }
+
+    /**
+     * <p>Convert the <code>Calendar</code> to a <code>Date</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.
+     */
+    protected Object processCalendar(Calendar calendar) {
+        return calendar.getTime();
+    }
+
+    /**
+     * <p>Convert a <code>Date</code> to a <code>Calendar</code>.</p>
+     * 
+     * @param value The date value to be converted.
+     * @return The converted <code>Calendar</code>.
+     */
+    private Calendar getCalendar(Date value, TimeZone timeZone) {
+
+        Calendar calendar = null;
+        if (timeZone != null) {
+            calendar = Calendar.getInstance(timeZone);
+        } else {
+            calendar = Calendar.getInstance();
+        }
+        calendar.setTime(value);
+        return calendar;
+
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,223 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * <p><b>Double Validation</b> and Conversion routines (<code>java.lang.Double</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    a <code>Double</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>
+ *    </ul>
+ *    
+ * <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>Double</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class DoubleValidator extends AbstractNumberValidator {
+
+    private static final DoubleValidator VALIDATOR = new DoubleValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the DoubleValidator.
+     */
+    public static DoubleValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public DoubleValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public DoubleValidator(boolean strict) {
+        super(strict, true);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Double</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Double</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Double validate(String value) {
+        return (Double)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Double</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed <code>BigDecimal</code> if valid or <code>null</code> if invalid.
+     */
+    public Double validate(String value, String pattern) {
+        return (Double)validateObj(value, pattern);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Double</code> using the
+     *    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.
+     * @return The parsed <code>Double</code> if valid or <code>null</code> if invalid.
+     */
+    public Double validate(String value, Locale locale) {
+        return (Double)validateObj(value, locale);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(double value, double min, double max) {
+        return (value >= min && value <= max);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Double value, double min, double max) {
+        return isInRange(value.doubleValue(), min, max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(double value, double min) {
+        return (value >= min);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Double value, double min) {
+        return minValue(value.doubleValue(), min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(double value, double max) {
+        return (value <= max);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Double value, double max) {
+        return maxValue(value.doubleValue(), max);
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Number</code> to
+     * a <code>Double</code>.</p>
+     * 
+     * @param number The number validation is being performed on.
+     * @return The validated/converted <code>Double</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected Object processNumber(Number number) {
+
+        if (number instanceof Double) {
+            return number;
+        } else {
+            return new Double(number.doubleValue());
+        }
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,239 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * <p><b>Float Validation</b> and Conversion routines (<code>java.lang.Float</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    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>
+ *    </ul>
+ *    
+ * <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>Float</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class FloatValidator extends AbstractNumberValidator {
+
+    private static final FloatValidator VALIDATOR = new FloatValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the FloatValidator.
+     */
+    public static FloatValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public FloatValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public FloatValidator(boolean strict) {
+        super(strict, true);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Float</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Float</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Float validate(String value) {
+        return (Float)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Float</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @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);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Float</code> using the
+     *    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.
+     * @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);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(float value, float min, float max) {
+        return (value >= min && value <= max);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Float value, float min, float max) {
+        return isInRange(value.floatValue(), min, max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(float value, float min) {
+        return (value >= min);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Float value, float min) {
+        return minValue(value.floatValue(), min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(float value, float max) {
+        return (value <= max);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Float value, float max) {
+        return maxValue(value.floatValue(), max);
+    }
+
+    /**
+     * <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.
+     */
+    protected Object processNumber(Number number) {
+
+        double doubleValue = number.doubleValue();
+
+        if (doubleValue > 0) {
+            if (doubleValue < Float.MIN_VALUE) {
+                return null;
+            }
+            if (doubleValue > Float.MAX_VALUE) {
+                return null;
+            }
+        } else  if (doubleValue < 0){
+            double posDouble = doubleValue * -1;
+            if (posDouble < Float.MIN_VALUE) {
+                return null;
+            }
+            if (posDouble > Float.MAX_VALUE) {
+                return null;
+            }
+        }
+
+        return new Float(number.floatValue());
+
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,229 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * <p><b>Integer Validation</b> and Conversion routines (<code>java.lang.Integer</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    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>
+ *    </ul>
+ *    
+ * <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>Integer</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class IntegerValidator extends AbstractNumberValidator {
+
+    private static final IntegerValidator VALIDATOR = new IntegerValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the IntegerValidator.
+     */
+    public static IntegerValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public IntegerValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public IntegerValidator(boolean strict) {
+        super(strict, false);
+    }
+
+    /**
+     * <p>Validate/convert an <code>Integer</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Integer</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Integer validate(String value) {
+        return (Integer)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert an <code>Integer</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @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);
+    }
+
+    /**
+     * <p>Validate/convert an <code>Integer</code> using the
+     *    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.
+     * @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);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(int value, int min, int max) {
+        return (value >= min && value <= max);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Integer value, int min, int max) {
+        return isInRange(value.intValue(), min, max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(int value, int min) {
+        return (value >= min);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Integer value, int min) {
+        return minValue(value.intValue(), min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(int value, int max) {
+        return (value <= max);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Integer value, int max) {
+        return maxValue(value.intValue(), max);
+    }
+
+    /**
+     * <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.
+     */
+    protected Object processNumber(Number number) {
+
+        long longValue = number.longValue();
+
+        if (longValue < Integer.MIN_VALUE) {
+            return null;
+        }
+
+        if (longValue > Integer.MAX_VALUE) {
+            return null;
+        }
+
+        return new Integer(number.intValue());
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,223 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * <p><b>Long Validation</b> and Conversion routines (<code>java.lang.Long</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    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>
+ *    </ul>
+ *    
+ * <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>Long</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class LongValidator extends AbstractNumberValidator {
+
+    private static final LongValidator VALIDATOR = new LongValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the LongValidator.
+     */
+    public static LongValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public LongValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public LongValidator(boolean strict) {
+        super(strict, false);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Long</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Long</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Long validate(String value) {
+        return (Long)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Long</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @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);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Long</code> using the
+     *    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.
+     * @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);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(long value, long min, long max) {
+        return (value >= min && value <= max);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Long value, long min, long max) {
+        return isInRange(value.longValue(), min, max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(long value, long min) {
+        return (value >= min);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Long value, long min) {
+        return minValue(value.longValue(), min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(long value, long max) {
+        return (value <= max);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Long value, long max) {
+        return maxValue(value.longValue(), max);
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Number</code> to
+     * an <code>Long</code>.</p>
+     * 
+     * @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.
+     */
+    protected Object processNumber(Number number) {
+
+        if (number instanceof Long) {
+            return number;
+        } else {
+            return new Long(number.longValue());
+        }
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,84 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.Format;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * <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>Otherwise it provides the same functionality as the <code>BigDecimal</code>
+ *    with converted values being returned as a  <code>BigDecimal</code>.</p>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class PercentValidator extends BigDecimalValidator {
+
+    private static final PercentValidator VALIDATOR = new PercentValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the PercentValidator.
+     */
+    public static BigDecimalValidator getPercentInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public PercentValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public PercentValidator(boolean strict) {
+        super(strict);
+    }
+
+    /**
+     * <p>Returns a percentage <code>NumberFormat</code> for the specified Locale.</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.
+     */
+    public Format getFormat(Locale locale) {
+
+        if (locale == null) {
+            locale = Locale.getDefault();
+        }
+        return NumberFormat.getPercentInstance(locale);
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,229 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * <p><b>Short Validation</b> and Conversion routines (<code>java.lang.Short</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    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>
+ *    </ul>
+ *    
+ * <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>Short</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class ShortValidator extends AbstractNumberValidator {
+
+    private static final ShortValidator VALIDATOR = new ShortValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the ShortValidator.
+     */
+    public static ShortValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public ShortValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public ShortValidator(boolean strict) {
+        super(strict, false);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Short</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Short</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Short validate(String value) {
+        return (Short)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Short</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @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);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Short</code> using the
+     *    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.
+     * @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);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(short value, short min, short max) {
+        return (value >= min && value <= max);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Short value, short min, short max) {
+        return isInRange(value.shortValue(), min, max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(short value, short min) {
+        return (value >= min);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Short value, short min) {
+        return minValue(value.shortValue(), min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(short value, short max) {
+        return (value <= max);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Short value, short max) {
+        return maxValue(value.shortValue(), max);
+    }
+
+    /**
+     * <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.
+     */
+    protected Object processNumber(Number number) {
+
+        long longValue = number.longValue();
+
+        if (longValue < Short.MIN_VALUE) {
+            return null;
+        }
+
+        if (longValue > Short.MAX_VALUE) {
+            return null;
+        }
+
+        return new Short(number.shortValue());
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,256 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.validator.routines;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * <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>
+ *    <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>
+ *    </ul>
+ *    
+ * <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>
+ *
+ * <p>Implementations of the <code>validate()</code> method are provided
+ *    to create <code>Calendar</code> objects for different <i>time zones</i>
+ *    if the system default is not appropriate.</p>
+ *    
+ * <p>Alternatively the CalendarValidator's <code>adjustToTimeZone()</code> method
+ *    can be used to adjust the <code>TimeZone</code> of the <code>Calendar</code>
+ *    object afterwards.</p> 
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform various date comparison checks:</p>
+ *    <ul>
+ *       <li><code>compareTime()</code> compares the hours, minutes, seconds
+ *           and milliseconds of two calendars, returing 0, -1 or +1 indicating
+ *           whether the first time is equal, before or after the second.</li>
+ *       <li><code>compareSeconds()</code> compares the hours, minutes and
+ *           seconds of two times, returing 0, -1 or +1 indicating
+ *           whether the first is equal to, before or after the second.</li>
+ *       <li><code>compareMinutes()</code> compares the hours and minutes
+ *           two times, returing 0, -1 or +1 indicating
+ *           whether the first is equal to, before or after the second.</li>
+ *       <li><code>compareHours()</code> compares the hours
+ *           of two times, returing 0, -1 or +1 indicating
+ *           whether the first is equal to, before or after the second.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <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>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class TimeValidator extends AbstractCalendarValidator {
+
+    private static final TimeValidator VALIDATOR = new TimeValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the TimeValidator.
+     */
+    public static TimeValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance with <i>short</i>
+     * time style.
+     */
+    public TimeValidator() {
+        this(true, DateFormat.SHORT);
+    }
+
+    /**
+     * Construct an instance with the specified <i>strict</i>
+     * and <i>time style</i> parameters.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     * @param timeStyle the time style to use for Locale validation.
+     */
+    public TimeValidator(boolean strict, int timeStyle) {
+        super(strict, -1, timeStyle);
+    }
+
+    /**
+     * <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);
+    }
+
+    /**
+     * <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.
+     * @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);
+    }
+
+    /**
+     * <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);
+    }
+
+    /**
+     * <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.
+     * @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);
+    }
+
+    /**
+     * <p>Validate/convert a time using the 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 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, Locale locale) {
+        return (Calendar)validateObj(value, locale);
+    }
+
+    /**
+     * Checks if the value is a valid time for a
+     * specified <code>Locale</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 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);
+    }
+
+    /**
+     * <p>Compare Times (hour, minute, second and millisecond - not date).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the hours are equal, -1 if first
+     * time is less than the seconds and +1 if the first
+     * time is greater than.
+     */
+    public int compareTime(Calendar value, Calendar compare) {
+        return compareTime(value, compare, Calendar.MILLISECOND);
+    }
+
+    /**
+     * <p>Compare Seconds (hours, minutes and seconds).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the hours are equal, -1 if first
+     * parameter's seconds are less than the seconds and +1 if the first
+     * parameter's seconds are greater than.
+     */
+    public int compareSeconds(Calendar value, Calendar compare) {
+        return compareTime(value, compare, Calendar.SECOND);
+    }
+
+    /**
+     * <p>Compare Minutes (hours and minutes).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the hours are equal, -1 if first
+     * parameter's minutes are less than the seconds and +1 if the first
+     * parameter's minutes are greater than.
+     */
+    public int compareMinutes(Calendar value, Calendar compare) {
+        return compareTime(value, compare, Calendar.MINUTE);
+    }
+
+    /**
+     * <p>Compare Hours.</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the hours are equal, -1 if first
+     * parameter's hour is less than the seconds and +1 if the first
+     * parameter's hour is greater than.
+     */
+    public int compareHours(Calendar value, Calendar compare) {
+        return compareTime(value, compare, Calendar.HOUR_OF_DAY);
+    }
+
+    /**
+     * <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>
+     * 
+     * @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.
+     */
+    protected Object processCalendar(Calendar calendar) {
+        return calendar;
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html Wed Jan 18 22:38:24 2006
@@ -0,0 +1,80 @@
+<html>
+<head>
+<title>Package Documentation for org.apache.commons.validator.routines Package</title>
+</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>
+</body>
+</html>

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message