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/22 20:52:36 UTC

bval git commit: refactor @Size validation; add validator for Number+ passing an additional 17 TCK tests

Repository: bval
Updated Branches:
  refs/heads/bv2 0247c2361 -> babcf0db5


refactor @Size validation; add validator for Number+ passing an additional 17 TCK tests


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/babcf0db
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/babcf0db
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/babcf0db

Branch: refs/heads/bv2
Commit: babcf0db57844598b0f7631bfd71c98ae88d756e
Parents: 0247c23
Author: Matt Benson <mb...@apache.org>
Authored: Thu Mar 22 15:52:31 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Mar 22 15:52:31 2018 -0500

----------------------------------------------------------------------
 .../apache/bval/constraints/SizeValidator.java  | 89 +++++++++++++++++++-
 .../SizeValidatorForArrayOfBoolean.java         | 45 ----------
 .../SizeValidatorForArrayOfByte.java            | 45 ----------
 .../SizeValidatorForArrayOfChar.java            | 45 ----------
 .../SizeValidatorForArrayOfDouble.java          | 45 ----------
 .../SizeValidatorForArrayOfFloat.java           | 45 ----------
 .../constraints/SizeValidatorForArrayOfInt.java | 45 ----------
 .../SizeValidatorForArrayOfLong.java            | 45 ----------
 .../SizeValidatorForArrayOfObject.java          | 46 ----------
 .../SizeValidatorForArrayOfShort.java           | 45 ----------
 .../SizeValidatorForCharSequence.java           | 44 ----------
 .../constraints/SizeValidatorForCollection.java | 47 -----------
 .../bval/constraints/SizeValidatorForMap.java   | 46 ----------
 .../bval/jsr/DefaultConstraints.properties      | 26 +++---
 .../java/org/apache/bval/jsr/Jsr303Test.java    |  4 +-
 .../src/test/resources/sample-constraints.xml   |  2 +-
 16 files changed, 102 insertions(+), 562 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java
index aba94af..df557a9 100644
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java
+++ b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidator.java
@@ -18,21 +18,93 @@
  */
 package org.apache.bval.constraints;
 
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Map;
+import java.util.function.ToIntFunction;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
 import javax.validation.ValidationException;
 import javax.validation.constraints.Size;
 
 /**
  * Description: Abstract validator impl. for @Size annotation<br/>
  */
-public abstract class SizeValidator {
+public abstract class SizeValidator<T> implements ConstraintValidator<Size, T> {
+    public static class ForArray<T> extends SizeValidator<T> {
+        public static class OfObject extends ForArray<Object[]> {
+        }
+
+        public static class OfByte extends ForArray<byte[]> {
+        }
+
+        public static class OfShort extends ForArray<short[]> {
+        }
+
+        public static class OfInt extends ForArray<int[]> {
+        }
+
+        public static class OfLong extends ForArray<long[]> {
+        }
+
+        public static class OfChar extends ForArray<char[]> {
+        }
+
+        public static class OfFloat extends ForArray<float[]> {
+        }
+
+        public static class OfDouble extends ForArray<double[]> {
+        }
+
+        public static class OfBoolean extends ForArray<boolean[]> {
+        }
+
+        protected ForArray() {
+            super(Array::getLength);
+        }
+    }
+
+    public static class ForCharSequence extends SizeValidator<CharSequence> {
+        public ForCharSequence() {
+            super(CharSequence::length);
+        }
+    }
+
+    public static class ForCollection extends SizeValidator<Collection<?>> {
+
+        public ForCollection() {
+            super(Collection::size);
+        }
+    }
+
+    public static class ForMap extends SizeValidator<Map<?, ?>> {
+        public ForMap() {
+            super(Map::size);
+        }
+    }
+
+    public static class ForNumber extends SizeValidator<Number> {
+        public ForNumber() {
+            super(Number::intValue);
+        }
+    }
+
+    private final ToIntFunction<? super T> sizeOf;
+
     protected int min;
     protected int max;
 
+    protected SizeValidator(ToIntFunction<? super T> sizeOf) {
+        super();
+        this.sizeOf = sizeOf;
+    }
+
     /**
-     * Configure the constraint validator based on the elements
-     * specified at the time it was defined.
+     * Configure the constraint validator based on the elements specified at the time it was defined.
      *
-     * @param constraint the constraint definition
+     * @param constraint
+     *            the constraint definition
      */
     public void initialize(Size constraint) {
         min = constraint.min();
@@ -47,4 +119,13 @@ public abstract class SizeValidator {
             throw new ValidationException("Max cannot be less than Min");
         }
     }
+
+    @Override
+    public boolean isValid(T value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true;
+        }
+        final int size = sizeOf.applyAsInt(value);
+        return min <= size && size <= max;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java
deleted file mode 100644
index e87c814..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfBoolean.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfBoolean extends SizeValidator implements ConstraintValidator<Size, boolean[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(boolean[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java
deleted file mode 100644
index ea897c1..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfByte.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfByte extends SizeValidator implements ConstraintValidator<Size, byte[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(byte[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java
deleted file mode 100644
index 70d0796..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfChar.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfChar extends SizeValidator implements ConstraintValidator<Size, char[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(char[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java
deleted file mode 100644
index eae7f5f..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfDouble.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfDouble extends SizeValidator implements ConstraintValidator<Size, double[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(double[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java
deleted file mode 100644
index 272dc3e..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfFloat.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfFloat extends SizeValidator implements ConstraintValidator<Size, float[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(float[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java
deleted file mode 100644
index d0d5709..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfInt.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfInt extends SizeValidator implements ConstraintValidator<Size, int[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(int[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java
deleted file mode 100644
index 06bf02b..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfLong.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfLong extends SizeValidator implements ConstraintValidator<Size, long[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(long[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java
deleted file mode 100644
index 84ab3f7..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfObject.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-/** Check that the length of an array is between <i>min</i> and <i>max</i> */
-public class SizeValidatorForArrayOfObject extends SizeValidator implements ConstraintValidator<Size, Object[]> {
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(Object[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java
deleted file mode 100644
index 4377882..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForArrayOfShort.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.lang.reflect.Array;
-
-public class SizeValidatorForArrayOfShort extends SizeValidator implements ConstraintValidator<Size, short[]> {
-
-    /**
-     * Checks the number of entries in an array.
-     *
-     * @param array   The array to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
-     *         <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(short[] array, ConstraintValidatorContext context) {
-        if (array == null) {
-            return true;
-        }
-        final int length = Array.getLength(array);
-        return length >= min && length <= max;
-    }
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java
deleted file mode 100644
index 9fc6ce4..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCharSequence.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-
-/** Check that a string's length is between min and max. */
-public class SizeValidatorForCharSequence extends SizeValidator implements ConstraintValidator<Size, CharSequence> {
-    /**
-     * Checks the length of the specified string.
-     *
-     * @param s       The string to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the string is <code>null</code> or the length of <code>s</code> between the specified
-     *         <code>min</code> and <code>max</code> values (inclusive), <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(CharSequence s, ConstraintValidatorContext context) {
-        if (s == null) {
-            return true;
-        }
-        final int length = s.length();
-        return length >= min && length <= max;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCollection.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCollection.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCollection.java
deleted file mode 100644
index 0df4fad..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForCollection.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.util.Collection;
-
-/** Check that a Collection's size is between min and max. */
-public class SizeValidatorForCollection extends SizeValidator implements ConstraintValidator<Size, Collection<?>> {
-
-    /**
-     * Checks the number of entries in a map.
-     *
-     * @param collection The collection to validate.
-     * @param context    context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the collection is <code>null</code> or the number of entries in
-     *         <code>collection</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(Collection<?> collection, ConstraintValidatorContext context) {
-        if (collection == null) {
-            return true;
-        }
-        final int length = collection.size();
-        return length >= min && length <= max;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForMap.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForMap.java b/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForMap.java
deleted file mode 100644
index 3ee8712..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/constraints/SizeValidatorForMap.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-import java.util.Map;
-
-/** Check that a Map's size is between min and max. */
-public class SizeValidatorForMap extends SizeValidator implements ConstraintValidator<Size, Map<?, ?>> {
-    /**
-     * Checks the number of entries in a map.
-     *
-     * @param map     The map to validate.
-     * @param context context in which the constraint is evaluated.
-     * @return Returns <code>true</code> if the map is <code>null</code> or the number of entries in <code>map</code>
-     *         is between the specified <code>min</code> and <code>max</code> values (inclusive),
-     *         <code>false</code> otherwise.
-     */
-    @Override
-    public boolean isValid(Map<?, ?> map, ConstraintValidatorContext context) {
-        if (map == null) {
-            return true;
-        }
-        final int size = map.size();
-        return size >= min && size <= max;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties b/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
index a092cfa..f7eff69 100644
--- a/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
+++ b/bval-jsr/src/main/resources/org/apache/bval/jsr/DefaultConstraints.properties
@@ -114,17 +114,19 @@ javax.validation.constraints.PastOrPresent=\
 javax.validation.constraints.Positive=org.apache.bval.constraints.NumberSignValidator$ForPositive
 javax.validation.constraints.PositiveOrZero=org.apache.bval.constraints.NumberSignValidator$ForPositive$OrZero
 
-javax.validation.constraints.Size=org.apache.bval.constraints.SizeValidatorForCharSequence,\
-  org.apache.bval.constraints.SizeValidatorForMap,\
-  org.apache.bval.constraints.SizeValidatorForCollection,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfBoolean,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfByte,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfChar,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfDouble,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfFloat,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfInt,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfLong,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfObject,\
-  org.apache.bval.constraints.SizeValidatorForArrayOfShort
+javax.validation.constraints.Size=\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfObject,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfByte,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfShort,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfInt,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfChar,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfLong,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfFloat,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfDouble,\
+  org.apache.bval.constraints.SizeValidator$ForArray$OfBoolean,\
+  org.apache.bval.constraints.SizeValidator$ForCharSequence,\
+  org.apache.bval.constraints.SizeValidator$ForCollection,\
+  org.apache.bval.constraints.SizeValidator$ForMap,\
+  org.apache.bval.constraints.SizeValidator$ForNumber
 
 javax.validation.constraints.Pattern=org.apache.bval.constraints.PatternValidator

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java b/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java
index 2dfe493..bc49aee 100644
--- a/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java
+++ b/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java
@@ -40,7 +40,7 @@ import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
 
-import org.apache.bval.constraints.SizeValidatorForCharSequence;
+import org.apache.bval.constraints.SizeValidator;
 import org.apache.bval.jsr.example.Address;
 import org.apache.bval.jsr.example.Book;
 import org.apache.bval.jsr.example.Engine;
@@ -145,7 +145,7 @@ public class Jsr303Test extends ValidationTestBase {
         boolean found = false;
 
         for (ConstraintDescriptor<?> each : desc.getConstraintDescriptors()) {
-            if (each.getConstraintValidatorClasses().contains(SizeValidatorForCharSequence.class)) {
+            if (each.getConstraintValidatorClasses().contains(SizeValidator.ForCharSequence.class)) {
                 assertTrue(each.getAttributes().containsKey("max"));
                 assertEquals(30, each.getAttributes().get("max"));
                 found = true;

http://git-wip-us.apache.org/repos/asf/bval/blob/babcf0db/bval-jsr/src/test/resources/sample-constraints.xml
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/resources/sample-constraints.xml b/bval-jsr/src/test/resources/sample-constraints.xml
index 9208a19..3c78a4e 100644
--- a/bval-jsr/src/test/resources/sample-constraints.xml
+++ b/bval-jsr/src/test/resources/sample-constraints.xml
@@ -66,7 +66,7 @@
 
   <constraint-definition annotation="javax.validation.constraints.Size">
       <validated-by include-existing-validators="false">
-          <value>org.apache.bval.constraints.SizeValidatorForCharSequence</value>
+          <value>org.apache.bval.constraints.SizeValidator$ForCharSequence</value>
       </validated-by>
   </constraint-definition>