commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1651913 - in /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator: Field.java Form.java ValidatorAction.java
Date Thu, 15 Jan 2015 00:42:07 GMT
Author: sebb
Date: Thu Jan 15 00:42:06 2015
New Revision: 1651913

URL: http://svn.apache.org/r1651913
Log:
Generics

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java?rev=1651913&r1=1651912&r2=1651913&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java (original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java Thu
Jan 15 00:42:06 2015
@@ -688,7 +688,9 @@ public class Field implements Cloneable,
             throw new RuntimeException(e.toString());
         }
 
-        field.args = new Map[this.args.length];
+        @SuppressWarnings("unchecked") // empty array always OK; cannot check this at compile
time
+        final Map<String, Arg>[] tempMap = new Map[this.args.length];
+        field.args = tempMap;
         for (int i = 0; i < this.args.length; i++) {
             if (this.args[i] == null) {
                 continue;
@@ -816,8 +818,8 @@ public class Field implements Cloneable,
     private boolean validateForRule(
         ValidatorAction va,
         ValidatorResults results,
-        Map actions,
-        Map params,
+        Map<String, ValidatorAction> actions,
+        Map<String, Object> params,
         int pos)
         throws ValidatorException {
 
@@ -847,7 +849,7 @@ public class Field implements Cloneable,
         ValidatorAction va,
         ValidatorResults results,
         Map<String, ValidatorAction> actions,
-        Map params,
+        Map<String, Object> params,
         int pos)
         throws ValidatorException {
 
@@ -885,7 +887,7 @@ public class Field implements Cloneable,
      * this field.
      * @throws ValidatorException If an error occurs during validation.
      */
-    public ValidatorResults validate(Map params, Map<String, ValidatorAction> actions)
+    public ValidatorResults validate(Map<String, Object> params, Map<String, ValidatorAction>
actions)
         throws ValidatorException {
 
         if (this.getDepends() == null) {
@@ -905,7 +907,7 @@ public class Field implements Cloneable,
             while (dependencies.hasNext()) {
                 String depend = dependencies.next();
 
-                ValidatorAction action = (ValidatorAction) actions.get(depend);
+                ValidatorAction action = actions.get(depend);
                 if (action == null) {
                     this.handleMissingAction(depend);
                 }

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java?rev=1651913&r1=1651912&r2=1651913&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java (original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java Thu
Jan 15 00:42:06 2015
@@ -243,8 +243,7 @@ public class Form implements Serializabl
      *      validation messages.
      * @throws ValidatorException
      */
-    // TODO difficult to add generics for params as the map may contain values with incompatible
classes
-    ValidatorResults validate(Map params, Map<String, ValidatorAction> actions, int
page)
+    ValidatorResults validate(Map<String, Object> params, Map<String, ValidatorAction>
actions, int page)
         throws ValidatorException {
         return validate(params, actions, page, null);
     }
@@ -263,15 +262,14 @@ public class Form implements Serializabl
      * @throws ValidatorException
      * @since 1.2.0
      */
-    ValidatorResults validate(Map<String, ? super Object> params, Map<String, ValidatorAction>
actions, int page, String fieldName)
+    ValidatorResults validate(Map<String, Object> params, Map<String, ValidatorAction>
actions, int page, String fieldName)
         throws ValidatorException {
-// TODO the params map contains both ValidatorResults and Field entries
         ValidatorResults results = new ValidatorResults();
         params.put(Validator.VALIDATOR_RESULTS_PARAM, results);
 
         // Only validate a single field if specified
         if (fieldName != null) {
-            Field field = (Field) getFieldMap().get(fieldName);
+            Field field = getFieldMap().get(fieldName);
 
             if (field == null) {
                throw new ValidatorException("Unknown field "+fieldName+" in form "+getName());

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java?rev=1651913&r1=1651912&r2=1651913&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java
Thu Jan 15 00:42:06 2015
@@ -520,7 +520,7 @@ public class ValidatorAction implements
         Field field,
         // TODO What is this the correct value type?
         // both ValidatorAction and Validator are added as parameters
-        Map params,
+        Map<String, Object> params,
         ValidatorResults results,
         int pos)
         throws ValidatorException {
@@ -761,9 +761,8 @@ public class ValidatorAction implements
     /**
      * Returns the ClassLoader set in the Validator contained in the parameter
      * Map.
-     * TODO expects Map to contain <String, Validator>
      */
-    private ClassLoader getClassLoader(Map params) {
+    private ClassLoader getClassLoader(Map<String, Object> params) {
         Validator v = (Validator) params.get(Validator.VALIDATOR_PARAM);
         return v.getClassLoader();
     }
@@ -771,9 +770,8 @@ public class ValidatorAction implements
     /**
      * Returns the onlyReturnErrors setting in the Validator contained in the
      * parameter Map.
-     * TODO expects Map to contain <String, Validator>
      */
-    private boolean onlyReturnErrors(Map params) {
+    private boolean onlyReturnErrors(Map<String, Object> params) {
         Validator v = (Validator) params.get(Validator.VALIDATOR_PARAM);
         return v.getOnlyReturnErrors();
     }



Mime
View raw message