bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r996993 - /incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
Date Tue, 14 Sep 2010 17:07:10 GMT
Author: mbenson
Date: Tue Sep 14 17:07:10 2010
New Revision: 996993

URL: http://svn.apache.org/viewvc?rev=996993&view=rev
Log:
javadoc/refactoring

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java?rev=996993&r1=996992&r2=996993&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
Tue Sep 14 17:07:10 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.bval.jsr303;
 
-
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 
@@ -30,26 +29,59 @@ import java.util.Set;
  * Description: MetaData class<br/>
  */
 public abstract class ElementDescriptorImpl implements ElementDescriptor {
+
+    /**
+     * Get a set of {@link ConstraintDescriptor}s from the specified array of
+     * {@link Validation}s.
+     * 
+     * @param validations
+     * @return {@link ConstraintDescriptor} set
+     */
+    protected static Set<ConstraintDescriptor<?>> getConstraintDescriptors(Validation[]
validations) {
+        final Set<ConstraintDescriptor<?>> result = new HashSet<ConstraintDescriptor<?>>(validations.length);
+        for (Validation validation : validations) {
+            if (validation instanceof ConstraintValidation<?>) {
+                result.add((ConstraintValidation<?>) validation);
+            }
+        }
+        return result;
+    }
+
+    /** the MetaBean of this element */
     protected final MetaBean metaBean;
+
+    /** the raw type of this element */
     protected final Class<?> elementClass;
+
     private Set<ConstraintDescriptor<?>> constraintDescriptors;
 
-    protected ElementDescriptorImpl(MetaBean metaBean, Class<?> elementClass, 
-                                 Validation[] validations) {
+    /**
+     * Create a new ElementDescriptorImpl instance.
+     * 
+     * @param metaBean
+     * @param elementClass
+     * @param validations
+     */
+    protected ElementDescriptorImpl(MetaBean metaBean, Class<?> elementClass, Validation[]
validations) {
         this.metaBean = metaBean;
         this.elementClass = elementClass;
-        createConstraintDescriptors(validations);
+        setConstraintDescriptors(getConstraintDescriptors(validations));
     }
 
+    /**
+     * Create a new ElementDescriptorImpl instance.
+     * 
+     * @param elementClass
+     * @param validations
+     */
     protected ElementDescriptorImpl(Class<?> elementClass, Validation[] validations)
{
-        this.metaBean = null;
-        this.elementClass = elementClass;
-        createConstraintDescriptors(validations);
+        this(null, elementClass, validations);
     }
 
     /**
      * {@inheritDoc}
-     *  @return Statically defined returned type.
+     * 
+     * @return Statically defined returned type.
      */
     public Class<?> getElementClass() {
         return elementClass;
@@ -60,7 +92,7 @@ public abstract class ElementDescriptorI
      */
     @SuppressWarnings("unchecked")
     public ElementDescriptor.ConstraintFinder findConstraints() {
-        return new ConstraintFinderImpl(metaBean, (Set) constraintDescriptors);
+        return new ConstraintFinderImpl(metaBean, (Set) getConstraintDescriptors());
     }
 
     /**
@@ -71,27 +103,18 @@ public abstract class ElementDescriptorI
     }
 
     /**
-     * {@inheritDoc}
-     * return true if at least one constraint declaration is present on the element.
+     * {@inheritDoc} return true if at least one constraint declaration is
+     * present on the element.
      */
     public boolean hasConstraints() {
-        return !constraintDescriptors.isEmpty();
-    }
-
-    private void createConstraintDescriptors(Validation[] validations) {
-        final Set<ConstraintDescriptor<?>> cds = new HashSet<ConstraintDescriptor<?>>(validations.length);
-        for (Validation validation : validations) {
-            if (validation instanceof ConstraintValidation<?>) {
-                ConstraintValidation<?> cval = (ConstraintValidation<?>) validation;
-                cds.add(cval);
-            }
-        }
-        setConstraintDescriptors(cds);
+        return !getConstraintDescriptors().isEmpty();
     }
 
     /**
      * Set the constraintDescriptors for this element.
-     * @param constraintDescriptors to set
+     * 
+     * @param constraintDescriptors
+     *            to set
      */
     public void setConstraintDescriptors(Set<ConstraintDescriptor<?>> constraintDescriptors)
{
         this.constraintDescriptors = constraintDescriptors;
@@ -99,6 +122,7 @@ public abstract class ElementDescriptorI
 
     /**
      * Get the model {@link MetaBean} used.
+     * 
      * @return MetaBean
      */
     public MetaBean getMetaBean() {



Mime
View raw message