bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1649714 - in /bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr: ConstraintDefaults.java ConstraintDescriptorImpl.java ConstraintFinderImpl.java ConstraintValidation.java
Date Tue, 06 Jan 2015 02:17:25 GMT
Author: mbenson
Date: Tue Jan  6 02:17:24 2015
New Revision: 1649714

URL: http://svn.apache.org/r1649714
Log:
cleanup

Modified:
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDescriptorImpl.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintFinderImpl.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java?rev=1649714&r1=1649713&r2=1649714&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
Tue Jan  6 02:17:24 2015
@@ -23,15 +23,16 @@ import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.validation.ConstraintValidator;
 
 import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.weaver.privilizer.Privilizing;
 import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
 
@@ -42,13 +43,12 @@ import org.apache.commons.weaver.privili
 @Privilizing(@CallTo(Reflection.class))
 public class ConstraintDefaults {
     private static final Logger log = Logger.getLogger(ConstraintDefaults.class.getName());
-    private static final String DEFAULT_CONSTRAINTS =
-          "org/apache/bval/jsr/DefaultConstraints.properties";
+    private static final String DEFAULT_CONSTRAINTS = "org/apache/bval/jsr/DefaultConstraints.properties";
     
     /**
      * The default constraint data stored herein.
      */
-    protected Map<String, Class<? extends ConstraintValidator<?, ?>>[]>
defaultConstraints;
+    private Map<String, Class<? extends ConstraintValidator<?, ?>>[]> defaultConstraints;
 
     /**
      * Create a new ConstraintDefaults instance.
@@ -78,10 +78,12 @@ public class ConstraintDefaults {
 
     @SuppressWarnings("unchecked")
     private Map<String, Class<? extends ConstraintValidator<?, ?>>[]> loadDefaultConstraints(String
resource) {
-        Properties constraintProperties = new Properties();
+        final Properties constraintProperties = new Properties();
         final ClassLoader classloader = getClassLoader();
-        InputStream stream = classloader.getResourceAsStream(resource);
-        if (stream != null) {
+        final InputStream stream = classloader.getResourceAsStream(resource);
+        if (stream == null) {
+            log.log(Level.WARNING, String.format("Cannot find %s", resource));
+        } else {
             try {
                 constraintProperties.load(stream);
             } catch (IOException e) {
@@ -93,33 +95,27 @@ public class ConstraintDefaults {
                     // no-op
                 }
             }
-        } else {
-            log.log(Level.WARNING, String.format("Cannot find %s", resource));
         }
 
-        final Map<String, Class<? extends ConstraintValidator<?, ?>>[]>
loadedConstraints = new HashMap<String, Class<? extends ConstraintValidator<?,?>>[]>();
-        for (final Map.Entry<Object, Object> entry : constraintProperties.entrySet())
{
-
-            final StringTokenizer tokens = new StringTokenizer((String) entry.getValue(),
", ");
-            final LinkedList<Class<?>> classes = new LinkedList<Class<?>>();
-            while (tokens.hasMoreTokens()) {
-                final String eachClassName = tokens.nextToken();
+        final Map<String, Class<? extends ConstraintValidator<?, ?>>[]>
loadedConstraints =
+            new HashMap<String, Class<? extends ConstraintValidator<?, ?>>[]>();
 
+        for (final Map.Entry<Object, Object> entry : constraintProperties.entrySet())
{
+            final List<Class<?>> classes = new LinkedList<Class<?>>();
+            for (String className : StringUtils.split((String) entry.getValue(), ',')) {
                 try {
-                    classes.add(Reflection.getClass(classloader, eachClassName));
+                    classes.add(Reflection.getClass(classloader, className.trim()));
                 } catch (Exception e) {
-                    log.log(Level.SEVERE, String.format("Cannot find class %s", eachClassName),
e);
+                    log.log(Level.SEVERE, String.format("Cannot find class %s", className),
e);
                 }
             }
-
             loadedConstraints.put((String) entry.getKey(), classes.toArray(new Class[classes.size()]));
         }
         return loadedConstraints;
     }
 
     private ClassLoader getClassLoader() {
-        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
-        if (classloader == null) classloader = getClass().getClassLoader();
-        return classloader;
+        final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+        return classloader == null ? getClass().getClassLoader() : classloader;
     }
 }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDescriptorImpl.java?rev=1649714&r1=1649713&r2=1649714&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDescriptorImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDescriptorImpl.java
Tue Jan  6 02:17:24 2015
@@ -21,6 +21,10 @@ package org.apache.bval.jsr;
 import javax.validation.ConstraintTarget;
 import javax.validation.Payload;
 import javax.validation.metadata.ConstraintDescriptor;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.util.List;
@@ -28,8 +32,8 @@ import java.util.Map;
 import java.util.Set;
 
 /**
- * Description: immutable, serializable implementation of ConstraintDescriptor
- * interface of JSR303<br>
+ * Immutable, {@link Serializable} {@link ConstraintDescriptor} implementation.
+ *
  * User: roman.stumm<br>
  * Date: 22.04.2010<br>
  * Time: 10:21:23<br>
@@ -147,24 +151,27 @@ public class ConstraintDescriptorImpl<T
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
+        if (this == o) {
+            return true;
+        }
+        if (o == null || !getClass().equals(o.getClass())) {
+            return false;
+        }
 
+        @SuppressWarnings("rawtypes")
         final ConstraintDescriptorImpl that = (ConstraintDescriptorImpl) o;
 
-        if (reportAsSingleViolation != that.reportAsSingleViolation) return false;
-        if (!annotation.annotationType().equals(that.annotation.annotationType())) return
false;
-        if (attributes != null ? !attributes.equals(that.attributes) : that.attributes !=
null) return false;
-        if (composingConstraints != null ? !composingConstraints.equals(that.composingConstraints)
: that.composingConstraints != null)
-            return false;
-        if (constraintValidatorClasses != null ? !constraintValidatorClasses.equals(that.constraintValidatorClasses)
: that.constraintValidatorClasses != null)
-            return false;
-        if (groups != null ? !groups.equals(that.groups) : that.groups != null) return false;
-        if (payload != null ? !payload.equals(that.payload) : that.payload != null) return
false;
-        if (template != null ? !template.equals(that.template) : that.template != null) return
false;
-        if (validationAppliesTo != that.validationAppliesTo) return false;
-
-        return true;
+        return new EqualsBuilder()
+            .append(reportAsSingleViolation, that.reportAsSingleViolation)
+            .append(annotation.annotationType(), that.annotation.annotationType())
+            .append(attributes, that.attributes)
+            .append(composingConstraints, that.composingConstraints)
+            .append(constraintValidatorClasses, that.constraintValidatorClasses)
+            .append(groups, that.groups)
+            .append(payload, that.payload)
+            .append(template, that.template)
+            .append(validationAppliesTo, that.validationAppliesTo)
+            .build();
     }
 
     @Override
@@ -172,16 +179,17 @@ public class ConstraintDescriptorImpl<T
         return hashCode;
     }
 
-    public int computeHashCode() {
-        int result = annotation.annotationType().hashCode();
-        result = 31 * result + (groups != null ? groups.hashCode() : 0);
-        result = 31 * result + (payload != null ? payload.hashCode() : 0);
-        result = 31 * result + (constraintValidatorClasses != null ? constraintValidatorClasses.hashCode()
: 0);
-        result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
-        result = 31 * result + (composingConstraints != null ? composingConstraints.hashCode()
: 0);
-        result = 31 * result + (reportAsSingleViolation ? 1 : 0);
-        result = 31 * result + (validationAppliesTo != null ? validationAppliesTo.hashCode()
: 0);
-        result = 31 * result + (template != null ? template.hashCode() : 0);
-        return result;
+    private int computeHashCode() {
+        return new HashCodeBuilder(1, 31)
+            .append(annotation.annotationType())
+            .append(groups)
+            .append(payload)
+            .append(constraintValidatorClasses)
+            .append(attributes)
+            .append(composingConstraints)
+            .append(reportAsSingleViolation)
+            .append(validationAppliesTo)
+            .append(template)
+            .build();
     }
 }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintFinderImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintFinderImpl.java?rev=1649714&r1=1649713&r2=1649714&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintFinderImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintFinderImpl.java
Tue Jan  6 02:17:24 2015
@@ -59,14 +59,13 @@ final class ConstraintFinderImpl impleme
      * {@inheritDoc}
      */
     public ElementDescriptor.ConstraintFinder unorderedAndMatchingGroups(Class<?>...
groups) {
-        Set<ConstraintValidation<?>> matchingDescriptors =
+        final Set<ConstraintValidation<?>> matchingDescriptors =
             new HashSet<ConstraintValidation<?>>(constraintDescriptors.size());
-        Groups groupChain = new GroupsComputer().computeGroups(groups);
+        final Groups groupChain = new GroupsComputer().computeGroups(groups);
         for (Group group : groupChain.getGroups()) {
             if (group.isDefault()) {
                 // If group is default, check if it gets redefined
-                List<Group> expandedDefaultGroup = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
-                for (Group defaultGroupMember : expandedDefaultGroup) {
+                for (Group defaultGroupMember : metaBean.<List<Group>>getFeature(JsrFeatures.Bean.GROUP_SEQUENCE))
{
                     for (ConstraintValidation<?> descriptor : constraintDescriptors)
{
                         if (isInScope(descriptor) && isInGroup(descriptor, defaultGroupMember))
{
                             matchingDescriptors.add(descriptor);
@@ -88,11 +87,10 @@ final class ConstraintFinderImpl impleme
      * {@inheritDoc}
      */
     public ElementDescriptor.ConstraintFinder lookingAt(Scope scope) {
-        if (scope.equals(Scope.LOCAL_ELEMENT)) {
+        if (scope == Scope.LOCAL_ELEMENT) {
             findInScopes.remove(Scope.HIERARCHY);
             for (Iterator<ConstraintValidation<?>> it = constraintDescriptors.iterator();
it.hasNext();) {
-                ConstraintValidation<?> cv = it.next();
-                if (cv.getOwner() != metaBean.getBeanClass()) {
+                if (!it.next().getOwner().equals(metaBean.getBeanClass())) {
                     it.remove();
                 }
             }
@@ -104,7 +102,7 @@ final class ConstraintFinderImpl impleme
      * {@inheritDoc}
      */
     public ElementDescriptor.ConstraintFinder declaredOn(ElementType... elementTypes) {
-        Set<ConstraintValidation<?>> matchingDescriptors =
+        final Set<ConstraintValidation<?>> matchingDescriptors =
             new HashSet<ConstraintValidation<?>>(constraintDescriptors.size());
         for (ElementType each : elementTypes) {
             for (ConstraintValidation<?> descriptor : constraintDescriptors) {
@@ -122,19 +120,23 @@ final class ConstraintFinderImpl impleme
 
     private boolean isInScope(ConstraintValidation<?> descriptor) {
         if (findInScopes.size() == Scope.values().length)
+         {
             return true; // all scopes
+        }
         if (metaBean != null) {
-            Class<?> owner = descriptor.getOwner();
+            final boolean isOwner = descriptor.getOwner().equals(metaBean.getBeanClass());
             for (Scope scope : findInScopes) {
                 switch (scope) {
-                case LOCAL_ELEMENT:
-                    if (owner.equals(metaBean.getBeanClass()))
-                        return true;
-                    break;
-                case HIERARCHY:
-                    if (!owner.equals(metaBean.getBeanClass()))
-                        return true;
-                    break;
+                    case LOCAL_ELEMENT:
+                        if (isOwner) {
+                            return true;
+                        }
+                        break;
+                    case HIERARCHY:
+                        if (!isOwner) {
+                            return true;
+                        }
+                        break;
                 }
             }
         }
@@ -157,7 +159,7 @@ final class ConstraintFinderImpl impleme
         if (constraintDescriptors.isEmpty()) {
             return Collections.emptySet();
         }
-        return Collections.<ConstraintDescriptor<?>>unmodifiableSet(constraintDescriptors);
+        return Collections.<ConstraintDescriptor<?>> unmodifiableSet(constraintDescriptors);
     }
 
     /**

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java?rev=1649714&r1=1649713&r2=1649714&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
Tue Jan  6 02:17:24 2015
@@ -26,6 +26,7 @@ import org.apache.bval.model.ValidationL
 import org.apache.bval.util.AccessStrategy;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.reflect.TypeUtils;
 
 import javax.validation.ConstraintDefinitionException;
@@ -38,6 +39,7 @@ import javax.validation.ValidationExcept
 import javax.validation.constraintvalidation.SupportedValidationTarget;
 import javax.validation.constraintvalidation.ValidationTarget;
 import javax.validation.metadata.ConstraintDescriptor;
+
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
@@ -179,7 +181,7 @@ public class ConstraintValidation<T exte
         if (!isMemberOf(context.getCurrentGroup().getGroup())) {
             return; // do not validate in the current group
         }
-        if (context.getCurrentOwner() != null && this.owner != context.getCurrentOwner())
{
+        if (context.getCurrentOwner() != null && !this.owner.equals(context.getCurrentOwner()))
{
             return;
         }
         if (validator != null && !context.collectValidated(validator))
@@ -191,14 +193,15 @@ public class ConstraintValidation<T exte
 
         // process composed constraints
         if (isReportAsSingleViolation()) {
-            ConstraintValidationListener<?> listener = context.getListener();
+            final ConstraintValidationListener<?> listener = context.getListener();
             listener.beginReportAsSingle();
 
             boolean failed = listener.hasViolations();
             try {
                 // stop validating when already failed and
                 // ReportAsSingleInvalidConstraint = true ?
-                for (Iterator<ConstraintValidation<?>> composed = getComposingValidations().iterator();
!failed && composed.hasNext(); ) {
+                for (Iterator<ConstraintValidation<?>> composed = getComposingValidations().iterator();
!failed
+                    && composed.hasNext();) {
                     composed.next().validate(context);
                     failed = listener.hasViolations();
                 }
@@ -210,8 +213,7 @@ public class ConstraintValidation<T exte
 
             if (failed) {
                 // TODO RSt - how should the composed constraint error report look like?
-                ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context,
this);
-                addErrors(context, jsrContext); // add defaultErrorMessage only
+                addErrors(context, new ConstraintValidatorContextImpl(context, this)); //
add defaultErrorMessage only
                 return;
             }
         } else {
@@ -224,19 +226,19 @@ public class ConstraintValidation<T exte
         }
 
         if (validator != null) {
-            ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context,
this);
             @SuppressWarnings("unchecked")
             final ConstraintValidator<T, Object> objectValidator = (ConstraintValidator<T,
Object>) validator;
+            final ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context,
this);
             if (!objectValidator.isValid(context.getValidatedValue(), jsrContext)) {
                 addErrors(context, jsrContext);
             }
         }
     }
 
-    private <A extends Annotation, T> ConstraintValidator<A, ? super T> getConstraintValidator(A
annotation,
+    private <A extends Annotation> ConstraintValidator<A, ? super T> getConstraintValidator(A
annotation,
         Class<? extends ConstraintValidator<A, ?>>[] constraintClasses, Class<?>
owner, AccessStrategy access) {
-        if (constraintClasses != null && constraintClasses.length > 0) {
-            Type type = determineTargetedType(owner, access);
+        if (ArrayUtils.isNotEmpty(constraintClasses)) {
+            final Type type = determineTargetedType(owner, access);
 
             /**
              * spec says in chapter 3.5.3.: The ConstraintValidator chosen to
@@ -254,8 +256,10 @@ public class ConstraintValidation<T exte
             reduceAssignableTypes(assignableTypes);
             checkOneType(assignableTypes, type, owner, annotation, access);
 
-            if ((type == Object.class || type == Object[].class) && validatorTypes.containsKey(Object.class)
&& validatorTypes.containsKey(Object[].class)) {
-                throw new ConstraintDefinitionException("Only a validator for Object or Object[]
should be provided for cross parameter validators");
+            if ((type.equals(Object.class) || type.equals(Object[].class)) && validatorTypes.containsKey(Object.class)
+                && validatorTypes.containsKey(Object[].class)) {
+                throw new ConstraintDefinitionException(
+                    "Only a validator for Object or Object[] should be provided for cross-parameter
validators");
             }
 
             final Collection<Class<? extends ConstraintValidator<A, ?>>>
key = validatorTypes.get(assignableTypes.get(0));
@@ -307,7 +311,7 @@ public class ConstraintValidation<T exte
     }
 
     private static void checkOneType(List<Type> types, Type targetType, Class<?>
owner, Annotation anno,
-                                     AccessStrategy access) {
+        AccessStrategy access) {
 
         if (types.isEmpty()) {
             final String message = "No validator could be found for type " + stringForType(targetType)
@@ -316,48 +320,28 @@ public class ConstraintValidation<T exte
                 throw new ConstraintDefinitionException(message);
             }
             throw new UnexpectedTypeException(message);
-        } else if (types.size() > 1) {
-            StringBuilder buf = new StringBuilder();
-            buf.append("Ambiguous validators for type ");
-            buf.append(stringForType(targetType));
-            buf.append(". See: @").append(anno.annotationType().getSimpleName()).append("
at ").append(
-                stringForLocation(owner, access));
-            buf.append(". Validators are: ");
-            boolean comma = false;
-            for (Type each : types) {
-                if (comma)
-                    buf.append(", ");
-                comma = true;
-                buf.append(each);
-            }
-            throw new UnexpectedTypeException(buf.toString());
+        }
+        if (types.size() > 1) {
+            throw new UnexpectedTypeException(String.format(
+                "Ambiguous validators for type %s. See: @%s at %s. Validators are: %s", stringForType(targetType),
anno
+                    .annotationType().getSimpleName(), stringForLocation(owner, access),
StringUtils.join(types, ", ")));
         }
     }
 
     private static String stringForType(Type clazz) {
         if (clazz instanceof Class<?>) {
-            if (((Class<?>) clazz).isArray()) {
-                return ((Class<?>) clazz).getComponentType().getName() + "[]";
-            } else {
-                return ((Class<?>) clazz).getName();
-            }
-        } else {
-            return clazz.toString();
+            return ((Class<?>) clazz).isArray() ? ((Class<?>) clazz).getComponentType().getName()
+ "[]" : ((Class<?>) clazz).getName();
         }
+        return clazz.toString();
     }
 
     private static String stringForLocation(Class<?> owner, AccessStrategy access)
{
-        if (access != null) {
-            return access.toString();
-        } else {
-            return owner.getName();
-        }
+        return access == null ? owner.getName() : access.toString();
     }
 
     private static void fillAssignableTypes(Type type, Set<Type> validatorsTypes, List<Type>
suitableTypes) {
         for (final Type validatorType : validatorsTypes) {
-            if (org.apache.commons.lang3.reflect.TypeUtils.isAssignable(type, validatorType)
-                && !suitableTypes.contains(validatorType)) {
+            if (TypeUtils.isAssignable(type, validatorType) && !suitableTypes.contains(validatorType))
{
                 suitableTypes.add(validatorType);
             }
         }
@@ -374,12 +358,11 @@ public class ConstraintValidation<T exte
         if (assignableTypes.size() <= 1) {
             return; // no need to reduce
         }
-        boolean removed;
+        boolean removed = false;
         do {
-            removed = false;
             final Type type = assignableTypes.get(0);
             for (int i = 1; i < assignableTypes.size(); i++) {
-                Type nextType = assignableTypes.get(i);
+                final Type nextType = assignableTypes.get(i);
                 if (TypeUtils.isAssignable(nextType, type)) {
                     assignableTypes.remove(0);
                     i--;
@@ -390,19 +373,21 @@ public class ConstraintValidation<T exte
                 }
             }
         } while (removed && assignableTypes.size() > 1);
-
     }
 
     private static <A extends Annotation> Map<Type, Collection<Class<? extends
ConstraintValidator<A, ?>>>> getValidatorsTypes(
         Class<? extends ConstraintValidator<A, ?>>[] constraintValidatorClasses)
{
-        final Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>>
validatorsTypes = new HashMap<Type, Collection<Class<? extends ConstraintValidator<A,
?>>>>();
+        final Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>>
validatorsTypes =
+            new HashMap<Type, Collection<Class<? extends ConstraintValidator<A,
?>>>>();
         for (Class<? extends ConstraintValidator<A, ?>> validatorType : constraintValidatorClasses)
{
-            Type validatedType = TypeUtils.getTypeArguments(validatorType, ConstraintValidator.class).get(ConstraintValidator.class.getTypeParameters()[1]);
+            Type validatedType =
+                TypeUtils.getTypeArguments(validatorType, ConstraintValidator.class).get(
+                    ConstraintValidator.class.getTypeParameters()[1]);
             if (validatedType == null) {
                 throw new ValidationException(String.format("Could not detect validated type
for %s", validatorType));
             }
             if (validatedType instanceof GenericArrayType) {
-                Type componentType = TypeUtils.getArrayComponentType(validatedType);
+                final Type componentType = TypeUtils.getArrayComponentType(validatedType);
                 if (componentType instanceof Class<?>) {
                     validatedType = Array.newInstance((Class<?>) componentType, 0).getClass();
                 }
@@ -421,14 +406,14 @@ public class ConstraintValidation<T exte
     private static Type determineTargetedType(Class<?> owner, AccessStrategy access)
{
         // if the constraint declaration is hosted on a class or an interface,
         // the targeted type is the class or the interface.
-        if (access == null)
+        if (access == null) {
             return owner;
-        Type type = access.getJavaType();
-        if (type == null)
+        }
+        final Type type = access.getJavaType();
+        if (type == null) {
             return Object.class;
-        if (type instanceof Class<?>)
-            type = ClassUtils.primitiveToWrapper((Class<?>) type);
-        return type;
+        }
+        return type instanceof Class<?> ? ClassUtils.primitiveToWrapper((Class<?>)
type) : type;
     }
 
     /**
@@ -459,12 +444,12 @@ public class ConstraintValidation<T exte
         }
         try {
             if (!context.getTraversableResolver().isReachable(context.getBean(), node,
-                context.getRootMetaBean().getBeanClass(), beanPath, access.getElementType()))
+                context.getRootMetaBean().getBeanClass(), beanPath, access.getElementType()))
{
                 return false;
+            }
         } catch (RuntimeException e) {
             throw new ValidationException("Error in TraversableResolver.isReachable() for
" + context.getBean(), e);
         }
-
         return true;
     }
 
@@ -538,9 +523,8 @@ public class ConstraintValidation<T exte
      *
      * @return {@link Set} of {@link ConstraintValidation}
      */
-    @SuppressWarnings("unchecked")
     Set<ConstraintValidation<?>> getComposingValidations() {
-        return composedConstraints == null ? Collections.EMPTY_SET : composedConstraints;
+        return composedConstraints == null ? Collections.<ConstraintValidation<?>>
emptySet() : composedConstraints;
     }
 
     /**
@@ -565,10 +549,7 @@ public class ConstraintValidation<T exte
      * {@inheritDoc}
      */
     public List<Class<? extends ConstraintValidator<T, ?>>> getConstraintValidatorClasses()
{
-        if (validatorClasses == null) {
-            return Collections.emptyList();
-        }
-        return Arrays.asList(validatorClasses);
+        return validatorClasses == null ? Collections.<Class<? extends ConstraintValidator<T,
?>>> emptyList() : Arrays.asList(validatorClasses);
     }
 
     public void setValidationAppliesTo(final ConstraintTarget validationAppliesTo) {



Mime
View raw message