You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2018/03/16 22:59:02 UTC
[02/12] bval git commit: ExecutableTypes utility class
ExecutableTypes utility class
Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/47cfebea
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/47cfebea
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/47cfebea
Branch: refs/heads/bv2
Commit: 47cfebeac0baf42a6b5903a4c3d6837d8f220294
Parents: 433e42b
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 15 15:23:33 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 15 15:23:33 2018 -0500
----------------------------------------------------------------------
.../bval/jsr/BootstrapConfigurationImpl.java | 26 +------
.../apache/bval/jsr/util/ExecutableTypes.java | 82 ++++++++++++++++++++
.../apache/bval/jsr/xml/ValidationParser.java | 3 +-
3 files changed, 87 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/bval/blob/47cfebea/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
index f7a11a3..3871b90 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/BootstrapConfigurationImpl.java
@@ -26,29 +26,11 @@ import java.util.Set;
import javax.validation.BootstrapConfiguration;
import javax.validation.executable.ExecutableType;
-public class BootstrapConfigurationImpl implements BootstrapConfiguration {
- public static final Set<ExecutableType> DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES =
- Collections.unmodifiableSet(EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS));
+import org.apache.bval.jsr.util.ExecutableTypes;
+public class BootstrapConfigurationImpl implements BootstrapConfiguration {
public static final BootstrapConfigurationImpl DEFAULT = new BootstrapConfigurationImpl(Collections.emptySet(),
- true, BootstrapConfigurationImpl.DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES, Collections.emptyMap(),
- Collections.emptySet());
-
- private static Set<ExecutableType> expandExecutableValidation(Set<ExecutableType> executableTypes) {
- if (executableTypes == DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES) {
- return executableTypes;
- }
- executableTypes = EnumSet.copyOf(executableTypes);
- if (executableTypes.contains(ExecutableType.ALL)) {
- executableTypes.clear();
- executableTypes.add(ExecutableType.CONSTRUCTORS);
- executableTypes.add(ExecutableType.NON_GETTER_METHODS);
- executableTypes.add(ExecutableType.GETTER_METHODS);
- } else if (executableTypes.contains(ExecutableType.NONE)) { // if both are present ALL trumps NONE
- executableTypes.clear();
- }
- return Collections.unmodifiableSet(executableTypes);
- }
+ true, EnumSet.of(ExecutableType.IMPLICIT), Collections.emptyMap(), Collections.emptySet());
private final Set<String> constraintMappingResourcePaths;
private final boolean executableValidationEnabled;
@@ -71,7 +53,7 @@ public class BootstrapConfigurationImpl implements BootstrapConfiguration {
final String clockProviderClassName, final Set<String> valueExtractorClassNames) {
this(Collections.unmodifiableSet(constraintMappingResourcePaths), executableValidationEnabled,
- expandExecutableValidation(defaultValidatedExecutableTypes), Collections.unmodifiableMap(properties),
+ ExecutableTypes.interpret(defaultValidatedExecutableTypes), Collections.unmodifiableMap(properties),
Collections.unmodifiableSet(valueExtractorClassNames));
this.parameterNameProviderClassName = parameterNameProviderClassName;
http://git-wip-us.apache.org/repos/asf/bval/blob/47cfebea/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
new file mode 100644
index 0000000..b04bf28
--- /dev/null
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ExecutableTypes.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.jsr.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.validation.executable.ExecutableType;
+
+import org.apache.bval.util.Validate;
+
+/**
+ * Utility methods relating to {@link ExecutableType}.
+ */
+public class ExecutableTypes {
+
+ private static final Map<ExecutableType, Set<ExecutableType>> INTERPRETED_EXECUTABLE_TYPES;
+ static {
+ final Map<ExecutableType, Set<ExecutableType>> m = new EnumMap<>(ExecutableType.class);
+
+ m.put(ExecutableType.ALL, Collections.unmodifiableSet(
+ EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS, ExecutableType.GETTER_METHODS)));
+ m.put(ExecutableType.IMPLICIT,
+ Collections.unmodifiableSet(EnumSet.of(ExecutableType.CONSTRUCTORS, ExecutableType.NON_GETTER_METHODS)));
+ m.put(ExecutableType.NONE, Collections.emptySet());
+
+ INTERPRETED_EXECUTABLE_TYPES = Collections.unmodifiableMap(m);
+ }
+
+ /**
+ * Interpret occurrences of {@link ExecutableType#ALL}, {@link ExecutableType#IMPLICIT}, and
+ * {@link ExecutableType#NONE}.
+ *
+ * @param executableTypes
+ * @return (unmodifiable) {@link Set} of {@link ExecutableType}
+ */
+ public static Set<ExecutableType> interpret(Collection<ExecutableType> executableTypes) {
+ Validate.notNull(executableTypes);
+
+ for (Map.Entry<ExecutableType, Set<ExecutableType>> e : INTERPRETED_EXECUTABLE_TYPES.entrySet()) {
+ if (e.getValue().equals(executableTypes) || executableTypes.contains(e.getKey())) {
+ return e.getValue();
+ }
+ }
+ return Collections.unmodifiableSet(EnumSet.copyOf(executableTypes));
+ }
+
+ /**
+ * Interpret occurrences of {@link ExecutableType#ALL}, {@link ExecutableType#IMPLICIT}, and
+ * {@link ExecutableType#NONE}.
+ *
+ * @param executableTypes
+ * @return (unmodifiable) {@link Set} of {@link ExecutableType}
+ */
+ public static Set<ExecutableType> interpret(ExecutableType... executableTypes) {
+ return interpret(Arrays.asList(executableTypes));
+ }
+
+ private ExecutableTypes() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/bval/blob/47cfebea/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
index 35d510b..a8972e2 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
@@ -79,7 +79,7 @@ public class ValidationParser {
final Set<ExecutableType> defaultValidatedExecutableTypes;
if (xmlConfig.getExecutableValidation() == null) {
- defaultValidatedExecutableTypes = BootstrapConfigurationImpl.DEFAULT_DEFAULT_VALIDATED_EXECUTABLE_TYPES;
+ defaultValidatedExecutableTypes = EnumSet.of(ExecutableType.IMPLICIT);
executableValidationEnabled = true;
} else {
final Optional<ExecutableValidationType> executableValidation =
@@ -145,6 +145,5 @@ public class ValidationParser {
}
private ValidationParser() {
- // no-op
}
}