bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1765669 - /bval/trunk/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
Date Wed, 19 Oct 2016 16:04:07 GMT
Author: mbenson
Date: Wed Oct 19 16:04:07 2016
New Revision: 1765669

URL: http://svn.apache.org/viewvc?rev=1765669&view=rev
Log:
attempt to rewrite a confusing if block

Modified:
    bval/trunk/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java

Modified: bval/trunk/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
URL: http://svn.apache.org/viewvc/bval/trunk/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java?rev=1765669&r1=1765668&r2=1765669&view=diff
==============================================================================
--- bval/trunk/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java (original)
+++ bval/trunk/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java Wed Oct 19 16:04:07
2016
@@ -1057,19 +1057,25 @@ public class ClassValidator implements C
     }
 
     private <T> void initMetaBean(final GroupValidationContext<T> context, final
MetaBeanFinder metaBeanFinder, final Class<?> directValueClass) {
-        final boolean collection = Collection.class.isAssignableFrom(directValueClass);
-        final boolean map = Map.class.isAssignableFrom(directValueClass);
-        if (!directValueClass.isArray()
-                && (!collection || Collection.class.cast(context.getValidatedValue()).isEmpty())
-                && (!map || Map.class.cast(context.getValidatedValue()).isEmpty()))
{
-            context.setMetaBean(metaBeanFinder.findForClass(directValueClass));
-        } else if (collection) {
-            context.setMetaBean(metaBeanFinder.findForClass(Collection.class.cast(context.getValidatedValue()).iterator().next().getClass()));
-        } else if (map) {
-            context.setMetaBean(metaBeanFinder.findForClass(Map.class.cast(context.getValidatedValue()).values().iterator().next().getClass()));
-        } else {
+        if (directValueClass.isArray()) {
             context.setMetaBean(metaBeanFinder.findForClass(directValueClass.getComponentType()));
+            return;
         }
+        if (Collection.class.isAssignableFrom(directValueClass)) {
+            final Collection<?> coll = Collection.class.cast(context.getValidatedValue());
+            if (!coll.isEmpty()) {
+                context.setMetaBean(metaBeanFinder.findForClass(coll.iterator().next().getClass()));
+                return;
+            }
+        }
+        if (Map.class.isAssignableFrom(directValueClass)) {
+            final Map<?, ?> m = Map.class.cast(context.getValidatedValue());
+            if (!m.isEmpty()) {
+                context.setMetaBean(metaBeanFinder.findForClass(m.values().iterator().next().getClass()));
+                return;
+            }
+        }
+        context.setMetaBean(metaBeanFinder.findForClass(directValueClass));
     }
 
     /**



Mime
View raw message