You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2014/12/26 12:04:56 UTC

svn commit: r1647953 - /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java

Author: britter
Date: Fri Dec 26 11:04:55 2014
New Revision: 1647953

URL: http://svn.apache.org/r1647953
Log:
Format source code

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java?rev=1647953&r1=1647952&r2=1647953&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java (original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/GenericTypeValidator.java Fri Dec 26 11:04:55 2014
@@ -17,19 +17,20 @@
 package org.apache.commons.validator;
 
 import java.io.Serializable;
-import java.util.Date;
-import java.util.Locale;
 import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- *  This class contains basic methods for performing validations that return the
- *  correctly typed class based on the validation performed.
+ * This class contains basic methods for performing validations that return the
+ * correctly typed class based on the validation performed.
  *
  * @version $Revision$ $Date$
  */
@@ -38,10 +39,10 @@ public class GenericTypeValidator implem
     private static final long serialVersionUID = 5487162314134261703L;
 
     /**
-     *  Checks if the value can safely be converted to a byte primitive.
+     * Checks if the value can safely be converted to a byte primitive.
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Byte value.
+     * @param value The value validation is being performed on.
+     * @return the converted Byte value.
      */
     public static Byte formatByte(String value) {
         if (value == null) {
@@ -57,12 +58,12 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a byte primitive.
+     * Checks if the value can safely be converted to a byte primitive.
      *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The locale to use to parse the number (system default if
-     *      null)
-     *@return the converted Byte value.
+     * @param value  The value validation is being performed on.
+     * @param locale The locale to use to parse the number (system default if
+     *               null)
+     * @return the converted Byte value.
      */
     public static Byte formatByte(String value, Locale locale) {
         Byte result = null;
@@ -81,7 +82,7 @@ public class GenericTypeValidator implem
             // If there was no error      and we used the whole string
             if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
                 if (num.doubleValue() >= Byte.MIN_VALUE &&
-                    num.doubleValue() <= Byte.MAX_VALUE) {
+                        num.doubleValue() <= Byte.MAX_VALUE) {
                     result = new Byte(num.byteValue());
                 }
             }
@@ -91,10 +92,10 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a short primitive.
+     * Checks if the value can safely be converted to a short primitive.
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Short value.
+     * @param value The value validation is being performed on.
+     * @return the converted Short value.
      */
     public static Short formatShort(String value) {
         if (value == null) {
@@ -110,12 +111,12 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a short primitive.
+     * Checks if the value can safely be converted to a short primitive.
      *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The locale to use to parse the number (system default if
-     *      null)
-     *@return the converted Short value.
+     * @param value  The value validation is being performed on.
+     * @param locale The locale to use to parse the number (system default if
+     *               null)
+     * @return the converted Short value.
      */
     public static Short formatShort(String value, Locale locale) {
         Short result = null;
@@ -134,7 +135,7 @@ public class GenericTypeValidator implem
             // If there was no error      and we used the whole string
             if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
                 if (num.doubleValue() >= Short.MIN_VALUE &&
-                    num.doubleValue() <= Short.MAX_VALUE) {
+                        num.doubleValue() <= Short.MAX_VALUE) {
                     result = new Short(num.shortValue());
                 }
             }
@@ -144,10 +145,10 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a int primitive.
+     * Checks if the value can safely be converted to a int primitive.
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Integer value.
+     * @param value The value validation is being performed on.
+     * @return the converted Integer value.
      */
     public static Integer formatInt(String value) {
         if (value == null) {
@@ -163,12 +164,12 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to an int primitive.
+     * Checks if the value can safely be converted to an int primitive.
      *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The locale to use to parse the number (system default if
-     *      null)
-     *@return the converted Integer value.
+     * @param value  The value validation is being performed on.
+     * @param locale The locale to use to parse the number (system default if
+     *               null)
+     * @return the converted Integer value.
      */
     public static Integer formatInt(String value, Locale locale) {
         Integer result = null;
@@ -187,7 +188,7 @@ public class GenericTypeValidator implem
             // If there was no error      and we used the whole string
             if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
                 if (num.doubleValue() >= Integer.MIN_VALUE &&
-                    num.doubleValue() <= Integer.MAX_VALUE) {
+                        num.doubleValue() <= Integer.MAX_VALUE) {
                     result = new Integer(num.intValue());
                 }
             }
@@ -197,10 +198,10 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a long primitive.
+     * Checks if the value can safely be converted to a long primitive.
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Long value.
+     * @param value The value validation is being performed on.
+     * @return the converted Long value.
      */
     public static Long formatLong(String value) {
         if (value == null) {
@@ -216,12 +217,12 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a long primitive.
+     * Checks if the value can safely be converted to a long primitive.
      *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The locale to use to parse the number (system default if
-     *      null)
-     *@return the converted Long value.
+     * @param value  The value validation is being performed on.
+     * @param locale The locale to use to parse the number (system default if
+     *               null)
+     * @return the converted Long value.
      */
     public static Long formatLong(String value, Locale locale) {
         Long result = null;
@@ -240,7 +241,7 @@ public class GenericTypeValidator implem
             // If there was no error      and we used the whole string
             if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
                 if (num.doubleValue() >= Long.MIN_VALUE &&
-                    num.doubleValue() <= Long.MAX_VALUE) {
+                        num.doubleValue() <= Long.MAX_VALUE) {
                     result = new Long(num.longValue());
                 }
             }
@@ -250,10 +251,10 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a float primitive.
+     * Checks if the value can safely be converted to a float primitive.
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Float value.
+     * @param value The value validation is being performed on.
+     * @return the converted Float value.
      */
     public static Float formatFloat(String value) {
         if (value == null) {
@@ -269,12 +270,12 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a float primitive.
+     * Checks if the value can safely be converted to a float primitive.
      *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The locale to use to parse the number (system default if
-     *      null)
-     *@return the converted Float value.
+     * @param value  The value validation is being performed on.
+     * @param locale The locale to use to parse the number (system default if
+     *               null)
+     * @return the converted Float value.
      */
     public static Float formatFloat(String value, Locale locale) {
         Float result = null;
@@ -292,7 +293,7 @@ public class GenericTypeValidator implem
             // If there was no error      and we used the whole string
             if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
                 if (num.doubleValue() >= (Float.MAX_VALUE * -1) &&
-                    num.doubleValue() <= Float.MAX_VALUE) {
+                        num.doubleValue() <= Float.MAX_VALUE) {
                     result = new Float(num.floatValue());
                 }
             }
@@ -302,10 +303,10 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a double primitive.
+     * Checks if the value can safely be converted to a double primitive.
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Double value.
+     * @param value The value validation is being performed on.
+     * @return the converted Double value.
      */
     public static Double formatDouble(String value) {
         if (value == null) {
@@ -321,12 +322,12 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  Checks if the value can safely be converted to a double primitive.
+     * Checks if the value can safely be converted to a double primitive.
      *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The locale to use to parse the number (system default if
-     *      null)
-     *@return the converted Double value.
+     * @param value  The value validation is being performed on.
+     * @param locale The locale to use to parse the number (system default if
+     *               null)
+     * @return the converted Double value.
      */
     public static Double formatDouble(String value, Locale locale) {
         Double result = null;
@@ -344,7 +345,7 @@ public class GenericTypeValidator implem
             // If there was no error      and we used the whole string
             if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
                 if (num.doubleValue() >= (Double.MAX_VALUE * -1) &&
-                    num.doubleValue() <= Double.MAX_VALUE) {
+                        num.doubleValue() <= Double.MAX_VALUE) {
                     result = new Double(num.doubleValue());
                 }
             }
@@ -354,16 +355,16 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  <p>
-     *
-     *  Checks if the field is a valid date. The <code>Locale</code> is used
-     *  with <code>java.text.DateFormat</code>. The setLenient method is set to
-     *  <code>false</code> for all.</p>
-     *
-     *@param  value   The value validation is being performed on.
-     *@param  locale  The Locale to use to parse the date (system default if
-     *      null)
-     *@return the converted Date value.
+     * <p>
+     * <p/>
+     * Checks if the field is a valid date. The <code>Locale</code> is used
+     * with <code>java.text.DateFormat</code>. The setLenient method is set to
+     * <code>false</code> for all.</p>
+     *
+     * @param value  The value validation is being performed on.
+     * @param locale The Locale to use to parse the date (system default if
+     *               null)
+     * @return the converted Date value.
      */
     public static Date formatDate(String value, Locale locale) {
         Date date = null;
@@ -378,18 +379,18 @@ public class GenericTypeValidator implem
             DateFormat formatterDefault = null;
             if (locale != null) {
                 formatterShort =
-                   DateFormat.getDateInstance(DateFormat.SHORT, locale);
+                        DateFormat.getDateInstance(DateFormat.SHORT, locale);
                 formatterDefault =
-                   DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
+                        DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
             } else {
                 formatterShort =
-                    DateFormat.getDateInstance(
-                    DateFormat.SHORT,
-                    Locale.getDefault());
+                        DateFormat.getDateInstance(
+                                DateFormat.SHORT,
+                                Locale.getDefault());
                 formatterDefault =
-                   DateFormat.getDateInstance(
-                   DateFormat.DEFAULT,
-                   Locale.getDefault());
+                        DateFormat.getDateInstance(
+                                DateFormat.DEFAULT,
+                                Locale.getDefault());
             }
 
             // Turn off lenient parsing
@@ -398,17 +399,17 @@ public class GenericTypeValidator implem
 
             // Firstly, try with the short form
             try {
-               date = formatterShort.parse(value);
+                date = formatterShort.parse(value);
             } catch (ParseException e) {
-               // Fall back on the default one
-               date = formatterDefault.parse(value);
+                // Fall back on the default one
+                date = formatterDefault.parse(value);
             }
         } catch (ParseException e) {
             // Bad date, so log and return null
             Log log = LogFactory.getLog(GenericTypeValidator.class);
             if (log.isDebugEnabled()) {
-                log.debug("Date parse failed value=[" + value  + "], " +
-                                           "locale=[" + locale + "] "  + e);
+                log.debug("Date parse failed value=[" + value + "], " +
+                        "locale=[" + locale + "] " + e);
             }
         }
 
@@ -416,25 +417,25 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  <p>
-     *  Checks if the field is a valid date. The pattern is used with <code>java.text.SimpleDateFormat</code>
-     *  . If strict is true, then the length will be checked so '2/12/1999' will
-     *  not pass validation with the format 'MM/dd/yyyy' because the month isn't
-     *  two digits. The setLenient method is set to <code>false</code> for all.
-     *  </p>
-     *
-     *@param  value        The value validation is being performed on.
-     *@param  datePattern  The pattern passed to <code>SimpleDateFormat</code>.
-     *@param  strict       Whether or not to have an exact match of the
-     *      datePattern.
-     *@return the converted Date value.
+     * <p>
+     * Checks if the field is a valid date. The pattern is used with <code>java.text.SimpleDateFormat</code>
+     * . If strict is true, then the length will be checked so '2/12/1999' will
+     * not pass validation with the format 'MM/dd/yyyy' because the month isn't
+     * two digits. The setLenient method is set to <code>false</code> for all.
+     * </p>
+     *
+     * @param value       The value validation is being performed on.
+     * @param datePattern The pattern passed to <code>SimpleDateFormat</code>.
+     * @param strict      Whether or not to have an exact match of the
+     *                    datePattern.
+     * @return the converted Date value.
      */
     public static Date formatDate(String value, String datePattern, boolean strict) {
         Date date = null;
 
         if (value == null
-             || datePattern == null
-             || datePattern.length() == 0) {
+                || datePattern == null
+                || datePattern.length() == 0) {
             return null;
         }
 
@@ -453,9 +454,9 @@ public class GenericTypeValidator implem
             // Bad date so return null
             Log log = LogFactory.getLog(GenericTypeValidator.class);
             if (log.isDebugEnabled()) {
-                log.debug("Date parse failed value=[" + value       + "], " +
-                                          "pattern=[" + datePattern + "], " +
-                                           "strict=[" + strict      + "] "  + e);
+                log.debug("Date parse failed value=[" + value + "], " +
+                        "pattern=[" + datePattern + "], " +
+                        "strict=[" + strict + "] " + e);
             }
         }
 
@@ -463,14 +464,14 @@ public class GenericTypeValidator implem
     }
 
     /**
-     *  <p>
-     *  Checks if the field is a valid credit card number.</p> <p>
-     *
-     *  Reference Sean M. Burke's <a href="http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl">
-     *  script</a> .</p>
+     * <p>
+     * Checks if the field is a valid credit card number.</p> <p>
+     * <p/>
+     * Reference Sean M. Burke's <a href="http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl">
+     * script</a> .</p>
      *
-     *@param  value  The value validation is being performed on.
-     *@return the converted Credit Card number.
+     * @param value The value validation is being performed on.
+     * @return the converted Credit Card number.
      */
     public static Long formatCreditCard(String value) {
         return GenericValidator.isCreditCard(value) ? new Long(value) : null;