tandraschko commented on code in PR #275:
URL: https://github.com/apache/bval/pull/275#discussion_r4184417888


##########
bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/BeanD.java:
##########
@@ -141,6 +161,93 @@ public GroupStrategy getGroupStrategy() {
         return groupStrategy;
     }
 
+    /**
+     * Get {@code groups} with {@link Group#DEFAULT} redefined as this bean's 
default group sequence. Returns
+     * {@code groups} itself (same instance) when no redefinition applies.
+     *
+     * @param groups
+     * @return {@link GroupStrategy}
+     */
+    @Override
+    public GroupStrategy getLocalGroupStrategy(GroupStrategy groups) {
+        GroupStrategy result = localGroupStrategies.get(groups);
+        if (result == null) {
+            final GroupStrategy computed =
+                GroupStrategy.redefining(groups, 
Collections.singletonMap(Group.DEFAULT, groupStrategy));
+            result = localGroupStrategies.putIfAbsent(groups, computed == 
groups ? UNCHANGED : computed);
+        }
+        return result == UNCHANGED ? groups : result;
+    }
+
+    /**
+     * What validating this bean for a requested group strategy involves.
+     */
+    public static final class GroupPlan {
+        private final GroupStrategy localGroupStrategy;
+        private final PropertyD<?>[] properties;
+
+        GroupPlan(GroupStrategy localGroupStrategy, PropertyD<?>[] properties) 
{
+            this.localGroupStrategy = localGroupStrategy;
+            this.properties = properties;
+        }
+
+        /**
+         * @param groups the requested strategy this plan was obtained for
+         * @return {@link BeanD#getLocalGroupStrategy(GroupStrategy)} of 
{@code groups}
+         */
+        public GroupStrategy getLocalGroupStrategy(GroupStrategy groups) {
+            return localGroupStrategy == null ? groups : localGroupStrategy;
+        }
+
+        /**
+         * @return the leaf properties that need a validation frame for the 
local group strategy; must not be modified
+         */
+        public PropertyD<?>[] getProperties() {
+            return properties;
+        }
+    }
+
+    /**
+     * Get the {@link GroupPlan} for validating this bean for {@code groups}, 
combining
+     * {@link #getLocalGroupStrategy(GroupStrategy)} and the properties that 
need a validation frame in one lookup.
+     *
+     * @param groups
+     * @return {@link GroupPlan}
+     */
+    public GroupPlan getPlan(GroupStrategy groups) {
+        final GroupPlan cached = plans.get(groups);
+        if (cached != null) {
+            return cached;
+        }
+        final GroupStrategy local = getLocalGroupStrategy(groups);

Review Comment:
   I usally use computeIfAbsent in this case, saves a call to the method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to