incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1029847 - /incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java
Date Mon, 01 Nov 2010 21:28:31 GMT
Author: mbenson
Date: Mon Nov  1 21:28:30 2010
New Revision: 1029847

URL: http://svn.apache.org/viewvc?rev=1029847&view=rev
Log:
NullValue appender was incorrectly merging to parent groups

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java?rev=1029847&r1=1029846&r2=1029847&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java
Mon Nov  1 21:28:30 2010
@@ -41,10 +41,10 @@ import javax.validation.ConstraintValida
 import javax.validation.Payload;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Null;
+import javax.validation.groups.Default;
 
 import org.apache.bval.jsr303.dynamic.ConstraintAppender;
-import org.apache.bval.jsr303.groups.Group;
-import org.apache.bval.jsr303.groups.Groups;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.proxy2.stub.AnnotationFactory;
 import org.apache.commons.proxy2.stub.StubConfigurer;
@@ -236,34 +236,37 @@ public @interface NullValue {
         }
 
         private static void addRulesByGroup(Map<Class<?>, Rule> toMap, NullValue
fromConstraint) {
-            Groups groups = GROUPS_COMPUTER.computeGroups(fromConstraint.groups());
-            for (Group g : groups.getGroups()) {
+            for (Class<?> group : groups(fromConstraint)) {
                 Rule particle = fromConstraint.value();
-                if (particle == Rule.ALLOW && toMap.containsKey(g.getGroup())) {
-                    if (toMap.get(g.getGroup()) != particle) {
-                        //mutual annihilation: ALLOW + any other == none
-                        toMap.remove(g.getGroup());
+                if (particle == Rule.ALLOW && toMap.containsKey(group)) {
+                    if (toMap.get(group) != particle) {
+                        // mutual annihilation: ALLOW + any other == none
+                        toMap.remove(group);
                     }
                     continue;
                 }
-                toMap.put(g.getGroup(), particle);
+                toMap.put(group, particle);
             }
         }
 
         private static void addConstraintByGroup(Map<Class<?>, Set<NullValue>>
toMap, NullValue constraint,
             Map<Class<?>, Rule> rulesByGroup) {
-            Groups groups = GROUPS_COMPUTER.computeGroups(constraint.groups());
-            for (Group g : groups.getGroups()) {
-                if (constraint.value() != rulesByGroup.get(g.getGroup())) {
+            for (Class<?> group : groups(constraint)) {
+                if (constraint.value() != rulesByGroup.get(group)) {
                     continue;
                 }
-                Set<NullValue> set = toMap.get(g.getGroup());
+                Set<NullValue> set = toMap.get(group);
                 if (set == null) {
                     set = new HashSet<NullValue>();
-                    toMap.put(g.getGroup(), set);
+                    toMap.put(group, set);
                 }
                 set.add(constraint);
             }
         }
+        
+        private static Class<?>[] groups(NullValue fromConstraint) {
+            Class<?>[] result = fromConstraint.groups();
+            return ArrayUtils.isEmpty(result) ? ArrayUtils.<Class<?>> toArray(Default.class)
: result;
+        }
     }
 }



Mime
View raw message