commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1651811 - in /commons/proper/validator/trunk/src: example/org/apache/commons/validator/example/ main/java/org/apache/commons/validator/ main/java/org/apache/commons/validator/routines/ main/java/org/apache/commons/validator/util/ test/java...
Date Wed, 14 Jan 2015 20:30:23 GMT
Author: sebb
Date: Wed Jan 14 20:30:23 2015
New Revision: 1651811

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

Modified:
    commons/proper/validator/trunk/src/example/org/apache/commons/validator/example/ValidateExample.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/CreditCardValidator.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/FormSet.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResult.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResults.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ParameterTest.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ValidatorTest.java

Modified: commons/proper/validator/trunk/src/example/org/apache/commons/validator/example/ValidateExample.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/example/org/apache/commons/validator/example/ValidateExample.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/example/org/apache/commons/validator/example/ValidateExample.java
(original)
+++ commons/proper/validator/trunk/src/example/org/apache/commons/validator/example/ValidateExample.java
Wed Jan 14 20:30:23 2015
@@ -145,9 +145,9 @@ public class ValidateExample {
         System.out.println(bean);
 
         // Iterate over each of the properties of the Bean which had messages.
-        Iterator propertyNames = results.getPropertyNames().iterator();
+        Iterator<String> propertyNames = results.getPropertyNames().iterator();
         while (propertyNames.hasNext()) {
-            String propertyName = (String) propertyNames.next();
+            String propertyName = propertyNames.next();
 
             // Get the Field associated with that property in the Form
             Field field = form.getField(propertyName);
@@ -159,10 +159,10 @@ public class ValidateExample {
             ValidatorResult result = results.getValidatorResult(propertyName);
 
             // Get all the actions run against the property, and iterate over their names.
-            Map actionMap = result.getActionMap();
-            Iterator keys = actionMap.keySet().iterator();
+            Map<String, ?> actionMap = result.getActionMap();
+            Iterator<String> keys = actionMap.keySet().iterator();
             while (keys.hasNext()) {
-                String actName = (String) keys.next();
+                String actName = keys.next();
 
                 // Get the Action for that name.
                 ValidatorAction action = resources.getValidatorAction(actName);

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/CreditCardValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/CreditCardValidator.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/CreditCardValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/CreditCardValidator.java
Wed Jan 14 20:30:23 2015
@@ -18,7 +18,6 @@ package org.apache.commons.validator;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 
 import org.apache.commons.validator.util.Flags;
 
@@ -94,7 +93,7 @@ public class CreditCardValidator {
     /**
      * The CreditCardTypes that are allowed to pass validation.
      */
-    private final Collection cardTypes = new ArrayList();
+    private final Collection<CreditCardType> cardTypes = new ArrayList<CreditCardType>();
 
     /**
      * Create a new CreditCardValidator with default options.

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/FormSet.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/FormSet.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/FormSet.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/FormSet.java
Wed Jan 14 20:30:23 2015
@@ -59,13 +59,13 @@ public class FormSet implements Serializ
      * A <code>Map</code> of <code>Form</code>s using the name field
of the
      * <code>Form</code> as the key.
      */
-    private final Map forms = new HashMap();
+    private final Map<String, Form> forms = new HashMap<String, Form>();
 
     /**
      * A <code>Map</code> of <code>Constant</code>s using the name
field of the
      * <code>Constant</code> as the key.
      */
-    private final Map constants = new HashMap();
+    private final Map<String, String> constants = new HashMap<String, String>();
 
     /**
      * This is the type of <code>FormSet</code>s where no locale is specified.
@@ -151,8 +151,8 @@ public class FormSet implements Serializ
         if (depends != null) {
             Map pForms = getForms();
             Map dForms = depends.getForms();
-            for (Iterator it = dForms.entrySet().iterator(); it.hasNext(); ) {
-                Entry entry = (Entry) it.next();
+            for (Iterator<Entry> it = dForms.entrySet().iterator(); it.hasNext(); )
{
+                Entry entry = it.next();
                 Object key = entry.getKey();
                 Form pForm = (Form) pForms.get(key);
                 if (pForm != null) {//merge, but principal 'rules', don't overwrite
@@ -283,7 +283,7 @@ public class FormSet implements Serializ
      *
      * @return   The forms map
      */
-    public Map getForms() {
+    public Map<String, Form> getForms() {
         return Collections.unmodifiableMap(forms);
     }
 
@@ -293,8 +293,8 @@ public class FormSet implements Serializ
      * @param globalConstants  Global constants
      */
     synchronized void process(Map globalConstants) {
-        for (Iterator i = forms.values().iterator(); i.hasNext(); ) {
-            Form f = (Form) i.next();
+        for (Iterator<Form> i = forms.values().iterator(); i.hasNext(); ) {
+            Form f = i.next();
             f.process(globalConstants, constants, forms);
         }
 
@@ -349,7 +349,7 @@ public class FormSet implements Serializ
         results.append(variant);
         results.append("\n");
 
-        for (Iterator i = getForms().values().iterator(); i.hasNext(); ) {
+        for (Iterator<?> i = getForms().values().iterator(); i.hasNext(); ) {
             results.append("   ");
             results.append(i.next());
             results.append("\n");

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/UrlValidator.java
Wed Jan 14 20:30:23 2015
@@ -175,7 +175,7 @@ public class UrlValidator implements Ser
     /**
      * The set of schemes that are allowed to be in a URL.
      */
-    private final Set allowedSchemes = new HashSet();
+    private final Set<String> allowedSchemes = new HashSet<String>();
 
     /**
      * If no schemes are provided, default to this set.

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResult.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResult.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResult.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResult.java
Wed Jan 14 20:30:23 2015
@@ -36,7 +36,7 @@ public class ValidatorResult implements
      * Map of results.  The key is the name of the <code>ValidatorAction</code>
      * and the value is whether or not this field passed or not.
      */
-    protected Map hAction = new HashMap();
+    protected Map<String, ResultStatus> hAction = new HashMap<String, ResultStatus>();
 
     /**
      * <code>Field</code> being validated.
@@ -105,7 +105,7 @@ public class ValidatorResult implements
      * Return an Iterator of the action names contained in this Result.
      * @return The set of action names.
      */
-    public Iterator getActions() {
+    public Iterator<String> getActions() {
         return Collections.unmodifiableMap(hAction).keySet().iterator();
     }
 
@@ -117,7 +117,7 @@ public class ValidatorResult implements
      *             to determine the contents of ResultStatus.
      *
      */
-    public Map getActionMap() {
+    public Map<String, ResultStatus> getActionMap() {
         return Collections.unmodifiableMap(hAction);
     }
 

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResults.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResults.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResults.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResults.java
Wed Jan 14 20:30:23 2015
@@ -36,7 +36,7 @@ public class ValidatorResults implements
     /**
      * Map of validation results.
      */
-    protected Map hResults = new HashMap();
+    protected Map<String, ValidatorResult> hResults = new HashMap<String, ValidatorResult>();
 
     /**
      * Merge another ValidatorResults into mine.
@@ -118,7 +118,7 @@ public class ValidatorResults implements
      * been recorded.
      * @return An unmodifiable Set of the property names.
      */
-    public Set getPropertyNames() {
+    public Set<String> getPropertyNames() {
         return Collections.unmodifiableSet(this.hResults.keySet());
     }
 
@@ -128,15 +128,15 @@ public class ValidatorResults implements
      *
      * @return Map of objections returned by validators.
      */
-    public Map getResultValueMap() {
-        Map results = new HashMap();
+    public Map<String, Object> getResultValueMap() {
+        Map<String, Object> results = new HashMap<String, Object>();
 
-        for (Iterator i = hResults.keySet().iterator(); i.hasNext();) {
-            String propertyKey = (String) i.next();
+        for (Iterator<String> i = hResults.keySet().iterator(); i.hasNext();) {
+            String propertyKey = i.next();
             ValidatorResult vr = this.getValidatorResult(propertyKey);
 
-            for (Iterator x = vr.getActions(); x.hasNext();) {
-                String actionKey = (String)x.next();
+            for (Iterator<String> x = vr.getActions(); x.hasNext();) {
+                String actionKey = x.next();
                 Object result = vr.getResult(actionKey);
 
                 if (result != null && !(result instanceof Boolean)) {

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
Wed Jan 14 20:30:23 2015
@@ -123,16 +123,16 @@ public class InetAddressValidator implem
                 || (inet6Address.endsWith(":") && !inet6Address.endsWith("::")))
{
             return false;
         }
-        Object[] octets = inet6Address.split(":");
+        String[] octets = inet6Address.split(":");
         if (containsCompressedZeroes) {
-            List octetList = new ArrayList(Arrays.asList(octets));
+            List<String> octetList = new ArrayList<String>(Arrays.asList(octets));
             if (inet6Address.endsWith("::")) {
                 // String.split() drops ending empty segments
                 octetList.add("");
             } else if (inet6Address.startsWith("::") && !octetList.isEmpty()) {
                 octetList.remove(0);
             }
-            octets = octetList.toArray();
+            octets = octetList.toArray(new String[octetList.size()]);
         }
         if (octets.length > 8) {
             return false;

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
Wed Jan 14 20:30:23 2015
@@ -166,7 +166,7 @@ public class UrlValidator implements Ser
     /**
      * The set of schemes that are allowed to be in a URL.
      */
-    private final Set allowedSchemes; // Must be lower-case
+    private final Set<String> allowedSchemes; // Must be lower-case
 
     /**
      * Regular expressions used to manually validate authorities if IANA
@@ -258,12 +258,12 @@ public class UrlValidator implements Ser
         this.options = options;
 
         if (isOn(ALLOW_ALL_SCHEMES)) {
-            allowedSchemes = Collections.EMPTY_SET;
+            allowedSchemes = Collections.emptySet();
         } else {
             if (schemes == null) {
                 schemes = DEFAULT_SCHEMES;
             }
-            allowedSchemes = new HashSet(schemes.length);
+            allowedSchemes = new HashSet<String>(schemes.length);
             for(int i=0; i < schemes.length; i++) {
                 allowedSchemes.add(schemes[i].toLowerCase(Locale.ENGLISH));
             }

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java
Wed Jan 14 20:30:23 2015
@@ -120,7 +120,7 @@ public class ValidatorUtils {
             return ((String[]) value).length > 0 ? value.toString() : "";
 
         } else if (value instanceof Collection) {
-            return ((Collection) value).isEmpty() ? "" : value.toString();
+            return ((Collection<?>) value).isEmpty() ? "" : value.toString();
 
         } else {
             return value.toString();
@@ -143,9 +143,9 @@ public class ValidatorUtils {
     public static FastHashMap copyFastHashMap(FastHashMap map) {
         FastHashMap results = new FastHashMap();
 
-        Iterator i = map.entrySet().iterator();
+        Iterator<Entry<String, ?>> i = map.entrySet().iterator();
         while (i.hasNext()) {
-            Entry entry = (Entry) i.next();
+            Entry<String, ?> entry = i.next();
             String key = (String) entry.getKey();
             Object value = entry.getValue();
 
@@ -174,12 +174,12 @@ public class ValidatorUtils {
      * @return A copy of the <code>Map</code> that was passed in.
      */
     public static Map copyMap(Map map) {
-        Map results = new HashMap();
+        Map<String, ? super Object> results = new HashMap<String, Object>();
 
-        Iterator i = map.entrySet().iterator();
+        Iterator<Entry<String, ?>> i = map.entrySet().iterator();
         while (i.hasNext()) {
-            Entry entry = (Entry) i.next();
-            String key = (String) entry.getKey();
+            Entry<String, ?> entry = i.next();
+            String key = entry.getKey();
             Object value = entry.getValue();
 
             if (value instanceof Msg) {

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
Wed Jan 14 20:30:23 2015
@@ -89,7 +89,7 @@ public class GenericTypeValidatorTest ex
       
       assertNotNull("Results are null.", results);
       
-      Map hResultValues = results.getResultValueMap();
+      Map<String, ?> hResultValues = results.getResultValueMap();
 
       assertTrue("Expecting byte result to be an instance of Byte.", (hResultValues.get("byte")
instanceof Byte));
       assertTrue("Expecting short result to be an instance of Short.", (hResultValues.get("short")
instanceof Short));
@@ -98,8 +98,8 @@ public class GenericTypeValidatorTest ex
       assertTrue("Expecting float result to be an instance of Float.", (hResultValues.get("float")
instanceof Float));
       assertTrue("Expecting double result to be an instance of Double.", (hResultValues.get("double")
instanceof Double));
       
-      for (Iterator i = hResultValues.keySet().iterator(); i.hasNext(); ) {
-         String key = (String)i.next();
+      for (Iterator<String> i = hResultValues.keySet().iterator(); i.hasNext(); ) {
+         String key = i.next();
          Object value = hResultValues.get(key);
          
          assertNotNull("value ValidatorResults.getResultValueMap() should not be null.",
value);
@@ -181,8 +181,8 @@ public class GenericTypeValidatorTest ex
       assertTrue("Expecting double result to be an instance of Double for locale: "+locale,
(hResultValues.get("double") instanceof Double));
       assertTrue("Expecting date result to be an instance of Date for locale: "+locale, (hResultValues.get("date")
instanceof Date));
       
-      for (Iterator i = hResultValues.keySet().iterator(); i.hasNext(); ) {
-         String key = (String)i.next();
+      for (Iterator<String> i = hResultValues.keySet().iterator(); i.hasNext(); ) {
+         String key = i.next();
          Object value = hResultValues.get(key);
          
          assertNotNull("value ValidatorResults.getResultValueMap() should not be null for
locale: "+locale, value);

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
Wed Jan 14 20:30:23 2015
@@ -265,7 +265,7 @@ public class GenericValidatorImpl {
         return true;
     }
   
-  private static Class stringClass = new String().getClass();
+  private static Class<?> stringClass = new String().getClass();
 
   private static boolean isString(Object o) {
     if (o == null) {

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ParameterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ParameterTest.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ParameterTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ParameterTest.java
Wed Jan 14 20:30:23 2015
@@ -95,7 +95,7 @@ public class ParameterTest extends Abstr
     }
 
     private void assertParameterValue(Validator validator, String name,
-            Class type) {
+            Class<?> type) {
         Object value = validator.getParameterValue(name);
         assertNotNull("Expected '" + type.getName() + "' but was null", value);
         assertTrue("Expected '" + type.getName() + "' but was '" + value.getClass().getName()
+ "'",

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ValidatorTest.java?rev=1651811&r1=1651810&r2=1651811&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ValidatorTest.java
Wed Jan 14 20:30:23 2015
@@ -191,7 +191,7 @@ public class ValidatorTest extends TestC
       resources.addFormSet(fs);
       resources.process();
 
-      List l = new ArrayList();
+      List<?> l = new ArrayList<Object>();
 
       TestBean bean = new TestBean();  
       bean.setLetter("A");
@@ -223,7 +223,7 @@ public class ValidatorTest extends TestC
    /**
     * Checks if the field is one upper case letter between 'A' and 'Z'.
     */
-   public static boolean isCapLetter(Object bean, Field field, List l) {
+   public static boolean isCapLetter(Object bean, Field field, List<String> l) {
       String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
 
       if (value != null && value.length() == 1) {



Mime
View raw message